more G-Labs products

Author Topic: Scheduler and holidays  (Read 660 times)

February 12, 2017, 06:44:24 PM
Read 660 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
There was a set of holiday defined in the timetable widget a while back.  I was hoping it might be included in the new scheduler but I'm not seeing it.  Is it there and I'm missing it, or do I need to define my own cron expressions for the holidays I'm interested in?  I'm primarily thinking about US Thanksgiving through new years as I have holiday lights that turn on in the evening in my old setup but I need to get things updated now.

The basic cron expression needs to turn on the lights at dusk and off at 11pm between the 4th Thursday of November (+1 day really) and December 31.  I can create a cron expression to do this I think, but I was hoping holidays might already be available if I look in the right spot.

February 13, 2017, 05:22:02 PM
Reply #1

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Also, I'm not seeing a link to the updated scheduler documentation that I thought Gene had provided.  If anyone has a link, please post it.

In the mean time, could someone guide me on how to convert this module from the old scheduler (Scheduled On/Off) over to the new scheduler?  The module turns on in the evening at sunset and then off at 10:30 and sunrise in November and December.  What I really want is for the module to turn on and off only between Thanksgiving+1 (Black Friday) and December 31.  Since the lights don't get put up until Thanksgiving at the earliest, the modules get turned on/off early but it doesn't affect lighting.

Holiday lights
ON:   @SolarAltitude.Evening.Sunset.Start;* * * 11,12 *
OFF:  (30 22 * 11,12 *):(@SolarAltitude.Morning.Sunrise.End;* * * 11,12 *)

I tried some things but so far I only have the holiday dates defined.  I don't know how to link them into scheduled activity.

February 14, 2017, 03:49:04 AM
Reply #2

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
Hello,

I never saw any doc's from Gene about the scheduler.  I put a few things on the new scheduler into the Dummies doc but nothing as sophisticated as you are looking for.

For holidays,  I just use my Dusk to Dawn or Dusk to 10:30 module addresses since I have numerous other modules on those addresses and controlled that way everyday.

I like the idea of gating over months but Ive never done it  :)

February 14, 2017, 06:36:18 AM
Reply #3

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Hi,

Yesterday evening I was quickly looking through the new scheduler's code and didn't understand it completely yet. I will continue to study it and maybe (oh, gods) I'll write some unit tests and a quick guide for the new scheduler.

A quick note: looks like @ sign allow you to refer to the predefined events (like @SolarTimes.Sunrise, @SolarTimes.Sunset and @SolarTimes.SolarNoon) OR your own scheduled event.

Need to find out what can we do with operators ">", ":", ";" and "%".

February 14, 2017, 06:57:05 AM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
The old scheduler (Scheduled On/Off) used @ to refer to scheduler events like sunrise or sunset.  It's been a while since I set up the and/or conditions so I don't remember which is which.  However, ":" and ";" are used for logical AND and OR. I don't know how to use the other operators and I don't think they work with the old setup.

February 14, 2017, 02:15:17 PM
Reply #5

mchias13

  • **
  • Information
  • Jr. Member
  • Posts: 45
all the operators are explained here:
http://genielabs.github.io/HomeGenie/scheduler.html

maybe try this:
ThanksgivingDay
(* * 22-28 11 *) ; (* * * * 4)    -> this will compare the 7 days that could be thanksgiving versus if that day is a thursday



BlackFriday
(* * 23-29 11 *) ; (* * * * 5)    -> this will compare the 7 days that could be black friday versus if that day is a friday

ChristmasDay
(* * 25 12 *)

ChristmasSeason
(@BlackFriday > @ChristmasDay)

lights on
@ChristmasSeason ; @SolarTimes.Sunset

lights off
@ChristmasSeason ; @SolarTimes.Sunrise


i think i have my dates correct.  you should verify them to be certain. I modify my lights on and off by +/-30 mins.  So you could do (@SolarTimes.Sunset - 30) to turn them on 30 mins before sunset.
« Last Edit: February 14, 2017, 02:23:42 PM by mchias13 »

