HomeGenie Forum
Automation Program Plugins and Wizard Scripting => Help => Topic started by: mdsflyer on June 11, 2014, 09:15:44 AM
-
Hi there, love this program, I was using Homeseer but prefer the Homegenie App and Alarm system.
I have a Z-Wave setup of sensors and switches all of which are recognised and can be used by Homegenie which is great.
The help I require is as follows:-
I wish to activate certain lights if movement is detected. And have successfully set this up by using wizard scripting and when a sensor value changes to 255 then activating one of my switches.
However I only wish this to happen between sunset and sunrise.
How do I wizard script in that condition, i.e. if movement is detected and it is after sunset but before sunrise then activate this switch
Many thanks for any help given
m
-
Hi mdsflyer,
This javascript snippet will give you the sunrise and sunset times if you are using jkUtils - Solar Altitude :
var solarAltitude = hg.Modules.WithName("jkUtils - Solar Altitude").Get();
var sunriseTime = new Date (new Date().toDateString() + ' ' + solarAltitude.Parameter("jkUtils.SolarAltitude.Morning.Sunrise.End").Value)
var sunsetTime = new Date (new Date().toDateString() + ' ' + solarAltitude.Parameter("jkUtils.SolarAltitude.Evening.Sunset.Start").Value)
Edit: Sorry, I see that you would like to do this with wizard scripting, I don't know how to do it that way.
-
Thanks for the reply. I have weather underground supplying the sunset and sunrise times. But I cant find a way to use them to run a scenario or disable it. ie if it is after sunset but before sunrise do this if motion is detected. If anybody has a way of doing this id be keen to see how it is done.
-
Hi,
When you edit you "automation" script.
You can do :
"add a condition" -> ?????? I don't find a way to get the current system time ????? (perhaps, you have to write one ....)
-> "more than" ->
"programs" -> "501 (jkUtils - Solar Altitude)" -> "jkUtils.SolarAltitude.Morning.Sunrise.End"
Does anyone already do this kind of test ?
Bye
-
Wouldn't it be easier to simply create a parameter for "night" based on whatever sunrise/sunsets you pick? My smart lights code looks at jkutils sunrise and sunset and compares to the current time to set a night boolean variable. I use this variable in my code to check for whether I should turn lights on if motion is detected.
-
So if i well understand you don't manage by "wizard script" but only with a "C# script" (or other language). If yes, can you share your script please ?
I manage my shutter only with "wizard script", but sometimes i think i could more thinks with "language script" ....
Bye
-
Here's some example code (in JavaScript):
var solarAltitude = hg.Modules.WithName("jkUtils - Solar Altitude").Get();
// Get the sunriseTime as a DateTime
var sunriseTime = Date.parse(new Date().toDateString() + ' ' + solarAltitude.Parameter("jkUtils.SolarAltitude.Morning.Sunrise.End").Value);
// Get the SunsetTime as a DateTime
var sunsetTime = Date.parse(new Date().toDateString() + ' ' + solarAltitude.Parameter("jkUtils.SolarAltitude.Evening.Sunset.Start").Value);
// Get the current Time
var currentTime = new Date();
// Compare current time to Sunrise and sunset times
if (currentTime < sunsetTime && currentTime > sunriseTime)
{
hg.Program.Notify("debug", "day");
}
else
{
hg.Program.Notify("debug", "night");
}
-
Gene has a C# code that does motion sensing under Automation -> Scenes -> Smart Lights. I have modified this to do a lot more, but his code provides a good basis for any kind of motion sensor interaction as well as considering day/night. The code in that module uses the Weather Underground widget, so you will need to set that up first. I would recommend switching that over to use the jkutils code. If you want to do that, I can provide a snippet.
-
Thanks for the interest, would be very grateful if bkenobi could post up your modified smart light code as that will give me a clue where to start. Looks like you have the solution i need. Cheers m.
-
I was planning on posting the code once complete. I have a couple bugs that I'm still working on, but I'd say it's 95% complete. I need to get the last bit of functionality going and then remove a bunch of debug code. This has been a work in progress for the last 6 months or so, but it should be complete within a few days assuming I get time to work on it.
-
I posted my Advanced Smart Lights code here:
http://www.homegenie.it/forum/index.php?topic=241.0 (http://www.homegenie.it/forum/index.php?topic=241.0)
Take a look and see if it helps.