HomeGenie Forum
General Category => General Discussion => Topic started by: nolio on April 26, 2014, 09:07:10 AM
-
Hi,
I try to use the following scheduler expression (on "turn on" of a devices) :
@SunCalc.Morning.Sunrise.End;@Weekdays:30 8 * * 0,6,7
This one is trigger well (turn on the deivces) :
@SunCalc.Morning.Sunrise.End;@Weekdays
But this one don't trigger (don't turn on devices on weekend) :
30 8 * * 0,6,7
Any idea why ?
Bye
-
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.
-
I already try :
30 8 * * 0,6
or :
30 8 * * *;@Weekend
-
Did you check timezone on your server?
pi@raspberrypi ~ $ date
Sat Apr 26 10:40:58 CEST 2014
g.
-
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:
@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.
-
Oki that's clear (It's like multiplication has priority on addition :)).
So i simplify in scheduler expression :
@SunCalc.Morning.Sunrise.End;30 7 * * *
date
Sat Apr 26 13:14:52 CEST 2014
Thanks.
Bye
-
Hi,
I try again with HG r374 and parentheses function, but it doesn't work.
My original scheduler :
@SunCalc.Morning.Sunrise.End;@Weekdays:30 8 * * 0,6,7
And i try this one :
(@SunCalc.Morning.Sunrise.End;@Weekdays):(30 8 * * 0,6,7)
Any idea why it doesn't work ?
Bye
-
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.
-
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
-
I may be right, but it doesn't work for me either. ;D
I used the scheduler code:
@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.
-
Hi,
KO for me too.
I am trying to take a look at the code in
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
-
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.
-
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:
(@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:
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.
-
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.
-
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
-
Have you tried compiling this and testing the results? I've tried to compile the HG exe and it didn't work in the past. I was able to compile XTenLib.dll, so I might give this another go just to see if the code repair works if you can't verify.
I've been testing different configurations of Scheduler ON/OFF events and the only thing that seems to work is using cron expressions with no logic (and, or, parenthesis). The following error (or similar) keeps popping up for me when I try anything more complex.
06:18:50.113 Scheduler.Error Missing binary operator:
(0) [?] 0
0 [?] (0) ( @SolarAltitude.Morning.Sunrise.End ) : ( 30 22 * * * ) HomeAutomation.HomeGenie.Scheduler
In this case, I added a space before and after each element to eliminate the p++ issue. It's possible HG doesn't like this space and that's causing the issue.
-
Hi guys,
the problems reported should be fixed in next update.
This is the new code, in case some of you want help testing it:
public bool IsScheduling(string cronExpression)
{
string buildExpression = "";
int p = 0;
while (p < cronExpression.Length)
{
char token = cronExpression[p];
if (token == '(' || token == ')' || token == ';' || token == ':')
{
buildExpression += token;
p++;
continue;
}
string currentExpression = token.ToString();
p++;
while (p < cronExpression.Length)
{
token = cronExpression[p];
if (token != '(' && token != ')' && token != ';' && token != ':')
{
currentExpression += token;
p++;
}
else
{
break;
}
}
currentExpression = currentExpression.Trim(new char[]{ ' ', ' ' });
if (String.IsNullOrEmpty(currentExpression)) continue;
bool isEntryActive = false;
if (currentExpression.StartsWith("@"))
{
// Check expresion from scheduled item with a given name
var eventItem = Get(currentExpression.Substring(1));
isEntryActive = (eventItem != null && eventItem.IsEnabled && EvaluateCronEntry(eventItem.CronExpression));
}
else
{
isEntryActive = EvaluateCronEntry(currentExpression);
}
buildExpression += (isEntryActive ? "1" : "0");
}
buildExpression = buildExpression.Replace(":", "+");
buildExpression = buildExpression.Replace(";", "*");
bool success = false;
try
{
ExpressionEval eval = new ExpressionEval();
eval.Expression = buildExpression;
success = eval.EvaluateBool();
}
catch (Exception ex)
{
masterControlProgram.HomeGenie.LogBroadcastEvent(
Domains.HomeAutomation_HomeGenie_Scheduler,
cronExpression,
"Scheduler Expression",
Properties.SCHEDULER_ERROR,
JsonConvert.SerializeObject(ex.Message));
}
return success;
}
Just added the code to skip empty expressions (white spaces).
I tested it against the expressions you guys posted here and it worked.
When using "@" to reference an item in the scheduler, ensure that the item is enabled from the UI, otherwise it will be evaluated as false.
Thanks!
g.
-
I will test it out as soon as the testing release is populated on SourceForge. Thanks!
-
Gene
I didn't understand what you were saying before about enabling the scheduled event. I thought you meant in the "Scheduled ON/OFF" setup within the module. I found that there is a toggle for the scheduled event in the Scheduler list of items as well. Once I enabled my test item, it worked great every time. I am now able to create complex expressions and they work!
(@test_time;@weekend):(40 8 * * *;@weekend)
This works great now. So, I have to ask why the default for these scheduler items is disabled? In my mind, the most logical approach would be to enable the item when it's initially created (manually in the Scheduler view or by a script). If it is manually or programically disabled, it should not be overridden. All of the timer events created by Jen's code are not turned on, so this is why they don't work. I think Jen's code should either enable them the first time it is run or HG should automatically enable all new scheduler items on instantiation.