I have a rule that runs 7 daily scheduled tasks, when I reload the rule some of the current running timers seem to remain scheduled rather than following the rule and cancelling on a reload. Is there a command to find and cancel the orphaned timers, or a workaround other than rebooting?
Each individual task cancels the timer, and then resets it, one of the rules is below:
rule "HVAC Evening Scheduler"
when Time cron "30 5 0 ? * *"
or System started
or Item TodayEveningTime changed
or Item TodayEveningHVAC changed
or Item Vacation changed from ON to OFF
then
if (HVACEveningOnTime != null)
{ HVACEveningOnTime.cancel()
logInfo("Timers", "Evening HVAC Timer cancelled, current status is " +HVACEveningOnTime) }
if (DisableScheduler.state == OFF && TodayEveningHVAC.state == ON) {
var DateTime TodaysEveningOnTime = parse(Year.state.toString+"-"+Month.state.toString+"- "+Day.state.toString+"T"+TodayEveningTime.state.toString+":00")
if (TodaysEveningOnTime.beforeNow) { } else {
logInfo("Timers", "HVAC Evening On Scheduled for " +TodaysEveningOnTime)
HVACEveningOnTime = createTimer(TodaysEveningOnTime) [|
logInfo("Timers", "HVAC Evening Scheduled on rule ran ")
sendCommand(HVAC, ON)
]
}
}
end
Log Entries from normal operation with one change causes the script to cancel the timer and reschedule it as expected:
2016-05-05 08:53:57.228 INFO o.openhab.model.script.Timers[:53]- HVAC Evening On Scheduled for 2016-05-05T18:30:00.000+12:00
2016-05-05 08:56:01.549 INFO o.openhab.model.script.Timers[:53]- Evening HVAC Timer cancelled, current status is org.openhab.model.script.internal.actions.TimerImpl@6ca989
2016-05-05 08:56:01.564 INFO o.openhab.model.script.Timers[:53]- HVAC Evening On Scheduled for 2016-05-05T18:35:00.000+12:00
After saving the rule again with no changes I see:
2016-05-05 08:57:28.309 INFO o.openhab.model.script.Timers[:53]- HVAC Evening On Scheduled for 2016-05-05T18:35:00.000+12:00
2016-05-05 08:57:50.631 INFO o.openhab.model.script.Timers[:53]- Evening HVAC Timer cancelled, current status is org.openhab.model.script.internal.actions.TimerImpl@1a6d7a7
2016-05-05 08:57:50.647 INFO o.openhab.model.script.Timers[:53]- HVAC Evening On Scheduled for 2016-05-05T18:30:00.000+12:00
BUT after the rule is reloaded there is NO timer cancelled message before the timer is created, suggesting the old timer is still running.
I have seen this reflected in the logs as the same event being triggered twice, and under certain conditions with a stack dump which thankfully seems to have gone now I’ve put them in their own rule file with separate logging.
2016-05-04 18:30:00.052 INFO o.openhab.model.script.Timers[:53]- HVAC Evening Scheduled on rule ran
2016-05-04 18:30:00.287 INFO o.openhab.model.script.Timers[:53]- HVAC Evening Scheduled on rule ran
It doesn’t seem to happen to all the timers in the rule after I edit the rule file, yesterday it affected 2 out of the 4 left to run.
The Cron Job that schedules the rule to run just after midnight seems to only invoke one instance of each timer.