Notify all persons that are currently at home

Sometimes you want to send a notification only to the persons that are currently at home. This blueprint allows you to do that quite easily.

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

This blueprint creates a script which can be used like most notify services. When you call the script, it checks if the person is at home; if so, the notification is sent.

Configuration

In order to create the script, you need to supply a mapping of person names with their corresponding notify services. Say you’ve got two persons, Lisa and John, resulting in two person entities: person.lisa and person.john. For Lisa, you want to send a notification to notify.lisa, and for John, you want to send a notification to notify.mobile_app_john. The mapping will then look like this:

lisa: notify.lisa
john: notify.mobile_app_john

Usage

The blueprint will create a script, e.g. script.notify_everybody_at_home, which you can supply with a number of parameters. These are documented in the script and shown in the service developer tools.

Open your Home Assistant instance and show your service developer tools with a specific service selected.

The following parameters can be specified:

  • message: Notification text.
  • title: Notification title.
  • data: Notification data, depends on the platform used to send the notification.
  • persons: List of persons you want to notify, useful if you want to send the notification only to a specific set of people. If not specified, all persons configured in the blueprint are notified.

The message, title and data parameters are passed directly to the configured notify services.

Limitations

The script calls all the notification services with the same data object (if supplied). It may therefore not work if you are using different notification platforms, e.g. the Android app and Pushbullet. In some cases, you can solve this kind of problems by creating a notify group.

More info on my GitHub: GitHub - crnh/home-assistant-blueprints: Home Assistant Blueprints.

blueprint:
  domain: script
  name: Notify everybody at home
  source_url: https://github.com/crnh/home-assistant-blueprints/blob/7e6aa06193165bb5c01fec197849347c1a1193a2/notify_everybody_at_home.yaml
  input:
    person_service_map:
      name: Person notify services
      description: >
        Mappings between person names and their corresponding notify services.
        The default value shows what the object should look like if the service 
        `notify.mobile_app_john` belongs to `person.john`.
      selector:
        object:
      default:
        john: notify.mobile_app_john

mode: parallel

fields:
  persons:
    name: Persons
    description: >
      List with persons who should get a notification. If not supplied, all
      persons will be used.
    required: false
    selector:
      object:
  title:
    name: Title
    description: Title of the notification
    required: false
    selector:
      text:
  message:
    name: Message
    description: Message to send
    required: true
    selector:
      text:
        multiline: true
  data:
    name: Data
    description: Notification data object
    required: false
    selector:
      object:
sequence:
  - variables:
      person_service_map: !input person_service_map
      persons: >
        {% set all_persons = person_service_map.keys() | list %}
        {{ persons | default(all_persons, true) }}
  - repeat:
      count: "{{ persons | count }}"
      sequence:
        - choose:
            conditions:
              - "{{ is_state('person.' ~ persons[repeat.index - 1], 'home') }}"
            sequence:
              - service: "{{ person_service_map[persons[repeat.index - 1]] }}"
                data:
                  title: "{{ title | default }}"
                  message: "{{ message | default }}"
                  data: "{{ data | default({}) }}"
6 Likes

This is super useful! Thank you!.

2 Likes

Just what I was looking for, nice easy setup. Thanks.

1 Like