more G-Labs products

Author Topic: Scheduler with "OR"  (Read 5325 times)

April 26, 2014, 09:07:10 AM
Read 5325 times

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
I try to use the following scheduler expression (on "turn on" of a devices) :
Code: [Select]
@SunCalc.Morning.Sunrise.End;@Weekdays:30 8 * * 0,6,7
This one is trigger well (turn on the deivces) :
Code: [Select]
@SunCalc.Morning.Sunrise.End;@WeekdaysBut this one don't trigger (don't turn on devices on weekend) :
Code: [Select]
30 8 * * 0,6,7
Any idea why ?

Bye

April 26, 2014, 09:21:26 AM
Reply #1

mvdarend

  • *****
  • Information
  • Hero Member
  • Posts: 431
Code: [Select]
30 8 * * 0,6,7
I don't think 7 is a valid value here, as the days of the week are a zero based array. With Sunday as the first day of the week, its value is 0, Saturday will be 6.

Hope that helps.

April 26, 2014, 09:49:51 AM
Reply #2

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
I already try :
Code: [Select]
30 8 * * 0,6or :
Code: [Select]
30 8 * * *;@Weekend

April 26, 2014, 10:41:18 AM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Did you check timezone on your server?

Code: [Select]
pi@raspberrypi ~ $ date
Sat Apr 26 10:40:58 CEST 2014

g.

April 26, 2014, 10:48:53 AM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Also, in current implementation there is no grouping in building expressions (eg. by using parenthesys), so the precedence is given by the AND (;) operator first and the OR operator later.

So your expression will be evaluated as:

Code: [Select]
@SunCalc.Morning.Sunrise.End

AND

@Weekdays OR 30 8 * * 0,6,7

The 7 is allowed but it's the same as 0, so you can have both Monday to Sunday as 1-7 or Sunday to Saturday as 0-6.

g.

April 26, 2014, 01:25:01 PM
Reply #5

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Oki that's clear (It's like multiplication has priority on addition :)).

So i simplify in scheduler expression :
Code: [Select]
@SunCalc.Morning.Sunrise.End;30 7 * * *
Code: [Select]
date
Sat Apr 26 13:14:52 CEST 2014

Thanks.
Bye



June 11, 2014, 09:05:35 PM
Reply #6

nolio

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

I try again with HG r374 and parentheses function, but it doesn't work.
My original  scheduler :
Code: [Select]
@SunCalc.Morning.Sunrise.End;@Weekdays:30 8 * * 0,6,7And i try this one :
Code: [Select]
(@SunCalc.Morning.Sunrise.End;@Weekdays):(30 8 * * 0,6,7)
Any idea why it doesn't work ?

Bye

June 18, 2014, 07:47:51 AM
Reply #7

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I don't know if this is resolved or not, but I think the problem is that you are using the wrong value.  I believe that it should be @SolarAltitude... rather than @SunCalc...  At least that's what it appears to be in r374.

June 18, 2014, 09:05:48 AM
Reply #8

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
Hi,
You are right :).
I am not sure if i use this exact expression or another one in my HG configuration (and do the mistake only in the forum).
So i will try again in HG configuration to be sure.
Thanks
Bye

June 18, 2014, 03:19:41 PM
Reply #9

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I may be right, but it doesn't work for me either.   ;D

I used the scheduler code:

Code: [Select]
@SolarAltitude.Morning.Sunrise.End
I do not see any activity that indicates that the code is working in my logs.  So, there must be something I'm doing wrong as well.

June 19, 2014, 04:11:11 PM
Reply #10

nolio

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

KO for me too.
I am trying to take a look at the code in
Code: [Select]
HomeGenie/Automation/Scheduler/SchedulerService.cs-->> https://github.com/genielabs/HomeGenie/commit/e9f639bfceb85cc9650c6bdca3052f453be81951#diff-1
But in my first look, i didn't understand all the management of parenthese.

Bye

June 19, 2014, 04:34:56 PM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
The on/off at a specific time seems to work, but the shortcut types (e.g. @Morning.Sunrise.Start)  do not.  I'll look at the code you linked and see if I can figure anything out.

June 19, 2014, 06:00:14 PM
Reply #12

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I think I found the problem with the code.  I believe there is an issue with tracking the current position in the cronExpression.  Take the following expression:
Code: [Select]
(@SunCalc.Morning.Sunrise.End;@Weekdays):(30 8 * * 0,6,7)
Now, using the code from:
https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/Scheduler/SchedulerService.cs
and looking at line 156 which is the start of the IsSchduling code.  If I work through the code from the start:

Code: [Select]
line Variable Value
156 cronExpression (@SunCalc.Morning.Sunrise.End;@Weekdays):(30 8 * * 0,6,7)
158 buildExpression ""
159 p 0
162 token (
165 buildExpression (
166 p 1
170 currentExpression (
171 p 2
174 token S
177 currentExpression (S

This is the error.  currentExpression should contain the @ symbol but because the p was incremented twice in a row, it skipped that symbol.  It may do the same for other situations, but it looks like the token check is incrementing the pointer p one too many times.

June 20, 2014, 07:38:04 AM
Reply #13

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I tried using the scheduler this evening and it works correctly with a single cron expression however it does not work at all when combining multiple statements nor does it work with scheduler items (shortcuts with @).  I'm not sure what to do to get it working.

June 20, 2014, 10:12:27 AM
Reply #14

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
I think you are right, you have to move the line 171 : p++ at the end of the while so at the line 200.
And modify the second while at line 172 to include ":" or ";" in the buildExpression

while (p < cronExpression.Length)
{
         token = cronExpression[p];
        if (token != '(' && token != ')' && token != ';' && token != ':')
         {
               currentExpression += token;
               p++;
        }
        else
         {
              if ( token == ';'  || token == ':')
              {
                  buildExpression += token;
              }
              break;
         }
}

Cheers
Dani
« Last Edit: June 20, 2014, 10:32:11 AM by dani »