more G-Labs products

Author Topic: Scheduled tasks  (Read 2302 times)

February 26, 2014, 07:46:25 AM
Read 2302 times

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I thought this deserved it's own thread so I duplicated the question.

A cron expression can contain comma separated values which stand for "OR" operator. Using a semicolon will stand for "AND".
For example, in the picture we see:

@Sunrise,00 23 * * *;@Weekdays

this means every week day "at sunrise" OR at 23.00 .
If the light is turned on after 23, it will be turned off anyway after sunrise.

Crontab can use a comma in it's expression to indicate multiple entries (e.g., 1,6,12 in month would mean January, June, December).  Would using commas in a crontab field mess up the OR logic you have included here?  For instance:

Turn off lights at sunrise, 11pm, 3am on weekdays
@Sunrise,00 3,23 * * *;@Weekdays

I'm also curious if there is a way to do something like:
Turn off lights at sunrise and 11pm on weekdays, but sunrise and 3am on weekends.

February 26, 2014, 02:06:10 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Ben,

you hit the big bug =) So now we have to choose a better expression separator symbol.
Could it be "+" or "|" or ":" ?

Consider that using the ";" will basically split the whole expression.
Eg.:

expr1;expr2;expr3

would be evaluated as something like

(expr1) && (expr2) && (expr3)

So to achieve the one described in your example, one more event have to be added to the events scheduler, you cannot do it with just one line.



February 26, 2014, 04:38:25 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
That answers another question I was thinking about too.  I want to have multiple instances of ON and OFF in some cases.  For instance, I have an under cabinet light in my kitchen that I want to turn on at 5AM on weekdays, off at sunrise, on at sunset, and off at 10pm.  It looks like the correct input would be:

ON
0 5 * * 1-5, @sunset

OFF
@sunrise, 0 23 * * *

Since my weekday event is a specific time, I can simply add the "1-5" in the day of week field.  If I wanted to do something with weekdays at sunset and also at another time, I guess that would be structured like:

@sunset;@weekday, 0 23 * * *;@weekend
or
@sunset;@weekday, 0 23 * * 0,6

(sunset on weekdays) or (11pm on weekends)

Am I doing that correctly?  Obviously the bug would pop up on the second option with the comma.  Maybe the delineation could be parenthesis to group an expression and a pipe for or?  If you are parsing the string anyway, maybe use conventional && and || or shortened to & and |.

February 26, 2014, 05:01:08 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Ben,

parenthesys would solve all the trouble with current implementation, though I want to keep this simple for now.
So let's use the colon ':' symbol to separate cron strings.
This will be available in next release.

In the future, pheraps, there will be paranthesys to help the use of nested expressions logic to allow composing any kind of event.

Cheers,
g.


February 26, 2014, 06:05:41 PM
Reply #4

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
Yes, keeping it simple would be preferable!

February 27, 2014, 03:29:31 AM
Reply #5

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
One other thing that needs considering in the next update to the scheduler is offsets.  I need to be able to turn lights on at sunset - x minutes (difference between ambient light levels inside the house and outside requires turning on a few minutes early compared to outside).  I could certainly do this by building some c# code or perhaps modifying the Weather Underground code, but it might be nice to include something in the Scheduler code directly.  maybe something like:

(@sunset - 10)&@weekday

Maybe you can come up with something better.