more G-Labs products

Author Topic: Schedule Motion Sensing - Help  (Read 3765 times)

June 11, 2014, 09:15:44 AM
Read 3765 times

mdsflyer

  • *
  • Information
  • Newbie
  • Posts: 3
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

June 11, 2014, 02:34:42 PM
Reply #1

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Hi mdsflyer,

This javascript snippet will give you the sunrise and sunset times if you are using jkUtils - Solar Altitude :

Code: [Select]
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.
« Last Edit: June 11, 2014, 02:49:14 PM by mvdarend »

June 12, 2014, 06:56:41 AM
Reply #2

mdsflyer

  • *
  • Information
  • Newbie
  • Posts: 3
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.

June 12, 2014, 11:52:00 AM
Reply #3

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
When you edit you "automation" script.
You can do :
Code: [Select]
"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

June 12, 2014, 04:46:29 PM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

June 12, 2014, 05:47:43 PM
Reply #5

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544

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

June 12, 2014, 06:46:37 PM
Reply #6

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Here's some example code (in JavaScript):
Code: [Select]
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");
}

June 12, 2014, 10:01:24 PM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

June 14, 2014, 05:42:43 AM
Reply #8

mdsflyer

  • *
  • Information
  • Newbie
  • Posts: 3
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.

June 16, 2014, 04:18:59 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
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.

June 17, 2014, 07:58:13 AM
Reply #10

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I posted my Advanced Smart Lights code here:

http://www.homegenie.it/forum/index.php?topic=241.0

Take a look and see if it helps.