Track multiple people / zones - 228 automations reduced to 3!

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 :slight_smile:

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

My blueprints

5 Likes

Can’t seem to be able to import this.
Do you have a git ?

image

Sorry I dont at the moment.

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?

1 Like

You can only have a single blueprint per 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 :slight_smile: 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 2: zone_change_audio_notification.yaml

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 3: zone_change_dual_notification.yaml

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

Hello. It is possible to have notifications on the telegram bot.
Thanks

Sorry, I dont use telegram but you can ammend the action as required to suit your prefferred method of notification(s).

Ok. I’ll try in case I let you know

I have tried in every way but I am not able to change the sending on telegram. Can someone help me. Thanks

What a beautiful blueprint, really happy with it … Only I come across the following …

I have neatly created Zones, which are also triggered when I get there. However, the notification works better for android and iphone.

On Iphone see screenshot, and on android the name of the zone is neatly displayed … What could this be in? Because I have not mentioned work in HA

1 Like

Very good, but how to get a friendly name of zone?

I don’t think this blueprint can do that, or more accurately I’m not sure how to do that!!

The reason for this is that it’s looking for the state of a “person” to change rather than a zone.

Sorry

I think I found a solution, but I haven’t tested it yet
{{ states.zone[trigger.to_state.state].name }}

If that does the trick then please do let me know and I’ll update the templates to use that so that everyone gets a better experience.

{{ states.zone[trigger.to_state.state].name }} works for me.

@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 }}"

image