Blueprint Request - Presence Notification

Hi All,

New HA user here and not sure if this is the right location to post in.

I have had a look through the blueprint exchange and tried a search but I cannot seem to find the blueprint I am looking for.

I am looking for a blueprint or example automation where you can add multiple device_tracker entities and have a push notification sent to a specific device when any of the device trackers enter or leave whatever zones are specified.

As I am only in first first 2 weeks of using HA I don’t feel I have the relevant knowledge to build or achieve this, would appreciate any help or guidance in building it myself or even if someone has something they are already using that does similar that the can share as an example, I would be happy to try and reverse engineer it and change\amend it to my needs!

Not a proper blueprint, but here is the automation I use:

- alias: Zone Change Notification
  id: "15"
  description: Sends out a notification when someone changes zones.
  trigger:
    - platform: state
      entity_id:
        - person.one
        - person.two
  variables:
    fromState: >
      {{ trigger.from_state.state }}
    toState: >
      {{ trigger.to_state.state }}
    personName: >
      {{ state_attr(trigger.entity_id, 'friendly_name') }}
  condition:
    - condition: template
      value_template: >
        {{toState is not none and
          fromState is not none and
          toState != fromState}}
  action:
    - service: >
        notify.ALL_X_{{ personName.upper() }}
      data:
        message: >
          {{ personName }} has
          {% if fromState != 'not_home' %}left {{ fromState }}{% endif %}
          {% if fromState != 'not_home' and toState != 'not_home' %}and{% endif %}
          {% if toState != 'not_home' %}entered {{toState}}{% endif %}
        title: "{{personName}} Location Update"
  mode: single

This one is made for people, hence the person entities. Also, I have notify groups set up that are all the devices I want to notify except for the person who triggered the automation, which is how the notify service works.

2 Likes

Thanks will give it a go!

Hi @r-j-taylor

I only managed to get round to trying this automation today, I have managed to import it but not sure how the notification groups part should be set up, I had a read at the link you have specified above which sadly hasn’t really made it any clearer for me.

Can you give me an example of how it should look similar to what you have done with the automation please?

I’m not sure how to give you a better example than the docs. Can you show me what you tried and what difficulties you faced?

1 Like

Hi @r-j-taylor,

Apologies for the slow reply I was working away from home all week and did not have much time to catch up on the forum, I spent a while playing with the configuration Yaml before I posted above and every time I was trying to have 2 notification types within the group I was getting error messages when checking the configuration so removed the code that was not working before I left for work.

I spent a bit more time again this morning and I think I may have cracked it but the code does not look how I think it should - here it is below:

notify:
  - name: Notification Group
    platform: group
    services:
    - service: persistent_notification
    data:
      target: persistent_notification
      notify:
  - name: Notification Group
    platform: group
    services:
    - service: mobile_app_z_fold_3
    data:
      target: mobile_app_z_fold_3

Previously I was trying to do it like this which was failing:

notify:
  - name: Notification Group
    platform: group
    services:
    - service: persistent_notification
    data:
      target: persistent_notification
      notify:
    - service: mobile_app_z_fold_3
    data:
      target: mobile_app_z_fold_3

I think my problem is really just inexperience with YAML as I don’t come from a development back ground and have been trying to build things mostly in the UI.

1 Like

I see.


There are a few problems.

First, white-space is very important to YAML, make sure you are maintaining the white-space for nested objects. However, your only mistake along these lines applies to data, which:

Second, the data variable is only necessary for specific notification integrations, and is not necessary for either of the ones you are trying to group.

Third, and you may have not actually done this when you tried, but the name is what defines how you will call this service you are creating, st should be unique. Also, any white-space will be converted into underscores (I assume), just something to be aware of.

Overall, just make sure you are reading the docs. I do stuff like this for a living and still double check the docs every time I try to do something. They are generally very explicit about everything you can and can’t do.

My notification groups.
- name: all_devices
  platform: group
  services:
    - service: mobile_app_person_1_phone
    - service: mobile_app_person_2_phone
    - service: mobile_app_chromebook

- name: ALL_X_PERSON_2
  platform: group
  services:
    - service: mobile_app_person_1_phone
    - service: mobile_app_chromebook

- name: ALL_X_PERSON_1
  platform: group
  services:
    - service: mobile_app_person_2_phone
    - service: mobile_app_chromebook

Notice that I don’t include any data. The docs stated it was optional and listed a couple use-cases, and I decided it didn’t apply to me and left it off.


I think this should answer all of your questions, but let me know if anything else comes up!

1 Like

Thanks for the advice, I am reading the docs but sometimes they don’t always make sense to me.

I am using VS Code as the editor which usually tells me when something is not working from the get go, with the notification groups I initially got the code looking right without flagging errors in VS Code but then had errors when checking the configuration but today I managed to resolve those after a second loo, I always makes sure to leave gaps between items (it makes it more readable)

Looks like this now:
image

Only thing outstanding is to test it works now but have not had a chance to pop out today so will do a little later.

It looks like you may want to look over the advice and examples from my last post and the docs again.

I’m not sure what your goal is with those groups, but you are creating two groups with the same name and a single service in each group, while including a target field, even though that isn’t a valid variable as specified in the docs.

Yes you are right, I ran a couple of quick tests now and can see it did not have the desired effect.

It now looks like this.

notify:
  - name: Notification Group
    platform: group
    services:
    - service: persistent_notification
    - service: mobile_app_z_fold_3
  - name: Parent Notification Group
    platform: group
    services:
    - service: mobile_app_lauras_iphone
    - service: mobile_app_z_fold_3

Your examples really helped me out here, thanks again for posting them.

1 Like