Allow a Zone grabbed by zone selector to be used as a zone trigger in a BluePrint

I have been trying to use the Zone Selector, but it appears to me to be of little use. It produces a list of the Zones found, but when trying to apply the zone collected into a zone trigger in a Blueprint, there is an error.
This is likely a ‘feature’ of the limited template, but entities and other things work in triggers with !input or trigger variables, why not zones?

Full Blueprint and error log can be found here,

but in summary this is what I’ve found.

Plugging the !input value of the zone into the zone trigger drops an error. So does using a trigger_variable to convert the !input value to a variable and plugging the variable into the zone line. It appears the only thing the zone line on the zone trigger will accept is a string representing the text of the zone you want to refer to. Not the zone entity and not a template of the string, only the string.

Please point me in a direction or correct me if I’m wrong…

I have tried setting it as a trigger variable, and it wouldn’t read it. I tried as a straight-up !input, that said this is not string.

Blueprint 'Person Alert Honitor - 2023-02-22' generated invalid automation with inputs .>. Entity ID {{ trigg_1 }} is an invalid entity ID for dictionary value @ data['zone']. Got None
Blueprint 'Person Alert Honitor - 2023-02-22' generated invalid automation with inputs  .>.  value should be a string for dictionary value @ data['zone']. Got None
trigger_variables:
  trigg_1: !input zone2monitor
trigger: 
  - platform: zone
    id: enter_trigger
    entity_id: !input people2monitor
    zone: '{{ trigg_1 }}'
    event: enter
trigger_variables:
  trigg_1: !input zone2monitor
trigger: 
  - platform: zone
    id: enter_trigger
    entity_id: !input people2monitor
    zone: !input zone2monitor
    event: enter

Discord Thread about this

Keep in mind this is a Blueprint I want to share with others, so creating a companion helper is not an ideal option. It just seems to me that there should be a way to do this. Don’t thibk it would help anyway.

I realize that this is quite old, but did anyone find a way to make this zone trigger work with blueprints ?

I know that an alternative solution would be to use the state trigger on the person entity, but that would not work with passive zones.

Thanks !

I’m not as seasoned a Blueprint creator as SG, and I don’t really use passive zones, but could you use a State trigger targeted at the person attribute of the zone(s)?

...
trigger_variables:
  people: !input people2monitor
trigger: 
  - platform: state
    entity_id: !input zones2monitor
    attribute: persons
    variables:
      to_list: "{{ trigger.to_state.attributes.persons }}"
      from_list: "{{ trigger.from_state.attributes.persons }}"
      event: "{{ 'enter' if to_list | count > from_list | count else 'leave' }}"
      person: |
        {% set combined = [to_list, from_list] if event == 'leave' else [from_list, to_list] %}
        {{ (combined[1]|reject('in', combined[0])|list)[0] }}
condition:
  - alias: Check if person is in Monitored list
    condition: template
    value_template: "{{ person in people }}"
action:

I didn’t.
Been thinking about why I would want to use passive zone, which slipped under my radar until you mentioned them. Not sure what I would do with them.

Anyway the project above I went with person triggers.

https://github.com/SirGoodenough/HA_Blueprints/blob/c05d6fb431c1d84cb145c7d6dd5ffe5a60b1d9e2/Automations/Person_Alert_Blueprint.yaml.

Also found this, maybe help you?
How to use passive zones with automations.

Thanks for both your answers.

The state trigger is an option as long as the zone is not set to passive (the passive option makes the zone barely invisible in the HA frontend, person entities do not get status update when entering passive zones, and only the zone trigger would work for those zones).

I finally found a workaround for the blueprint, it is not perfect, but if you use a text for the zone input (the user types the name of the zone, ie. zone.xxxx), it works with the !zone_xxxx placeholder.

Example (code truncated, invalid indentation) :

 blueprint:
    input:
      location_zone:
        name: zone entity
        default: "zone.home"
      location_entity:
        name: person or tracker entities
        selector:
          entity:
            multiple : true
            filter:
              domain:
                - person
                - device_tracker
        default: []

 trigger:
    - platform: zone
      entity_id: !input location_entity
      id: location
      zone: !input location_zone
      event: enter
 
 action:
   - choose:
       - conditions:
           - condition: trigger
             id:
               - location
           - condition: template
             value_template: "{{ not not location_entity }}"
         sequence:
           ...

An important thing with this code is to keep a valid default zone (ie. “zone.home”) even if the user of the blueprint does not want to use any zone based trigger.
An empty string for the zone placeholder would cause an HA error when loading the automation. You can however keep the person entity empty (no person or tracker selected) and that’s how I avoid the automation to run on the default zone.home (see action condition).

It’s not a perfect solution and in many cases the state trigger on the person entity would be a more elegant solution, but if you intend to use the trigger with a passive zone there is no other option so far.

Cheers !

I’m not sure I’m seeing what you think is wrong with the zone trigger. This seems to work fine for me, am I missing something?

blueprint:
  name: Zone Trigger
  domain: automation
  input:

    zone2monitor:
      name: Zone to watch
      selector:
        entity:
          multiple: false
          domain: zone

    people2monitor:
      name: Person or People to follow
      selector:
        entity:
          multiple: true
          domain: person

    enter_action:
      name: Enter the Zone Action
      default: []
      selector:
        action: {}
    leave_action:
      name: Leave the Zone Action
      default: []
      selector:
        action: {}

trigger:
 - platform: zone
   id: enter_trigger
   entity_id: !input people2monitor
   zone: !input zone2monitor
   event: enter

 - platform: zone
   id: leave_trigger
   entity_id: !input people2monitor
   zone: !input zone2monitor
   event: leave

action:
  - alias: Lets do an action based on the data we collected
    choose:
    - alias: Person has arrived
      conditions:
      - condition: trigger
        id: enter_trigger
      sequence: !input enter_action
    - alias: Person has left
      conditions:
      - condition: trigger
        id: leave_trigger
      sequence: !input leave_action

This was written a year ago, and at that point I don’t think the !input worked as shown by the errors in my first post. Also a template was not allowed.

I see an !input worked for you now.

Trying to remember, it might have been that the zone selector can have multiples, and the trigger would not accepts the list. Hard to remember.

I ended up coding around it and sorted the stuff out in conditions instead of trigger I think… Ya, I decided to trigger on any change to any of the people in the list being monitored and then got the zone list friendly names direct from the input.

HA_Blueprints/Automations/Person_Alert_Blueprint.yaml at c05d6fb431c1d84cb145c7d6dd5ffe5a60b1d9e2 · SirGoodenough/HA_Blueprints · GitHub.