Trigger action on a list of zones (labels & template trigger)

I wanted to trigger a notification when my spouse is detected in an airport, to passively inform me she’d landed safely, without her having to send me a message. I initially had created a separate trigger (multiple “or” triggers) for each airport zone I had created, but the additional of labels has simplified this. I don’t need to keep adding a new trigger each time I define a new airport zone, but simply label the zone, once defined as an airport zone.

  1. Set up each zone, and go to settings>>devices&services>>entities, and create a new label and apply it to all of the airport zones. In my example I named the label “Zone Airport”, so I new the label was for a zone when managing labels.

  2. Since the person I am tracking will have a state equal to the friendly name of the zone they are in, I use the following template to determine if the person’s current state is “in” the list of airport zones, like so:

{{ states('person.your_person') in (label_entities('zone_airport') | map('state_attr', 'friendly_name') | list ) }}

NOTE: In the part where the label entities are being mapped, zone_airport is the label_id, not the label friendly name. You need to work in the template area of Developer Tools to find the label_id by returning the id from the friendly name. In my example the friendly name for the lable is “Zone Airport” and {{ label_id("Zone Airport") }} returns zone_airport.

Test finding the label_id in developer tools >> template, and it then once you see that this {{ label_entities('zone_airport') | map('state_attr', 'friendly_name') | list }} is returning a desired list of zones, use the ful “person … in label entities” code above in your automation as a single template trigger that will fire any time the person is in one of the zones with the label “Zone Airport”

  1. With a uniform naming convention for my airport zones, I further used templates to define the various bits of text for my notification. The following variable action parses a state value of “Boston: Logan International Airport” (which, remember, is also the friendly name of the airport zone) into “Boston” and “is at the Logan International Airport”, splitting on the “:” for use in the notification message:
variables:
  zone: "{{ trigger.to_state.state }}"
  location: "{{zone.split(':')[0]}}"
  message: is at the{{zone.split(':')[1]}}

So as long as I name all my airport zone with a colon, I can easily split the pieces/parts.

This same strategy works for triggering on entry into a list of zones labeled “Zone Supermarket” if, for example, you might want HA to notify you that your spouse is picking up groceries, and you should be ready to help bring the bags of food inside!

Hello Frank Snyder,

Will my code in this blueprint help you at all?

That’s some nice work you did there! Thanks for sharing. In my case, I’m already very comfortable building automations, and writing a bit of yaml with templates as needed. So, for me, the blueprint is just extra, but I will play with it a bit to see what I might learn.

And, yes, one could definitely use this blueprint to do what I did. For anyone that would want to dynamically manipulating a zones list that an automations is triggered by, and use my labeling strategy to select a subset of the zones in their HA instance, they would just put a value like this in the blueprint input for “Zones to watch”, where zone_airport is the label_id for the label being used.

{{ label_entities('zone_airport') | list }}

Blueprints are just automations…
The code is the same.
This pulls the friendly name attribute out and I think does what you are looking to do if you look at it and pull the pieces you need.