mchecker
(Marek)
July 30, 2017, 8:08am
1
Hello everybody,
i’m trying to compare two DateTime string variables. But it seems, that the rules engine doesn’t like the equals compare method.
Can anybody help?
Thanks in advance!
Marek
[ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘sunrise’: An error occurred during the script execution: index=1, size=1
rule “sunrise"
when
Item CurrentTime received update
then
var String t1 = CurrentTime.state.format(”%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM")
var String t2 = SunriseTime.state.format("%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM")
logInfo(“print t1”,t1)
logInfo(“print t2”,t2)
if (t1.equals(t2)){
logInfo(“Start of Sunrise!”)
sendCommand(gEGShutter, UP)
logInfo(“sunrise”, “Shutter EG are UP”)
}
else
{
logInfo(“No sunrise…waiting!”, t1)
}
end
hr3
(Harry)
July 30, 2017, 8:50pm
2
After changing your quotation marks from
“..."
to
"..."
it works.
Didn’t you use the SmartHome-Designer?
You can also use
if (CurrentTime.state.format("%1$tH:%1$tM") == SunriseTime.state.format("%1$tH:%1$tM")) {...
chimera
(chimera)
July 30, 2017, 9:20pm
3
Seems a highly complicated not to mention resource intensive way of doing it. Use Astro binding, here’s my rule for sunset event triggering close of my hall blinds… (using sunset as an example here, because I have my blinds OPEN with a cron event, since I get up at the same time of the morning regardless of when sunrise is!)
rule "Close blinds Weekday Triggered at Sunset"
when
Channel 'astro:sun:local:set#event' triggered START
then
logInfo("blinds", "Hall blind close triggered")
sendCommand(hallblindTrigger, OFF)
end
rlkoshak
(Rich Koshak)
July 31, 2017, 3:29pm
4
To expand on chimera’s suggestion:
[Edit] Adde link to Time of Day State Machine
For years now I’ve let this Design Pattern post get out of hand so I’m going to rein it in a bit now. It’s really expanded away from what it’s originally intended to be (i.e. a way to illustrate how to code a time based state machine) into a thread that is mostly about the example, Time of Day. It’s partially my fault for naming the thread “Time of Day”. But there are better alternatives for Time of Day in specific and time based state machines in g…
Using String comparisons on a rule that triggers at least once a second is really really inefficient.