[Solved]Reaction based on an entity not changing for a certain time
-
Hi,
Most of the rules are based on something happening like entity changing state, variable changing, etc. What I would like to do, is have a Rule that would be trigger when nothing is happening (on a given entity) for a certain time. When I look at the trigger, I see that we can detect when a change occurs but I cannot find a way to detect when a device is not changing state for a certain time.
Any suggestion on how I could approach that?
Thanks in advance.
-
Does the entity have a limited number of states (e.g. only True or False)? If so, you could accomplish this with two rules. For example to monitor lack of activity from Switch 1 for more than 10 minutes:
Rule 1: When: Entity | Switch 1 | == True | is sustained for 600 seconds
and
Rule 2: When: Entity | Switch 1 | == False | is sustained for 600 secondsNeither will go true as long as Switch 1 changes it's status at least every 9 minutes and 59 seconds.
Alternately, for something with more values (for example to monitor a temperature sensor that can report any number), I think it can be done with one expression and one rule. For example to monitor lack of activity from Temp Sensor 1 for more than 10 minutes, If the entity is device #65 on mycontroller:
Create a global variable (expression) like: g_temp_sensor_1_last. Set the expression to getEntity( "mycontroller>65" ).attributes.temperature_sensor.value
Create a rule where Entity | Temp Sensor 1 | == ${{g_temp_sensor_1_last}} | sustained for 600 seconds.
This should start a 600 second sustain counter every time the entity changes. HOWEVER: I tried this out on my MSR and I can't get it to consistently react more than once. I don't know if this is a bug or if I'm doing it wrong. I tried using a Pulse so the rule would self-reset after a few seconds, but then when I changed the entity (which changed the expression) it didn't start counting the sustained again... it stayed false. Doing it without the pulse resulted in it staying true even though the entity value changed. Perhaps because the entity and expression both changed at the same moment, the rule never went false? Using pulse should have worked around that, so I'm not sure why it didn't work.
For my test I was using the cooling set point of my thermostat and an expression that gets set to that value every minute by a call to the thermostat API. When the rule first runs, they are equal and the sustained counter starts. I had the rule react if they were the same for 15 seconds. The rule would trip and reset after the pulse (5 seconds). When I then changed the setpoint, causing both the entity and expression to update to a new value, the rule didn't consistently go true again. It seems like it should. I'm not sure why the change to the entity wasn't causing the rule to be re-evaluated.
-
You can do it with one rule having a subgroup, and a condition in the subgroup:
- The condition is Entity Attribute <something you want to watch> changes
- The group surrounding the condition is "NOT AND" with "sustained for X seconds"
If the entity attribute is unchanged for X seconds, the rule will Set.
In this trivial example below, the rule will set if the state of the door sensor has not changed for 1800 seconds.
-
Sure enough, it is working just as you (toggledbits) described it. Not sure I could have figured this one out. I have made many attempt using the conditions but since I was having only one, using a group never occured to me. The condition and group have similar output control and restriction but not quite the same. Lesson learned.
Thanks again
-
T toggledbits locked this topic on