Notify person

How do you determine the right value for target? For example they list “macbook” in their example but if I want to notify a specific device like my iPhone is it just “mobile_app_xxxxs_iphone” (from “notify.mobile_app_xxxxs_iphone”) or something different?

I had the exact same idea…
then on the person menu we could choose which device that person will use to receive notifications.

1 Like

I was looking for something similar, i wanted to notify only the users that are in my group list that are home.
for example when the dishwasher, washingmachine etc is done with it’s program.

So i created this little python script.
It’s my first python script for home assistant and might need some error checking fine tuning but for now it works for me.

image

notify_home.py

new_group = data.get("group_persons", "")
new_topic = data.get("topic","")
new_message = data.get("message","")

entity = hass.states.get(new_group)
for entity_id in hass.states.get(new_group).attributes['entity_id']:
    state = hass.states.get(entity_id)
    if state.state == 'home':
        #Get source attribute
        source = hass.states.get(entity_id).attributes['source']
        #Replace text in string attributes
        newsource = source.replace('device_tracker.', 'mobile_app_')
        logger.info(newsource)
        #Send message to all mobile app users
        hass.services.call('notify', newsource, {
        "title": new_topic,
        "message": new_message})  
2 Likes

Would indeed be cool if the devices of one person are automatically added to some (meta) group. This might require that notifiers (like html5 push notify) have a person assigned to them.

I think this is not possible at the moment, right?

1 Like

A conceptual way to do this, like the initial “group” answer is publisher/subscriber/topic.

IE, you have an MQTT topic: /home/broadcast/notifications

You add that as the service you call.

Person 1 enters home
Subscribe all devices to MQTT topic /home/broadcast/notifications

On new message to topic, push notify.

Person 1 leaves home
Unsubscribe.

Its a bit tricky to automatically say “all people, add all devices on entering home” and not have it be annoying. Needs a concept of preferred notification means.

I just came up with the same idea of this FR because I face the issue with someone changing of device.
+1

+1
This sounds like a quite logical next step for improving the person integration!
@houtknots I think, you could tag the person integration in your feature request as well :slight_smile:

4 Likes

Hi, @frenck I really don’t want to interrupt you with anything you do, but can you take a look at this feature request. We all think this will be a great feature.

+1
I have changed my mobile phone recently and I was surprised that most of my automation simply handled over easily as I had them assigned to people instead of individual device trackers, so reassigning the device to a person simply solved most of it. I mean most as this notify system doesn’t support “person”.

1 Like

+1 here too. This would be a great and natural feature. Today, there does not seem to be a reliable and local way (a tenet of HA) to notify an individual user that will not eventually need maintenance due to device changes, etc.

1 Like

With the new helpers there is no longer the need to restart.

@metrbil, how did you do this?

I think you mean how to create a helper group? That’s easy, I think. Go to Settings > Helpers, create a new group and add one or more notifiers. Then reload the groups from the developer tools.

Dont really see a way to do that… As far as I’ve tested none of the helper group types work with notifiers. Did you get it to work?

Sorry for the confusion.

Notify groups (groups of device notifiers) should be created like this:

notify:
  # List all notifiers for a person
  # Creates a notifier 'notify.person_1'
  - name: Person 1
    platform: group
    services:
      - service: mobile_app_person_1  # refers to 'notify.mobile_app_person_1'
      - service: pushover  # refers to 'notify.pushover'
1 Like

If you just rename your device to the old device’s name your automations will just work like they did before. Example: my device is named “Samsung van Jaap” under person you choose “device to track: Samsung van Jaap” in automations you choose notify mobile app Samsung van Jaap. Next time you get a new device just remove the old one and add the new one with the same name.

This feature request thread brought this 5 year HA lurker out of the shadows to create an account.

Please don’t forget about this one guys. Targeting people and all their associated devices for notifications would be huge for increasing user engagement.

Here’s a workaround until this becomes a supported feature. In short, using customize.yaml you can associate notify services with each person entity. Then you can reference those in automations or scripts.

Step 1: Edit your customize.yaml file (see here for details) and list each person and their associated notification services that you’d like to use. For example:

