Check back on item after some time

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 :slight_smile:

Lets say I have the following setup:

  1. 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)
  2. 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 :slight_smile:

Thx in advance,

I would use a timer inside of rule 1 which end 5min after the rule is fired. Then do the things from rule 2.

Only problem I see. If rule is fired again within the 5 min ist first delayed pst 2 will not be executed because it is rescheduled.

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.

1 Like

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.

1 Like

Ah ok so would the item look this…

Switch vitem_checkInFive { expire="5m,command=OFF" }

and then the rule soemthing like ?

rule "5min over"
   Item vitem_checkInFive received command OFF

Or am I not getting the expire-binding description correct?

1 Like

Looks like you got it. :+1:

1 Like

It depends what you want to happen.

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.

1 Like

thx :slight_smile: