OpenHAB 3.1 expire command does not always work

Hello Friends,
I require some assistance configuring Expiration Timers for a few Items controlling Z-Wave switches.
I recently had to format my Raspberry Pi OS, so I took the opportunity to update my OpenHAB system to version 3.1 as a fresh install (building everything anew).
The system is installed on a Raspberry Pi 4 4GB running Raspberry Pi OS with Desktop.
I added a few Z-Wave Things and created corresponding Items to control the Z-Wave switches.
I would like two Items to automatically turn OFF after 1h0m0s, and one Item that needs to automatically turn OFF after 1h30m0s.
I defined the Items in OpenHAB and added the Metadata for the Expiration Timer, but the Items donā€™t turn OFF when the timer was supposed to finish.
The weird thing is, I tested all three Items configured with an Expiration Timer of 0h5m0s and the three of them turned OFF properly.
Am I doing something wrong?
Any help would be much appreciated.

See

3 Likes

Thank you very much, @rossko57, for pointing me to the cause of the problem :pray:
Iā€™m sorry for not understanding the proper way to solve this issue, but could you explain how I should proceed?
Do I need to create a separate rules file?
What commands should I include in it?

Yes, use rules with a Timer. Your choice of rules language (except Blockly has no timing functions yet). Many examples in this forum.

1 Like

Thanks. Iā€™ll try it tomorrow :pray::pray:

You can still use the expire if you set up a virtual/dummy switch as it will not be affected by the z-wave updates.
I use this method all the time.
image

2 Likes

Also a great suggestion
Here is a design pattern which explains the concept by our own illustrious Rich Koshak

1 Like

Thank you friends for the good advice.
Can someone suggest how I should go about writing a script in the UI Rule creator?
Previously, when I used OpenHAB 2.5.11 I had a rule file (in /etc/openhab2/rules) for automatically turning off the water boiler, but when I paste the full text I had in the file into OpenHAB 3.1 Rule DSL (v1) it does not work.
Am I doing something wrong?

rule "Turn Off Water Boiler"
when
         Item Boiler_Switch changed from OFF to ON
then
var Timer myTimer = createTimer(now.plusMinutes(60), [ |
    logInfo("rules", "Timer activated")
    sendCommand(Boiler_Switch, OFF)
])

end

Iā€™m not sure because not using OH3 yet but I think in a UI create rule, you donā€™t put the ā€˜ruleā€™ ā€˜whenā€™ or ā€˜thenā€™, you only paste into the script box the portion of the rule between then and end
the UI takes care of the when part and rule name ect.

2 Likes

You just need the code for the then part as you have already coded the event of when changed from off to on in the UI.

image

1 Like

Or if you are comfortable using text rules, continue to use text rules. Paste the whole show into a xxx.rules file and stuff works as it did in OH2.

1 Like

This worked. Thanks for the tip :slight_smile:

Many thanks to all of you for the help :pray:

Good day everyone,
Small question, is the timer feature limited to 60 minutes maximum?
I defined one DSL rule to turn off one item automatically after 60 minutes, and it works great.
Rule 1, Item 1:

var Timer myTimer = createTimer(now.plusMinutes(60), [ |
    logInfo("rules", "Timer activated")
    sendCommand(Boiler_Switch, OFF)
])

However, when I defined a second DSL rule to turn off a second item automatically after 90 minutes, the item actually turned off after 30 minutes.
I used exactly similar commands in both cases, except for the timer length.

Rule 2, Item 2:

var Timer myTimer = createTimer(now.plusMinutes(90), [ |
    logInfo("rules", "Timer activated")
    sendCommand(Bathroom_Switch1, OFF)
])

This has nothing to do with the expire feature, the topic of this thread.

No.

Note that if your rule runs once, it will create a timer.
If it runs again, it will create another independent timer, but not cancel or destroy the first one. That will still go off 90 minutes after the first run.

However, I would guess you have fallen into the ā€œorphaned timer by file editingā€ pitfall.

1 Like

You are correct, I apologize. Next time Iā€™ll ask a question, Iā€™ll double check it directly relates to the thread topic. If not, Iā€™ll search for the right thread to post the questions on.

Thank you. This explains why my item would stop after inconsistent times. I wasnā€™t aware timers work independently of the item itself.
I guess itā€™s time for me to learn how to use the virtual/dummy switch suggestion.

Or learn how to use rules-managed Timers. They can be cancelled or rescheduled.

2 Likes