Problem with timer


I have the following code in a rule:

var Timer  blindsBlockedTimer     = null

rule "Disable blinds blocking after some time"
    Item Blinds_Blocked received update ON
	if(blindsBlockedTimer == null) {
		blindsBlockedTimer = createTimer(now.plusSeconds(150)) [|
 			logInfo("blinds rules", "Auto blocking blinds disabled by timer")
 			blindsBlockedTimer = null
	        logInfo("blinds rules", "Blinds_Blocked received update ON, starting timer to disable")   
	} else {
	   	logInfo("blinds rules", "Blinds_Blocked received update ON, rescheduling timer  to disable")

Blinds_Blocked is triggered several times a day, mostly with 5-30s between individual triggers and than very long pauses (several hours).

Most of the time the code works as expected, but sometimes Blinds_Blocked will not be set to off, even 30min after the last update. It seems to work OK, when using an anonymous timer, but in this case I can not re-trigger it and the code would start several timers when Blinds_Blocked is updated while a timer is still active.

I suspect, that there is a problem with the timer, has anybody else seen such problem?


When it doesn’t work was there a reload of the rules file or restart of OH recently? When you restart or reload the rules file all your variables get reset and your timers get lost.

The code might be simpler to write and manage using the expire binding.

Expire Binding


Switch Blinds_Blocked { expire="150s,state=OFF" } // 150 seconds after it goes to ON, it will be updated to OFF, a new ON update resets the timer

Rule: No rule needed

No, openHAB is running for nearly 4 weeks without any changes. The problem occurs once or twice a week, in arround 2-3% of all cases in which Blinds_Blocked is triggered.

Thanks for for the tip with the expire binding, haven’t heard of it before but I will test ist, it looks very nice indeed!