The scheduler is only able to execute a few timer blocks at once (though it can schedule a great many).
If you’ve been playing a lot, you may have used those up with errors or something.
Reboot and test your rule again.
Here is an example of a working timer used with a motion sensor that may help or at least give some ideas for future rules.
var Timer myTimer = null
rule "Motion OFF"
when
Item Motion changed from OFF
then
if (myTimer === null) {
if (Motion.state == ON) {
myTimer = createTimer(now.plusSeconds(60), [ |
if (Motion.state == ON){
//do stuff
}
])
}
}
end
rule "BACK FROM ON"
when
Item Motion changed from ON
then
myTimer.cancel
myTimer = null
end
Also note the "var Timer myTimer = null at the top of rule. For your case I don’t think you have to move it to the top but you can always give it a try if a reboot doesn’t help.
Thanks a lot for the fast ansers. I tried now your code after restart (except im using my switch for testing instead of Motion):
var Timer myTimer = null
rule "Motion OFF"
when
Item testTimer changed from OFF
then
if (myTimer === null) {
if (testTimer.state == ON) {
logInfo("rule", "start timer")
myTimer = createTimer(now.plusSeconds(60), [ |
if (testTimer.state == ON){
//do stuff
logInfo("rule", "timer executed")
}
])
}
}
end
rule "BACK FROM ON"
when
Item testTimer changed from ON
then
myTimer.cancel
myTimer = null
end
Its kinda working but the time delay in the lock seems to be not what i set for the timer:
2019-11-23 15:02:33.545 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command OFF
2019-11-23 15:02:33.554 [vent.ItemStateChangedEvent] - testTimer changed from ON to OFF
2019-11-23 15:02:34.500 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘BACK FROM ON’: cannot invoke method public abstract boolean org.eclipse.smarthome.model.script.actions.Timer.cancel() on null
2019-11-23 15:02:56.693 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command ON
2019-11-23 15:02:56.721 [vent.ItemStateChangedEvent] - testTimer changed from OFF to ON
myTimer?.cancel solved the error message but still i have an additional delay of about 30 seconds on my 60 seconds timer (also tried another restart just to be sure):
2019-11-23 15:28:55.698 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command OFF
2019-11-23 15:28:55.717 [vent.ItemStateChangedEvent] - testTimer changed from ON to OFF
2019-11-23 15:29:01.169 [ome.event.ItemCommandEvent] - Item ‘testTimer’ received command ON
2019-11-23 15:29:01.182 [vent.ItemStateChangedEvent] - testTimer changed from OFF to ON
I’d guess your system is seriously overloaded. Are you expecting that time Item change at approx 40 secs past the minute, for example? Is that by a cron rule?
Other than that and not having all the info about your setup and system you may have to tweak the time till you have what you need. After that you need to check the regularly and verify the delay does not change.
Sorry i dont understand the question.
Just have this timer and when i turn my test switch on i expect the log “timer executed” 60 seconds after “start timer”
In the events.log you showed us there is an Item updating called date_today, I was just curious about what was doing that in case it was a cron triggered rule and could give us more insight into your system.
@Franco if you want something to turn off after a certain time you can use the Expire binding. I use this on several items e.g. a light that’s turned on will be turned off after a given time and no rule needed.