Hi,
this question might be a little basic and was probably answered a few times before but I just cant seem to find the answer to it my self
Lets say I have the following setup:
A virtual switch item is set to ON and a rule is saving the time when it was set to on in an item of type Number as unixtime (epoch-time)
After 5 minutes (based on the saved unix time from step one) some other item-state is checked
(something like “Last_saved_unixtime > Last_saved_unixtime + 300000”)
How would I do something like this? Because using a rule which triggers every 5 minutes seems to be a little over-the-top since I only need the rules once when the virtual switch is set to ON in the first step.
I hope someoone can help me with this or maybe point me in the right direction
So this would mean that openHAB would “stay” 5min in rule 1 because of the timer?
I mean if this would only block this one rule, that would be fine since the rule 1 would not be fired during the 5minutes time-period.
Background is: I like to start a rule when one network device goes offline. The rule then checks the watts of a socket and checks after 5minutes of the socket is still in a specific range. If yes, the socket would be turned off, if not nothing happens because it was just a wrong value or a random drop.
The rule ends but the timer runs. If the timer end, the part inside of the timer runs.
I would do it in an other way
Use a proxy item with expire binding (5min Command = OFF).
If the device goes of, change proxy item to ON . And trigger on these proxyitem to change to OFF.
I would turn on another’s virtual switch with expire binding and a 5m timeout. Then have a rule that looks for that switch turned to off and act on it.
Let’s offer a description of what it actually does -
If your switch changes state to ON, a 5 min timer starts up.
If nothing else happens, at the end of 5 minutes an OFF command is issued.
But - if the switch receives a further update to ON, a periodic report for example, the expire timer will restart/reschedule and begin counting down from 5 minutes again.
But - if the switch changes to OFF during the 5 minutes, nothing happens later. The expire action is not taken because existing state is already OFF.
Also - if your network blows up and the switch is updated to UNDEF, the timer starts over again from 5 minutes (due to the update) and will issue command OFF later (because state is not already OFF).
Thanks for the in-detail-explanation. Do you know if there is a way to stop any current time? maybe something like sending an off-command to the item with the expire parameter set?
The only way to stop a running expire is to set the Item state to one that matches the command or state that the expire will issue.
For the example, vitem_checkInFive.postUpdate(OFF) would do.
If you want flexibility, you’ll need to use “proper” rule based timers.