Automation based on a specific person entering or leaving a zone

I have the below automation set for HA to do something based on whether I enter or leave home. This works fine, but wondering if there’s a cleaner method of setting the Trigger, ie. instead of ‘or’ as I presently have it?

alias: Presence - Home (Scott)
description: ""
trigger:
  - platform: zone
    entity_id: person.scott
    zone: zone.home
    event: enter
    enabled: true
  - platform: zone
    entity_id: person.scott
    zone: zone.home
    event: leave
condition: []
action:

I don’t now if it’s any “cleaner”, but you can use a State trigger based on the person entity:

alias: Presence - Home (Scott)
description: ""
trigger:
  - platform: state
    entity_id: person.scott
    to:
      - home
      - not_home
    from:
      - home
      - not_home
condition: []
action:

or

alias: Presence - Home (Scott)
description: ""
trigger:
  - platform: state
    entity_id: person.scott
    to: null
condition:
  - "{{ trigger.to_state.state in ['home', 'not_home'] and trigger.from_state.state in ['home', 'not_home']}}"
action:
2 Likes

2 inquiries on this…

  1. Either requires manual coding… Will this type of setup ever be implemented into the UI?
  2. What’s the difference between home/not_home and Entering/Leaving a zone?

I guess the first could be split into 2 triggers and not require any manual configuration… I haven’t seen any discussion of adding the ability for multiple selections to the State trigger, but I also don’t regularly keep an eye on the frontend arch. discussion boards.

For many use cases they’re interchangeable. One significant difference is that Zone trigger (entering/leaving) requires a device tracker platform that supports reporting GPS coordinates. State trigger will work with non-GPS device trackers as well but, IIRC, will not work with passive zones.

1 Like