Better zone triggers + tags

I recently started working more with Zones and I must say it is pretty basic and lacks functionality other entities have.
For example, I want to create zones for several hardware stores nearby, and when I’m there, I want a notification that opens hardware store shopping list. Same thing with groceries.

The thing is - Zone trigger does not support multiple zones. Other entities doesn’t support it in GUI, but when you switch to yaml, you can trigger when input_select.mode changes to Morning or Day - as one trigger. However, with Zones, this doesn’t work:

trigger: zone
entity_id: device_tracker.***
zone:
  - zone.tesco
  - zone.globus
  - zone.kaufland
event: enter

Currently, you have to make 3 triggers. Ugly. Can we please get multiple zones in trigger supported? Also, can we have option to trigger on ANY zone and have tags supported on Zones? Basically it would work same way as “entity changes from unknown/unavailable”.
Then I can mark zone.tesco, zone.globus and zone.kaufland with “groceries” tag, and zone.hornbach, zone.obi as “hardware store” tag. Then I’d trigger on ANY zone, and in condition check whether it is “hardware store” to send correct notification. Much cleaner than to repeat all zones of the same type in all automations.

It does not need to.

I’ve removed some identifying information so I don’t get doxed but you should still be able to see how this works:

- id: 118a6c0d-52c3-4538-8784-abaeca360cab
  alias: 'Shopping Notify'
  max_exceeded: 'silent'
  triggers:
  - id: bunnings
    trigger: zone
    entity_id: device_tracker.iphone13
    zone: zone.bunnings
    event: enter
  - id: jaycar
    trigger: zone
    entity_id: device_tracker.iphone13
    zone: zone.jaycar
    event: enter
  - id: shopping_list
    trigger: zone
    entity_id: device_tracker.iphone13
    zone: zone.redacted
    event: enter
  - id: shopping_list
    trigger: zone
    entity_id: device_tracker.iphone13
    zone: zone.redacted
    event: enter
  - id: redacted
    trigger: zone
    entity_id: device_tracker.iphone13
    zone: zone.redacted
    event: enter
  conditions:
  - condition: or
    conditions:
    - condition: and
      conditions:
      - condition: trigger
        id: bunnings
      - condition: numeric_state
        entity_id: todo.bunnings
        above: 0
    - condition: and
      conditions:
      - condition: trigger
        id: shopping_list
      - condition: numeric_state
        entity_id: todo.shopping_list
        above: 0
    - condition: and
      conditions:
      - condition: trigger
        id: jaycar
      - condition: numeric_state
        entity_id: todo.jaycar
        above: 0
    - condition: and
      conditions:
      - condition: trigger
        id: redacted
      - condition: numeric_state
        entity_id: todo.redacted
        above: 0
  actions:
  - action: notify.mobile_app_iphone13
    data:
      message: "🛒 Time to shop? (long click to open list)"
      data:
        actions:
          - action: URI
            title: View shopping list
            uri: "/todo?entity_id=todo.{{trigger.id}}"
1 Like

That is exactly what I said. You currently have to create multiple triggers. While othe entities support trigger on multiple values. One trigger, multiple values:

trigger: state
entity_id:
  - input_select.mode
to:
  - Night
  - Away
  - Holiday

So it would be great if there is the same possibility for Zones.

did you consider templating the notification itself?
my presence notifications only use the person entities I need to track, and in the template for the notification you can set any group of zones you like in a list , and check whether the trackers state is in that list of zones

          message_en: >
            {% set tostate = trigger.to_state.state %}
            {% set fromstate = trigger.from_state.state %}
            {% set zones = label_entities('zone')
                |map('state_attr','friendly_name')|list %}
            {% set name = trigger.to_state.name %}

            Hi, at {{now().strftime('%X')~' '}},
            {%- if tostate == 'not_home' and fromstate in zones and fromstate != 'home' %}
              {{name}} left {{fromstate}}
            {%- elif tostate == 'not_home' and fromstate not in zones and
                     fromstate == 'home' -%}
              {{name}} left {{fromstate}}

            {%- elif tostate == 'not_home' and fromstate == 'driving'-%}
              {{name}} stopped {{fromstate}}

            {%- elif tostate == 'home' and fromstate == 'driving' -%}
             {{name}} stopped driving and arrived home.

            {% elif fromstate == 'not_home' and tostate == 'driving' -%}
              -{{name}} left and started {{tostate}}
            {%- elif tostate == 'driving' -%}
              {{name}} left {{fromstate}} and started {{tostate}}
            {%- elif fromstate == 'not_home' -%}
              {{name}} arrived at {{tostate}}
            {%- elif fromstate == 'driving' and tostate in zones -%}
              {{name}} stopped {{fromstate}} and arrived at {{tostate}}
            {%- else -%}
              {{name}} left {{fromstate}} and arrived at {{tostate}}
            {%- endif %}

this is without grouped zones but you get the idea :wink:

Use a state trigger.

triggers:
  - trigger: state
    entity_id: device_tracker.***
    to:
      - tesco
      - globus
      - kaufland
2 Likes