February 14, 2017, 02:21:46 PM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That was basically what I had, but it doesn't account for time of day.  I wasn't sure how to do both.  Also, the action/script would be turn modules on, right?  How do you command them off? A second event with a different time?

February 14, 2017, 02:24:54 PM
Reply #7

mchias13

  • **
  • Information
  • Jr. Member
  • Posts: 45
yes you will need scripts for on and off.

if you just do a time range from sunset to sunrise, then if you manually turn the lights off they will turn right back on.

my lights on script:
(@SolarTimes.Sunset)
:
(30 5 * * 1-5)

my lights off script:
(@SolarTimes.Sunrise)
 :
(0 22 * * *)
« Last Edit: February 14, 2017, 02:26:51 PM by mchias13 »

February 14, 2017, 02:37:31 PM
Reply #8

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
mchias13, thank you for the link to the documentation.

I'm wondering why Generoso decided to use ";" as AND operator and ":" as OR operator instead of standard for many program languages "&" (or "&&") and "|" (of "||") respectively.

February 14, 2017, 02:53:24 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I don't know an answer but I wondered the same when he originally added it.  I think it might even be answered in a thread from long ago.

February 14, 2017, 04:20:37 PM
Reply #10

kevinvinv

  • ****
  • Information
  • Sr. Member
  • Posts: 196
Not sure if I understood your question about turning lights on and off Bkenobi.  But they will automatically go off when the ON schedule expires... if that makes sense.

February 14, 2017, 04:49:30 PM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Oh, ok.  So if I can make an expression that brackets my desired on time, outside of that the lights will be left alone?  In other words, I need to define a block of time that defines when I want the lights to be on.  HG will turn them on any time it sees them off in this time period.  At the end of the period, it will turn them off once.

So, my time would be:

between Black Friday and New years:
Code: [Select]
(@BlackFriday>@NewYearsDay)
AND

between sunset and 10:30:
Code: [Select]
(@sunset> 30 22 * * *)
So the total expression would be:
Code: [Select]
(@BlackFriday>@NewYearsDay);(@sunset> 30 22 * * *)
That would be any time that is between sunset and 10:30 and also falls between the dates of BlackFriday and NewYearsDay.  Sound right?

The only thing I'm not sure of is if I really want it to turn the lights back on if they were commanded off.  I don't know why I would command them off, but if they were intentionally overridden I don't know that I want it automatically turning back on in every case.  It seems more intuitive that they would turn on at the initial time and then off at the end time (once and only once).

February 14, 2017, 09:43:38 PM
Reply #12

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Not sure if I understood your question about turning lights on and off Bkenobi.  But they will automatically go off when the ON schedule expires... if that makes sense.

I think they will automatically go OFF if your script looks like this:
Code: [Select]
// Turn on, if previous minute was not in schedule (start occurrence range)
if (!$$.onPrevious())
  $$.boundModules.on();
// Turn off, if next minute won't be in schedule (end occurrence range)
if ($$.onPrevious() && !$$.onNext())
  $$.boundModules.off();

February 14, 2017, 10:11:15 PM
Reply #13

mchias13

  • **
  • Information
  • Jr. Member
  • Posts: 45
(@sunset> 30 22 * * *)

may want to change the above to:
@sunset > (30 22 * * *)

not sure how parenthesis and cron expressions are read, but to be certain it's best to just use them to isolate each item.  also makes it easier to read.

Quote
The only thing I'm not sure of is if I really want it to turn the lights back on if they were commanded off.  I don't know why I would command them off, but if they were intentionally overridden I don't know that I want it automatically turning back on in every case.  It seems more intuitive that they would turn on at the initial time and then off at the end time (once and only once).
this is just how it will work unless you break up your on time and off time into separate schedules.  I found this out with my exterior lights.  If i set them on for a span of time, then anytime i turned them off manually they would turn back on.