This blueprint adds on to the official example by having an option for sending a notification when entering and leaving the specified zone.
There is one bug, and that is you have to toggle both booleans, otherwise you’ll get an error when saving the automation. I already made an issue for that: Blueprint selector Boolean needs to be toggled when creating automation · Issue #100658 · home-assistant/core · GitHub
Get started
Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)
blueprint:
name: Zone Enter/Leave Notification
description: Send a notification to a device when a person enters or leaves a specific zone.
domain: automation
author: Sjorsa
input:
person_entity:
name: Person
selector:
entity:
filter:
- domain:
- person
multiple: false
zone_entity:
name: Zone
selector:
entity:
filter:
- domain:
- zone
multiple: false
notify_device:
name: Device to notify
selector:
device:
filter:
- integration: mobile_app
multiple: false
notify_when_entering:
name: Notify when entering zone
description: Toggle this even if you want it off, otherwise you'll get an error when saving the automation. If both options are off, no notifications will be sent. You can also turn both on of course.
selector:
boolean:
notify_when_leaving:
name: Notify when leaving zone
description: Toggle this even if you want it off, otherwise you'll get an error when saving the automation. If both options are off, no notifications will be sent. You can also turn both on of course.
selector:
boolean:
trigger:
platform: state
entity_id: !input person_entity
variables:
zone_entity: !input zone_entity
zone_state: '{{ states[zone_entity].name|lower }}' # Not really "state", but lowering the name works too.
zone_name: '{{ states[zone_entity].name }}'
person_entity: !input person_entity
person_name: '{{ states[person_entity].name }}'
notify_when_leaving: !input notify_when_leaving
notify_when_entering: !input notify_when_entering
condition: []
action:
- if:
- condition: template
value_template: '{{ notify_when_leaving == true and trigger.from_state.state == zone_state and trigger.to_state.state != zone_state }}'
then:
domain: mobile_app
type: notify
device_id: !input notify_device
message: '{{ person_name }} has left {{ zone_name }}'
- if:
- condition: template
value_template: '{{ notify_when_entering == true and trigger.from_state.state != zone_state and trigger.to_state.state == zone_state }}'
then:
domain: mobile_app
type: notify
device_id: !input notify_device
message: '{{ person_name }} has entered {{ zone_name }}'