Hi,
I have a rule that includes a timer of 10minutes.
Is there a way to stop this rule while it is running, or resetting it so the timer restarts?
You help is very appreciated.
Hi,
I have a rule that includes a timer of 10minutes.
Is there a way to stop this rule while it is running, or resetting it so the timer restarts?
You help is very appreciated.
Hi, what rule language?
show your rule if possible
Indeed, we need to see the rule because if you are in fact using a timer, then the rule isn’t running. It’s simply waiting. But if it’s using a sleep it is running doing nothing but consuming resources and preventing the rule from being triggered again.
The usual approach is to trigger the rule when ever any states change which impact the timer (i.e. need to create the timer, reschedule the timer, or cancel the timer). Inside the rule you test the current conditions and do the action required.
For example, in pseudocode it would look something like this:
when: doorSensor changed
then:
if doorSensor.state == CLOSED
cache.private.get("timer")?.cancel() // cancel the timer when the door is CLOSED if it exists
else if cache.private.exists("timer")
cache.private.get("timer").reschedule(now.plusMinutes(1))
else
cache.private.put("timer", createTimer(now.plusMinutes(1), { log("close the door!") })
With a setup like this, it’s a simple matter of closing the door (or sending a CLOSED update to the doorSesnor Item) to cancel the timer.
There’s an added bonus here in that by using the cache, if the rule becomes unloaded any timers stored in the cache will be cancelled automatically for you. So hitting the pause button on the Rule’s page, or disabling the rule from another rule, will cause the rule to become unloaded and the timers in the cache will be cancelled for you.
However, if the rule is actively running because it’s sleeping, you can’t disable the rule until it exits.