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 **
I use the Visual Studio Code addon and then create a new file and paste code in that way when I come across the issue of importing.
EDIT: I missed the yaml tags in the code bit - have added then but am now getting another error. I know the code itself is good and working - just need to figure out how this part works!! I’m wondering if it’s because I have 3 in the same post?
That being said, it seems like you only need one blueprint, the third one does everything the other two do. It just needs to conditionally notify based on what inputs have been filled in. So something like this:
blueprint:
name: 1 Person Multi-Zone Change - Dual 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.
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 }}"
# Service to call for device that will be notified - have to type manually as can't select from a dropdown yet
notify_device_2_1:
name: Media Player Notification Service
description: "Notifier service for Media Player to receive audio/tts notifications. Example: notify.alexa_media_living_room_echo_dot"
# Media device that will be notified
notify_device_2_2:
name: Media Player to notify
description: Media Player to receive audio/tts notifications.
selector:
entity:
domain: media_player
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
# These are the notifiers
notify_device_1: !input notify_device_1
notify_device_2_1: !input notify_device_2_1
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
- choose:
conditions: "{{ notify_device_1 != "" }}"
sequence:
- type: notify
domain: mobile_app
device_id: !input notify_device_1
title: "{{ notification_title }}"
message: "{{ notification_message }}"
# Send the message to the media device with the chosen settings using tts
- choose:
conditions: "{{ notify_device_2_1 != "" }}"
sequence:
- service: !input notify_device_2_1
data:
data:
type: tts
message: "{{ person_name }} has entered {{ trigger.to_state.state }}"
target: !input notify_device_2_2
Ah - thanks for the confirmation - I thought that may be the cause. I had planned to come back today to split them out to seperate posts as a test.
I have the 3 blueprints as I decided at last minute I wanted app notifications whilst out of the house and both whilst at home, that way when I’m away alexa isn’t yapping away for no reason. I use a presence detection automation to handle this that switches them over(as well as some for bedtime tv activation etc. so that they dont fire if i’m away). It gives others flexability.
I’ll go test out the modifications to the third blueprint though as that’s what I was missing - The choose and condition However I fear that this then means the defaults fir inout will need to be “” (blank) so that the automation will create IF only 1 of the inputs is wanted?
Yes that’s true. Or alternatively you can make new boolean inputs that are like “send device notification?” and “send TTS notification?” That way you don’t have to rely on the notifier being blank in your condition and can just ask the user directly which type of notification they want.
Yeah, unfortunately it looks like it creates an automation but then the automation isn’t listed/isn’t functional. Even with defauults set to “” - I’m sure I tried something like this yesterday - but there’s sadly no way (that I know of) to mark an input as “optional” so that the blueprint will ignore it when creating the actual automation unfortunately, at least for now!
blueprint:
name: 1 Person Multi-Zone Change - Audio 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
# Service to call for device that will be notified - have to type manually as can't select from a dropdown yet
notify_device_1_1:
name: Media Player Notification Service
description: "Notifier service for Media Player to receive audio/tts notifications. Example: notify.alexa_media_living_room_echo_dot"
# Media device that will be notified
notify_device_1_2:
name: Media Player to notify
description: Media Player to receive audio/tts notifications.
selector:
entity:
domain: media_player
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 }}"
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 media device with the chosen settings using tts
- service: !input notify_device_1_1
data:
data:
type: tts
message: "{{ person_name }} has entered {{ trigger.to_state.state }}"
target: !input notify_device_1_2
blueprint:
name: 1 Person Multi-Zone Change - Dual 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.
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 }}"
# Service to call for device that will be notified - have to type manually as can't select from a dropdown yet
notify_device_2_1:
name: Media Player Notification Service
description: "Notifier service for Media Player to receive audio/tts notifications. Example: notify.alexa_media_living_room_echo_dot"
# Media device that will be notified
notify_device_2_2:
name: Media Player to notify
description: Media Player to receive audio/tts notifications.
selector:
entity:
domain: media_player
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 }}"
# Send the message to the media device with the chosen settings using tts
- service: !input notify_device_2_1
data:
data:
type: tts
message: "{{ person_name }} has entered {{ trigger.to_state.state }}"
target: !input notify_device_2_2
@Molot
Below is a quick and dirty way to notify via telegram.
blueprint:
name: Telegram Notification All Zones
description: Telegram Notification All Zones
domain: automation
input:
# Person/Device that will be tracked
person_entity:
name: Person
description: Person/Device that will be tracked ? .
selector:
entity:
domain: person
# Service to call for device that will be notified - have to type manually as can't select from a dropdown yet
notify_device_1_1:
name: Media Player Notification Service
description: "HOW TO NOTIFY"
# Media device that will be notified
notify_device_1_2:
name: Media Device To Notify
description: Telegram Bot to receive audio/tts notifications.
selector:
entity:
domain: media_player
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 }}"
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 notification device with the chosen settings using notify
- service: notify.notifier_telegram
data:
message: "{{ person_name }} has entered {{ trigger.to_state.state }}"