@carltonb
Although I can’t answer the WHY part with any authority or specific knowledge, my guess is that the HA app continues to seek out the best service, and in the process may fail to recognize that you haven’t actually moved from your WORK zone to AWAY, triggering another message. The first condition:
{{ trigger.from_state.state != trigger.to_state.state }}
forces the automation to look for a change in locations. For example from WORK to AWAY. If there was a drop of signal or a change in cell towers, the automation would not fire if your location went from WORK to WORK, but will fire for WORK to AWAY.
The second condition put a time delay in how often the automation can actually fire.
this.attributes.last_triggered is not defined or now() - this.attributes.last_triggered >= timedelta(minutes=5)
can be made a little more readable (and functionally equal) by changing it to this:
# Only run if more than 5 minutes (900 sec) since it last ran
value_template: >-
{{(as_timestamp(now(),0) - as_timestamp(state_attr("automation.NAMEOFYOURAUTOMATION", "last_triggered"),0) | int > 900 )}}
# Now as a timestamp value MINUS the timestamp value of the last trigger of your automation.
# The resulting number (as an INT) is the seconds elapsed. If Greater than COMPARISON VALUE (900) then TRUE. Automation continues. If FALSE, automation STOPS.
As you may notice, there are some subtle differences between the newer way and the old way of writing this, but both work the same for what you are trying to do. There are also two ways to write the older version, which can be seen in the two other examples below. I prefer the second way, for both readability and not having to enclose everything in quotes. Beware of using ’ to enclose the template and ’ to define entity and attributes. See the " in the example above.
'{{(as_timestamp(now(),0) - as_timestamp(state_attr('automation.NAMEOFYOURAUTOMATION', 'last_triggered'),0) | int > 900 )}}'
The above line WILL FAIL! Single quote enclose the entire template AND single quotes define the entity and attribute.
Using both should greatly reduce the number of False notifications but may block a notification if you move from zone to zone with a short interval of staying at any location. Do keep in mind, if you drive in and out of a zone, you will get the ENTER notification but NOT the EXIT (unless your drive is greater than 5 minutes). Personally, I do not use the delay on all my zone automations for that reason, but I think it is a useful tool if you get way too many triggers.
There are also many opportunities to use this condition to your advantage. Consider this Rain Nearby notification:
- condition: template
# Only run if more than 2 hours (7,200 sec) since it last ran
value_template: '{{(as_timestamp(now(),0) - as_timestamp(state_attr("automation.its_raining_nearby", "last_triggered"),0)> 7200 )}}'
or this HVAC automation
- condition: template
# Only run if more than 60 seconds since it last ran, eliminates repeat trigger events
value_template: >-
{{(as_timestamp(now(),0) - as_timestamp(state_attr("automation.hvac_set_mode_1", "last_triggered"),0) | int > 60 )}}
I hope this explanation helps you build a better automation experience in your home. I have learned many of these gems from other users here, so I am not the guru, but I do like trying to give back when I can. If my answers have helped you fix your problem, please remember to make it as a solution so others can benefit from it.