Zone notifications (leave and enter) over XMPP

This will send an XMPP notification when an identified person enters or leaves a particular zone

Notes:

  1. This requires the XMPP integration to be configured, instructions here
  2. I have not figured out how to make the xmpp service configurable, so it currently has to be hard coded into the blueprint after importing

The code:

blueprint:
  name: Zone Notification - xmpp
  description: Send a notification via xmpp_jp when a person leaves or arrives at a specific zone.
  domain: automation
  source_url: https://gist.github.com/joshp23/770bb214b5c905c467ec2172340c7067
  input:
    person_entity:
      name: Person
      selector:
        entity:
          domain: person
    zone_entity:
      name: Zone
      selector:
        entity:
          domain: zone

trigger:
  platform: state
  entity_id: !input person_entity

variables:
  zone_entity: !input zone_entity
  zone_state: "{{ states[zone_entity].name }}"
  person_entity: !input person_entity
  person_name: "{{ states[person_entity].name }}"

condition:
  condition: template
  value_template: "{{ zone_entity == 'zone.home' and trigger.to_state.state == 'home' and trigger.from_state.state != 'home' or zone_entity == 'zone.home' and trigger.from_state.state == 'home' and trigger.to_state.state != 'home' or trigger.to_state.state == zone_state and trigger.from_state.state != zone_state or trigger.from_state.state == zone_state and trigger.to_state.state != zone_state}}"

action:
  ## Change this to your configured XMPP service -> https://www.home-assistant.io/integrations/xmpp/
  - service: notify.xmpp_XXX
    data:
      message: |
        {% if trigger.event == 'enter' %} 
          '{{ states[trigger.entity_id].name}} has arrived at {{ trigger.zone.attributes.friendly_name }}'
        {% else %} 
          '{{ states[trigger.entity_id].name}} has left {{ trigger.zone.attributes.friendly_name }}'
        {% endif %}