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.
-
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.
-
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”
- 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!