I explored Timers a bit more, and searching the forums came upon Expiry Timers from a great post from @rlkoshak here Design Pattern: Expire Binding Based Timers
But my timer isnt expiring (sending the OFF command)
Any ideas why?
items
/* HW Countdown Timer , even set to 1 minute to interrupt the 60 minute counter. Didnt work */
Switch i_HVAC_HW_Timer_Switch { expire="1m,command=OFF" }
Number i_HVAC_HW_Counter "Hot water timer" <clock-on> (g_HVAC)
/* Sitemap switch */
Switch i_HVAC_HW_Switch "HW On/Off" <switch> (g_HVAC, g_HVAC_Switch) {channel = "zwave:4849599d:t_Zcontroller:node3:swtich_binary1"}
Rule
// Global var count can be updated from any rule
var count = 0
rule
// Start timer when HW switch set to ON
"HVAC_HW_Start_Timer"
when
Item i_HVAC_HW_Switch changed to ON
then
// Start expiry timer
logInfo("HVAC_HW.rules", "HOT WATER countdown timer STARTED by rule")
i_HVAC_HW_Timer_Switch.postUpdate(ON)
count = 60
while (count >= 0) {
i_HVAC_HW_Counter.postUpdate(count)
count = count - 1
// Sleep for one minute
Thread::sleep(60000)
}
logInfo("HVAC_HW.rules", "HOT WATER countdown updates finished")
i_HVAC_HW_Timer_Switch.sendCommand(OFF)
end
rule
// When timer has expired
"HVAC_HW_Timer_Expired"
when
Item i_HVAC_HW_Timer_Switch received command OFF
then
// Set counter to zero - will occult the timer value on the sietmap
logInfo("HVAC_HW.rules", "HOT WATER countdown timer EXPIRED")
count = 0
//Expiry on switch doesnt send the "OFF" command so force it ??
i_HVAC_HW_Switch.postUpdate(OFF)
end
rule
// Cancel timer if HW switch set to OFF by user
"HVAC_HW_Cancel_Timer"
when
Item i_HVAC_HW_Switch changed to OFF
then
if (i_HVAC_HW_Timer_Switch.state == ON) {
// Interrupt timer and force expiry
logInfo("HVAC_HW.rules", "HOT WATER countdown timer INTERRUPTED by rule")
count=0
i_HVAC_HW_Timer_Switch.sendCommand(OFF)
}
end
On the GUI, when I select HW (i_HVAC_HW_Switch) to ON, the events fire and the timer is started and the countdown appears in the GUI, but the expiry on the Switch i_HVAC_HW_Timer_Switch { expire=“1m,command=OFF” } does not “fire” the OFF command so that the rule
HVAC_HW_Timer_Expired is executed.
Any ideas?