Periodic test for how long a switch is on

I am trying to automate some failover conditions. To do one of these I need to test every 20 minutes if a switch has been off for an elapsed time and then turn off a different switch.

I can trigger if a switch has been off for a set time but not to check it every 20 minutes.

Is this possible?

It will be possible, maybe two rules. Something along the lines of…..

Rule 1 required expression private boolean true.
Trigger - when switch is turned off
Actions:

  • set PB false
  • Repeat every one minute while condition true
  • Add 1 to a hub variable that you’ve created
  • End repeat
  • Wait for event switch turns on
  • Set the hub variable to 0
  • Set PB true

Rule 2 could have a required expression of that same switch above being off.
Trigger every 20 minutes
Actions - turn your target switch off

Although I do recall someone creating an app for this or there’s already something available without using RM.

What is the necessity for checking every 20 minutes? Is it not enough to trigger once the switch has been off for X minutes?

1 Like

In this situation it is if the command to turn the lights off was sent but one of the lights didn’t actually switch off, a situation I sometimes get with my hue lights. I want to automate the retry so that it reattempts particularly when I am away.

The other situation is if one of the sensors has lost power I want to know if it is stuck open, it hasn’t changed for a determined interval, and stop using that sensor until the battery is replaced, again for when I am away.

The first situation is likely resolved by retrying commands within rules, depending on how you have connected the Hue devices, i.e. via a Hue bridge or directly to HE.

1 Like

The second situation is one that is likely worthy of more discussion that I am not sure what the best solution will be...

Can you tell me a bit more please, I am connected via a Hue Hub using CoCoHue I also have a matter bridge to the same Hue Hub. Matter works fine for switches and sensors but not to set colours on light bulbs, I have a virtual switch that tells me if the lights are expected to be on or off.

You might be stretching my brain at this time of.. the morning.... Although I can respond at this time....

For devices that have likely lost power and no longer reporting... Holistically I would suggest using @bptworld 's Device WatchDog (why dop I feel like I should be referencing an app by @bertabcd1234 ....)

The sensor battery solution I was going for is mainly possible as I connect my sensors to Matter and then set a 'presence' virtual switch for Habitat (which does all my real logic) when it is triggered.

So I was looking to check if a sensor hadn't changed for a few hours and if that was the situation turn off the 'presence' virtual switch on the basis that if the battery was dead it would never change the virtual switch. Fallback would be to reset all the virtual presence switches overnight.

My brain isn't really in the zone,... hopefully others can chime in....
The main thing to be sure of is to think about periods where there can be legitimately no motion reported.

Beyond that, I think ypu can manage the rest...

1 Like

Is this what you are looking for? A trigger for a switch being off for a period of time (20mins) w/o having to poll. This is how I would do that in RM.

1 Like

That is very close I believe the rule can only be used as part of an on/off trigger and not as a conditional statement, which was my issue.

I guess could probably do something using either more virtual switches or a boolean, many thanks it has clarified why I couldn't find the 'and stays' parameter.

Another possibility is for you to use a different type of logic (much simpler), using the following type of switch:

(it's an oldie but goodie!)
It allows you to set a switch to be on, which then goes off at exactly 20 minutes (completely variable, of course).
You then just have to check if the switch is on or off.

1 Like