Help with a timer rule

I have the following rule setup:

rule "Timer stair_light"
    Item stair_light changed to ON
    if(stair_light.state==ON) {
        if(timer==null) {
            // first ON command, so create a timer to turn the light off again
            timer = createTimer(now.plusSeconds(10)) [|
                logInfo("/var/log/openhab2/openhab.log", "stair_light turned off automatically by timer")
        } else {
            // subsequent ON command, so reschedule the existing timer
    } else if(stair_light.state==OFF) {
        // remove any previously scheduled timer
        if(timer!=null) {
            timer = null

This works great (only have it set to 10 seconds for testing) if and only if OpenHab sends the command to turn the lightswitch on. If the actual lightswitch is turned on manually, the timer never turns the light off; I’m not sure if this is by design or something I have mis-configured within OpenHab.

Here is how the item is setup:

Switch stair_light “Stair Light” (AllLights) { zwave=“5:command=switch_binary,refresh_interval=15” }

Light switch is a GE 12727, and the z-wave controler is an Aeotec gen 5 USB stick, OpenHab 2.0 on a raspberry Pi 3 Model B.

Any help would help would with what I might be missing would be fantastic! :weary:

look in the log, do you see your Item stair_light getting an update? is that ON?

2017-03-04 12:00:13.260 [ItemCommandEvent          ] - Item 'stair_light' received command ON
2017-03-04 12:00:13.275 [ItemStateChangedEvent     ] - stair_light changed from OFF to ON

That is from my event log and I should of mentioned I was checking via /rest/items/stair_light to see the state if the light switch is manually turned on.

When diagnosing, sprinkle some more logInfo e.g. first line of rule to see if it is triggered,and which if-else paths are followed.

Your timer only gets nulled when stair_light changes to ON and stair_light is OFF - and if the timer isn’t null you don’t make a new one.
Consider changing your logic, perhaps trigger the rule on any change.

The rule used to be set to Item stair_light changed, I switched to be a state of ON to try and rule out issues with the timer variable.

Most of my confusion comes from this working as expected when OpenHab turns on the light, and knows the state is set to ON when I manually change the switch…to me this is a binary state and should behave the same way regardless of how the state changes.

I have even tried the expire binding and reproduced my issue. However testing again with the zwave1 binding instead of zwave and the expire binding just solved my issue. :angry: Guess I will revisit timers when I obtain more automation devices, thanks for your time @rossko57