Getting a list of friendly names given a list of zones from the zone selector

I have found and figured out how to ‘convert’ a list of for instance sensors into a list of their friendly names, but Zones do hot have an entity_id attribute. I have been struggling with templates to figure out a solution, but am not having any luck.

1: So given a list of zones like you would get using a zone selector, how can I generate a list of the zones’ friendly_name(s). I need those because that is the actual value of the person entity and I want to see if the person is in one of the zones in a list.

2: I don’t think this is possible, but as a random thought if I could use the zones friendly name as reported by the person entity and connect that back to the actual zone entity, I could make that work as well.

3: As a fallback I could compare the persons attribute in the zone to see if it has person. Just thought of that one, haven’t tried it yet. (update, won’t work, logic is wrong)

Anyhow I bet there is a way to do that first one and would like to know if anyone has found it.

Of course none of this would be necessary if I could solve my first pass at all this. I can’t get the zone selector and the zone trigger to talk to each other…

The following is working as a script. I haven’t messed with Blueprints much… so not 100% sure it will work there.

alias: Test zone field friendly
fields:
  zones:
    name: Zones
    description: The zones
    selector:
      entity:
        domain: zone
        multiple: true
sequence:
  - service: persistent_notification.create
    data:
      message: >
        {% set ns = namespace(zone=[]) %}
        {% for z in zones %}
        {% set ns.zone = ns.zone + [states[z].attributes.friendly_name] %}
        {% endfor %} 
        {{ ns.zone }}
mode: single
1 Like

I’ll give it a shot. Thanks!

Update…

Works like a champ.
I would not have come up with that namespace command in a million years…

1 Like