Setup notification with different zones and persons

I have a setup with 8 different zones, and 5 persons.
But the difficulty is, I have to make an automation for each zone and each person entering or leaving each zones.
How could I make one automation with the different zones, all in one?

An example for the automations I have now:

`alias: j arrives at sportclub

trigger:
platform: zone
entity_id: device_tracker.j_gps
zone: zone.sportclub # Event is either enter or leave
event: enter # or “leave”
action:
service: notify.telegram_f
data:
message: 'j arrived at his sportsclub`

It’ll be something like this, but you’ll need to see what data you actually need to extract from the trigger, I don’t use zone triggers. I’m presuming that trigger.to_state.friendly_name will give you the friendly_name of the device tracker and trigger.to_state will give you ‘enter’ or ‘leave’ which we just add an ‘s’ to the end of. No idea what the template will be to get the name of the zone but a punt through your logs will probably work it out…

alias: people going places 
trigger:
  platform: zone
  entity_id:
    - device_tracker.j_gps
    - NEXT DEVICE 
    - ETC
action:
  service: notify.telegram_f
  data_template:
    message: "{{ trigger.to_state.friendly_name }} {{ trigger.to_state }}s {{ TEMPLATE FOR NAME OF ZONE }}"

Thank you. I’m on my way to complete it :slight_smile:

1 Like

Here is my implementation, you can modify it to your liking:

  alias: Notify when someone enters or leaves a zone
  description: ''
  trigger:
    platform: state
    entity_id: person.one, person.two, person.three, person.four
  condition:
    condition: template
    value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"
  action:
    - service: notify.all_devices
      data_template:
        title: 'Location update {{ states.sensor.time.state }}'
        message: "{{ trigger.to_state.attributes.friendly_name }} {% if trigger.to_state.state == 'not_home' %}has left {{ trigger.from_state.state }}{% endif %}{% if trigger.from_state.state == 'not_home' %}arrived at {{ trigger.to_state.state }}{% endif %}"