I tried to create a rule that only would fire on a certain timeframe each day, but i guess i have not yet
completely understood working with variables in rules…
This is my rule:
var Timer myTimer_motion_SZ = null
var Number hour = now.getHourOfDay
rule "motion_SZ_ON"
when
Item Motion_SZ changed from OFF to ON
then
if ((hour <= 21) && (hour >= 18)) {
logInfo("motion_SZ.rule","Rule motion_SZ executed, the hour is: " +hour.toString)
sendCommand("LED_SZ_4", "ON")
myTimer_motion_SZ = createTimer(now.plusSeconds(20)) [|
sendCommand ("LED_SZ_4" , "OFF") ]
}
else
logInfo ("motion_SZ.rule", "Rule motion_SZ NOT execute due to time of day, the hour is: " +hour.toString)
end
i expected the variable ‘hour’ to be updated whenever the rule itself fires, but from the logs i am writing i think it only gets updated the moment i create this rule (or copy it into the folder, or change something in the rule)
can anyone help me with this?
is there a way to “refresh” the variable when the rule starts?
I’m a bit lost at the moment