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:
NOTE: I’ve added an openHAB 2 Astro 2.0 binding version at the end.
NOTE: I’ve added an openHAB 2.2 version to the end which avoids the deprecation warnings on getCalendar()
Another transfer of a Design Pattern from the great big Design Pattern thread . I move them over to a new separate thread as I need to reference them in an answer to a question. NOTE: the rules have been extensively reworked to make them shorter and simpler.
Problem Statement
Often in home automation one has certain rule…
Using String comparisons on a rule that triggers at least once a second is really really inefficient.