I have created a rule to open or close windows depending on the outside and inside temperatures, In addition the rule is only active when the kids are not asleep and I can stop execution of the “then” part via a switch.
In order to not have this rule trigger with every temperature change but only every hour I have included a 60 minute timer that must be “null” for the rule to fire.
For some (probably trivial) reason this last part does not work. Any help would be much appreciated.
var Timer timer = null
rule "Lüften, wenn innen wärmer als draußen"
when
Item Temperature_FF_Bedroom changed or
Item Temperature_Garden_Terrace changed
then
var Number InsideTemperature = Temperature_FF_Bedroom.state as DecimalType
var Number OutsideTemperature = Temperature_Garden_Terrace.state as DecimalType
val dT=2
if (OutsideTemperature <= (InsideTemperature - dT) &&
(InsideTemperature >= 21) &&
(timer == null) &&
(Kids_awake.state == ON) &&
(ClimateControl_interrupt.state == OFF))
{
logInfo("FILE", "Too warm inside, opening windows")
sendTelegram("Jonas", "Too warm inside, opening windows")
sendCommand(Windows_All, UP)
createTimer(now.plusMinutes(60), [|
logInfo("FILE", "Timer expired")
timer = null
])
}
if (OutsideTemperature > (InsideTemperature + dT) &&
(InsideTemperature >= 22) &&
(timer == null) &&
(Kids_awake.state == ON) &&
(ClimateControl_interrupt.state == OFF))
{
logInfo("FILE", "Too warm outside, closing windows")
sendTelegram("bot1", "Too warm outside, closing windows")
sendCommand(Windows_All, DOWN)
createTimer(now.plusMinutes(60), [|
logInfo("FILE", "Timer expired")
timer = null
])
if (OutsideTemperature < (InsideTemperature) &&
(InsideTemperature < 20) &&
(timer == null) &&
(Kids_awake.state == ON) &&
(ClimateControl_interrupt.state == OFF))
{
logInfo("FILE", "Too cold outside, closing windows")
sendTelegram("bot1", "Too cold outside, closing windows")
sendCommand(Windows_All, DOWN)
createTimer(now.plusMinutes(60), [|
logInfo("FILE", "Timer expired")
timer = null
])
}
else {
logInfo("FILE", "Timer rescheduled")
timer.reschedule(now.plusMinutes(60))
}
}
end