Ok so my problem:
I have 3 people I want to track as they enter/leave specific (currently 38) zones I have setup on the map. This let to there being 2x38x3 - 228 - automations. I wasn’t happy with this as it’s a lot of automations to manage and a complete pain to deal with should I wish to expand the number of zones or people.
As each person enters/leaves a zone I wanted a notification on my mobile and/or an audio notification on alexa.
My solution:
I have created 3 blueprints that allow you to choose if a person will generate a text, audio or both types of notification. This allowed me to reduce from 228 automation to just 3 - 1 per person. I have however setup 1 of each type per person with 2 of them turned off so that I can easily switch between the 3 types of notification. I can now add as many more zones as I wish and dont have to make any changes to the automations
I’ve decided to share them here as they are the first ones I’ve created and would like any feedback on how they could be improved or for you all to use - I know as a novice at this how much of a pain it was to figure this out so it’ll hopefully help someone here too. I’ve added comments so you can follow what each part does.
Tweaks I would like to make:
I’d like the ability to have this as a single blueprint where you can choose multiple people/outputs but due to limitations each box isn’t optional in the triggers/actions section at the moment.
I’d like to have services selectable from a dropdown - currently for the audio notification you have to manually enter “notify.alexa_media_my_echo_dot” as text for “notify_device_1_1” (audio) or “notify_device_2_1” (dual)
My code:
Bluieprint 1: zone_change_app_notification.yaml
blueprint:
name: 1 Person Multi-Zone Change - App Notification
description: Send a notification to a device when a person enters a different zone.
domain: automation
input:
# Person/Device that will be tracked
person_entity:
name: Person
description: Person/Device that will be tracked.
selector:
entity:
domain: person
# Device that will be notified
notify_device_1:
name: Mobile Device to notify
description: Device needs to run the official Home Assistant app to receive notifications.
default: ""
selector:
device:
integration: mobile_app
# Configurable message title - can leave blank to use default
notification_title:
name: Notification title (Optional)
description: "The title of the notification. Default: Update from {{ person_name }}:"
default: "Update from {{ person_name }}:"
# Configurable message - can leave blank to use default
notification_message:
name: Notification message (Optional)
description: "The message of the notification. Default: Moved from {{ trigger.from_state.state }} to {{ trigger.to_state.state }}"
default: "Moved from {{ trigger.from_state.state }} to {{ trigger.to_state.state }}"
trigger:
platform: state
entity_id: !input person_entity
variables:
# This is the state of the person when it's in this zone
person_entity: !input person_entity
person_name: "{{ states[person_entity].name }}"
# These are the messages that will be sent to the mobile app
notification_title: !input notification_title
notification_message: !input notification_message
condition:
# Check that the old and new states(zones) are different
condition: template
value_template: "{{ trigger.from_state.state != trigger.to_state.state }}"
action:
# Send the message to the mobile app with the chosen settings
- type: notify
domain: mobile_app
device_id: !input notify_device_1
title: "{{ notification_title }}"
message: "{{ notification_message }}"
** See below for the other 2 versions of the blueprint - as the “import blueprint” function will only import the first blueprint in a thread the other 2 versions will need to be imported manually, this can be done using visual studio code/samba or any other method you prefer **
Changelog
- 2021-01-09: Initial version