person.john_doe:
  notify_services:
    - 'notify.mobile_app_johns_iphone'
    - 'notify.custom_notify_service_for_john'
person.jane_doe:
  notify_services:
    - 'notify.mobile_app_janes_android'

Then restart so it takes effect. (There are ways to reload this file without restarting and those methods are discussed in the docs; I won’t cover them here.)

Step 2: Utilize those new attributes in your automations & scripts. Here is an example script that will call every notify service attached to every person who is currently home:

alias: Alert everyone who is home
continue_on_error: true
sequence:
  - variables:
      notify_services: >
        {{ state_attr('zone.home','persons') | map('state_attr','notify_services') | sum(start=[]) | list }}
  - repeat:
      for_each: "{{ notify_services }}"
      sequence:
        - service: "{{ repeat.item }}"
          data:
            message: You are home!
mode: single

I specify continue on error in case a notify service is removed or renamed; this way all the other notifications are still sent. You will still see errors in your logs if that happens though.

Edit: here’s a simpler option if you are OK with restricting yourself to only one notify service per person.

Example of customize:

person.john_doe:
  notify_service: notify.mobile_app_johns_iphone
person.jane_doe:
  notify_service: notify.mobile_app_janes_android

Example of how to notify everyone who is home:

alias: Alert everyone who is home
continue_on_error: true
sequence:
  - variables:
      notify_services: >
        {{ state_attr('zone.home','persons') | map('state_attr','notify_service') | list }}
  - repeat:
      for_each: "{{ notify_services }}"
      sequence:
        - service: "{{ repeat.item }}"
          data:
            message: You are home!
mode: single

And where it becomes easier is if you only want to notify a single person. Instead of

service: notify.mobile_app_johns_iphone
data:
  message: "Hello John!"

You can use this instead:

service: "{{ state_attr('person.john_doe', 'notify_service') }}"
data:
  message: "Hello John!"

The benefit is that you never have to maintain your automations or scripts if you decide that you want to be notified by a different method. Or if you change your phone and your notification method changes. It’s a single change to the customize YAML.

1 Like

BUMP!

This is so important! In my case I have a guest user account that I give to visitors. (obviusly I change the PW inbetween visitors). This means that the devices accosiated with the user account changes frequently and sometimes this account is logged in on multiple devices. It needs to be possible to broadcast notifications to all devices where a certain account is logged in without having to manually add devices!

1 Like

For those still searching for a solution:
I made this script for myself, it takes a message and a list of people and sends notifications to their devices. If no people are specified it defaults to everyone.
It works perfectly for me, but I did not test it with multiple devices for the same person, so I don’t know what it’ll do in that case.

alias: Notifier script
description: Send notifications to the devices of the specified people.
fields:
  title:
    selector:
      text: null
    description: The title of the notification
    default: Notification
    required: true
  message:
    selector:
      text: null
    description: The message to send
    example: Generic notification. Something happened.
    required: true
  people:
    selector:
      text:
        multiple: true
    description: The list of people to notify
sequence:
  - variables:
      everyone: >-
        {{ states.person | map(attribute='entity_id') | map('replace',
        'person.', '') | list }}
      recipients: "{{ people if people | length > 0 else everyone }}"
  - repeat:
      for_each: "{{ recipients }}"
      sequence:
        - if:
            - condition: template
              value_template: "{{ repeat.item in everyone }}"
          then:
            - variables:
                person_entity: person.{{ repeat.item | lower }}
                device_name: >
                  {% set source = state_attr(person_entity,'source') %} {{
                  source.split('device_tracker.')[-1] if source != None else
                  None }}
            - if:
                - condition: template
                  value_template: "{{ device_name != None }}"
              then:
                - data:
                    title: "{{ title }}"
                    message: "{{ messaggio | default('Generic notification. Something happened.')  }}"
                  action: notify.mobile_app_{{ device_name }}
              else:
                - action: system_log.write
                  data:
                    level: warning
                    message: >-
                      The person "{{ repeat.item }}" has no linked devices, unable to notify.
                    logger: notifier_script
          else:
            - action: system_log.write
              data:
                level: warning
                message: >-
                  The person "{{ repeat.item }}" doesn't exist, unable to notify.
                logger: notifier_script