Check if a certain state change happened in the last 5 min

I have a welcome-light rule in which I check for presence through the TR064 binding and then turn on all lights if someone “comes home”. Works well but;

In very special situations, my router needs to automatically reboot during the night - and there it resets the precence indicators - which results in all lights turning on in the middle of the night. Not so clever (according to my wife) :slight_smile:

I want to add an “if”-statement to my welcome light rule, where it only turns on the lights if a certain state change for an item has not happened within the last 5 min.

What I would like to check, is if this statement in the log happened within the last 5 min:

fboxReboot changed from OFF to ON

I have persistance up and running - and know how I can check what a status was 5 min ago - but how to check for a state change ??

You could set a timer that resets an indicator of the change after 5 minutes, e.g.

var Timer myTimer = null

rule "5 min delay"
when 
    Item fboxReboot changed from OFF to ON
then
    myIndicator.postUpdate(ON)
    myTimer = createTimer(now.plusMinutes(5), 
             [
                 myIndicator.postUpdate(OFF)
             ])
end

and then react on the change of “myIndicator” item

1 Like

This is a very common use for the expire feature of an item. Depending on how your fboxReboot item gets set back to OFF you can either set the expire directly on that item or create a secondary switch item that locks out the light rule like the myIndicator in Jens’ post above, but instead of a rule with a timer just use the expire setting to have the locking item return to OFF after 5 minutes.

Another alternative would be to have an item that holds the timestamp of when fboxReboot last changed. If fboxReboot is coming from a channel then you can have a second item from that channel that uses the timestamp profile and then in your lighting rule you can just compare the time of that timestamp to now.

2 Likes