If you really want to know how it works, just read the code.
Before I explain this in a bit more depth, Iâll state I donât necessarily agree that it should work this way. I didnât write it originally. Iâm just trying to explain how it currently worksâŚ
Basically, for each entity listed in entity_id
, it effectively maintains a flag that indicates whether or not a change of state for that entity has caused the automation to trigger, which is initialized to False
when the automation is initialized. (I say effectively because the implementation is actually a list
, but thatâs not really important.) As @rccoleman pointed out, the automation is initialized when HA starts, but also when automations are reloaded, or when an individual automation is turned off and back on. So when these things happen all the âflagsâ are reset to False
.
Next, as I mentioned earlier, the triggers are only evaluated when an entity changes state. This could be when the âstate stringâ changes, or even when only one of the attributes changes. Or it could even be when nothing in the entityâs state changes (if that entity âforcesâ state changes.) Technically this is when a state_changed
event is fired for the entity.
So, when an entity changes state, its numeric value will be compared against the above
and/or below
parameters. If it meets the requirements, and the flag has not yet been set [which is the case after the automation has been (re)-initialized], the trigger will âfire,â and the flag for that entity will be set. This prevents future state changes for that entity that meet the requirements from re-triggering the automation until a state change that does not meet the requirements resets the flag, after which the next state change for that entity that does meet the requirements will trigger the automation again.
I think the original goal was probably to prevent successive state changes that all meet the requirements from causing multiple triggers. Itâs been described as requiring âthe boundary to be crossedâ, but thatâs not really how it works.
Itâs also worth noting that a state which cannot be interpreted as a number will also reset/clear the flag. So, in this example (w/ âbelow: 100
â), the following sequence of states:
99, unknown, 99, 99, unavailable, 99, 98, 1, 100, 50
would cause 4 triggers.