When creating automations, I often make variables that simplify my conditions/actions a lot. I would love to be able to access the previous state of those variables when the automation runs. This way, I could make “stable” decisions without having to create extra helpers.
For example, I have a text sensor that can have one of three states: good, average and bad. Based on the sensor state, I take a few actions. What I would like to do is only take an action when the state stabilizes on a given value (that is, it isn’t changed for let’s say 5 minutes).
With a helper I can store the “previous” state of the sensor, and prefer that state as long as the sensor is not stable for 5 minutes. However, I don’t like to create helpers for various internal automation states.
Hmm, I should have given more information about the total automation; it also takes other sensor states into account. Those sensors have simple state triggers, so the actions might be executed if the “problematic” sensor is “bad” for only a minute.
And it’s that what I can’t figure out to do without helpers at this moment using only variables or action conditions .
As you can see, the level of my ventilation is decided by the vindriktning_air_quality (which is Good, Average or Bad), along a lot of other sensors.
As per my understanding of @tom_l 's suggestion, this would indeed trigger if the sensor would be bad for 5 minutes, but would also trigger if the other sensor (let’s say the airco panasonic_upstairs) is turned on at which point it’s hard to figure out for how long the sensor is already in the state it’s in. In this case, I won’t be able to get the previous state of the vindriktning_air_quality either as far as I understand.
The current implementation seems to be working as expected, but use a helper. It would be nice if I could just see what the air_quality variable was the last time the automation ran. Another option could be that the automation could “register” a child helper that was exclusively for the automation (and would be created by the automation and would be cleaned up if the automation would ever be deleted again).
Off course, if there would be cleaner or better alternatives for my use-case, I’m certainly interested .
If the automation triggers because the shower is on, I can figure out whether the air quality is let’s say “good” for 5 minutes. However, if that’s not the case, the current state might already be “good”, but only since 2 minutes, so I should use the previous state, which I don’t know at this moment if I understand it correctly.
Given I have multiple triggers and assuming another trigger triggered (e.g. shower turned on), and this condition is not met (let’s say the air quality was average, and is only good for 2 minutes). At this moment, I know the air quality is not yet good for 5 minutes (as the condition fails), and I can also see the air quality is currently good for 2 minutes (by looking at the current state and the last changed). How can I know that the previous air quality is average, as that is what I want to take in account at this point.
In my current implementation I do that using a helper, but I don’t see how I can figure this out by only a trigger and/or condition