Problem with Expire binding and Timer action

Hello, I have a switch which I want to apply a timer to. When the switch receives ON (either through a cron job or manually, i.e. BasicUI) a 2 hour timer should start. When the 2 hours has passed the switch should receive OFF command.

The automatic ON command using cron jobs is working as expected, but I can’t get the automatic OFF command working.
If I manually send ON or OFF command from Basic UI the switch changes from ON to OFF or OFF to ON, so communication is working.

I’ve tried both Expire binding and Timer action without success.

My environment:
Rasperry Pi 3 Model B Plus Rev 1.3 with Z-wave.me RaZberry card
OpenHabian, Linux openhab 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l
OpenHAB 2.2.0-1
Java version 1.8.0_171

Expire binding (binding is installed and RPi restarted after installation):

Item definition

Switch TowelDryer "TowelDryer" <radiator> (Group1, Group2) { zwave="4", expire="30m,command=OFF"}

If I set the expire time to 10s, the OFF command is sent to the switch and it switches off as it should. This also works when I use 1m and 10m as expire time, but not with 30m, 60m, 120m, 2h… as expire time. Using expire times 30m or longer doesn’t send the command OFF to the switch. I haven’t yet exactly determined which the longest working expire time is.
When I add, change or remove the expire binding from the item definition I get an entry in the log file that says that the Expire Refresh Service has been started/shut down respectively.

Timer action in a rule:
I’ve also tried the timer action in a rule. When I send the command ON to the switch, manually from BasicIU or as a cron job, I get this error message in the log:

[ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Timer Rule': An error occurred during the script execution: index=1, size=1

The item definition now looks like this:

Switch TowelDryer "TowelDryer" <radiator> (Group1, Group2)

The rules looks like this. It’s the third and last rule that contains the Timer action:

var Timer myTowelDryerTimer = null

rule "Morning rule"

when
        Time cron "0 30 5 ? * *"
then
        if (TowelDryer.state == OFF) {
                TowelDryer.sendCommand(ON)
        }
end

rule "Evening rule"
when
        Time cron "0 0 20 ? * *"
then
        if TowelDryer.state == OFF){
                TowelDryer.sendCommand(ON)
        }
end

rule "Timer rule"
when
      Item TowelDryer changed from OFF to ON
then
      myTowelDryerTimer = createTimer(now.plusMinutes(120) [|
              TowelDryer.sendCommand(OFF)
      ])
end

What can I do?

My max time with the expire binding is 4 hours, works as expected.

You are missing an opening bracket and a space:

if (TowelDryer.state == OFF) {

Also wrong brackets here:

myTowelDryerTimer = createTimer(now.plusMinutes(120)) [ |
              TowelDryer.sendCommand(OFF)
      ]

You should use Visual Studio Code with the openHAB extension to verify your syntax:

Also a note on the expire timer: every time you do send an ON to the switch the timer will start again.

Thank you for the quick answer. Timer action now working as expected.
/Anders

1 Like

This is the key. It isn’t just an ON command but an ON update. @AndersHn, if the Z-wave.me binding is like the Zwave binding, there is a 30 minute polling period which means the Item is being update every 30 minutes, resetting the expire binding on every update.

1 Like

Interesting, never thought about that, thanks. All my items using expire timers are virtual items :sunglasses: