šŸ”” Actionable notifications for Android

This Blueprint helps you send actionable notifications to your Android device.

Requirements

  • Home Assistant app on your device
  • An input_boolean which will trigger the automation

Notes

The input_boolean can be created on the UI, navigate to Configuration->Helpers click Add helper and select Toggle. You can use the input_boolean.turn_on service to trigger this automation. The automation will turn off the boolean after it is triggered.

You can add up to 3 actions, but all 3 are optional.
For each action, you can do something the same way as for an Automation or open a URL, an application on the device or load a Lovelace view/dashboard.

  • If you plan to use a Lovelace view the format would be /lovelace/test where test is replaced by your defined path in the defined view.
  • If you plan to use a Lovelace dashboard the format would be /lovelace-dashboard/view where /lovelace-dashboard/ is replaced by your defined dashboard URL and view is replaced by the defined path within that dashboard.
  • To pick the application to open, prefix app:// to the the package name. How to find package name?

If the device does not have the application installed then the Home Assistant application will open to the default page.
If you define an action and an URI for a button, URI will take precedence over action.

Blueprint

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

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

Or you can import this Blueprint by using the forum topic URL:

blueprint:
  name: Send actionable notifications for Android
  description: |
    Send actionable notifications to an Android device
    For each action, you can open an URL, an application on the device or load a lovelace view/dashboard.
    If you plan to use a lovelace view the format would be /lovelace/test where test is replaced by your defined path in the defined view.
    If you plan to use a lovelace dashboard the format would be /lovelace-dashboard/view where /lovelace-dashboard/ is replaced by your defined dashboard URL
    and view is replaced by the defined path within that dashboard.
    To pick the application to open, prefix app:// to the the package name.
    If the device does not have the application installed then the Home Assistant application will open to the default page.
    If you define an action and an URI for a button, URI will take precedence over action.
  domain: automation
  input:
    notify_device:
      name: Device to notify
      description: Device needs to run the official Home Assistant app to receive notifications
      selector:
        device:
          integration: mobile_app

    trigger_entity:
      name: Trigger entity
      description: Send the notification when this boolean turns on
      selector:
        entity:
          domain: input_boolean

    notification_title:
      name: Notification title (Optional)
      description: The title of the notification
      default: ""

    notification_message:
      name: Notification message (Optional)
      description: The message of the notification
      default: ""
    
    persistent_notification:
      name: Create persistent notification?
      description: Persistent notifications cannot be dimissed by swiping away
      default: false
      selector:
        boolean:

# Action 1

    action_1_title:
      name: First action name
      description: Name of the first button
      default: ""
      
    action_1_uri:
      name: URI for action 1 (Optional)
      description: Optional URI for the first action
      default: ""

    first_action:
      name: Action 1
      description: "Action to run when the first action is clicked"
      default: []
      selector:
        action:

# Action 2

    action_2_title:
      name: Second action name
      description: Name of the second button
      default: ""

    action_2_uri:
      name: URI for action 1 (Optional)
      description: Optional URI for the second action
      default: ""

    second_action:
      name: Action 2
      description: Action to run when the second action is clicked"
      default: []
      selector:
        action:

# Action 3
    
    action_3_title:
      name: Third action name
      description: Name of the third button
      default: ""
      
    action_3_uri:
      name: URI for action 3 (Optional)
      description: Optional URI for the third action
      default: ""

    third_action:
      name: Action 3
      description: "Action to run when the third action is clicked"
      default: []
      selector:
        action:

mode: restart
max_exceeded: silent

variables:
  notify_device: !input notify_device
  trigger_entity: !input trigger_entity
  notification_title: !input notification_title
  notification_message: !input notification_message
  persistent_notification: !input persistent_notification
  action_1_title: !input action_1_title
  action_1_uri: !input action_1_uri
  first_action: !input first_action
  action_2_title: !input action_2_title
  action_2_uri: !input action_2_uri
  second_action: !input second_action
  action_3_title: !input action_3_title
  action_3_uri: !input action_3_uri
  third_action: !input third_action

trigger:
  platform: state
  entity_id: !input trigger_entity
  from: "off"
  to: "on"

action:
  # Reset trigger entity
  - service: input_boolean.turn_off
    entity_id: !input trigger_entity

  # Send actionable notification
  - domain: mobile_app
    type: notify
    device_id: !input notify_device
    title: "{{ notification_title }}"
    message: "{{ notification_message }}"
    data:
      tag: "{{ notification_title }}"
      persistent: "{{ persistent_notification }}"
      actions: >
        {% set titles = [action_1_title, action_2_title, action_3_title] %}
        {% set uris = [action_1_uri, action_2_uri, action_3_uri] %}
        {% set actions = namespace(data = []) %}

        {% for title in titles %}
          {% if title|length %}
            {% set uri = uris[loop.index - 1] %}
            {% set action_name = "action" + loop.index|string %}
            {% set action = {
              "action": "URI" if uri|length else action_name,
              "title": title,
              "uri": uri 
              }
            %}
            {% set actions.data = actions.data + [action] %}
          {% endif %}
        {% endfor %}
        {{ actions.data }}

  # Wait for the user to select an action
  - wait_for_trigger:
      platform: event
      event_type: mobile_app_notification_action

  # Do the action that the user selected
  - choose:
    - conditions: "{{ wait.trigger.event.data.action == 'action1' }}"
      sequence: !input first_action
    - conditions: "{{ wait.trigger.event.data.action == 'action2' }}"
      sequence: !input second_action
    - conditions: "{{ wait.trigger.event.data.action == 'action3' }}"
      sequence: !input third_action
72 Likes

you seem to have the trigger hard-coded to
entity_id: binary_sensor.basement_floor_wet

2 Likes

Thank you, Iā€™ve accidentally shared an earlier version. Edited the original post.

1 Like

Very fancy, I didnā€™t know Home Assistant could give rich notifications like that! Very cool!

2 Likes

Love this, itā€™s a perfect idea for a blueprint.

Any chance this could be modified to allow sending a notification to all devices rather than just one? For example, an automation can call notify.<device_id> to notify a single device, or it can call notify.notify to notify all devices. My wife and I both run the app so we can get notifications, and that addition would let me use this blueprint all the time! Without it, Iā€™d have to double the number of automations I have. Thanks for the consideration, love the blueprint.

3 Likes

Try making a notify group!

https://companion.home-assistant.io/docs/notifications/notifications-basic/#sending-notifications-to-multiple-devices

2 Likes

Nice blueprint! Made one for my front door being opened. Swapped input_boolean out for binary_sensor however as it made more sense for my setup

2 Likes

Great blueprint! Possible to make one for ios?

2 Likes

I was thinking the same thing for binary_sensor. I think I could replace several automations and node-red flows using this blueprint.

1 Like

Something similar possible for iOS? Would be great

1 Like

Thanks for the pointer, I didnā€™t know about notify groups. Unfortunately, the blueprintā€™s device selector dropdown doesnā€™t pick up groups (apparently), just mobile apps (which makes sense, given it has a selector of mobile_app).

2 Likes

Thats the motive i get mad when i look back at Webc0re, it was so easy there to select multiple devices, lights, why is it so hard do HA devs to make a option to select a device list from UI?!

1 Like

What if the user just dismiss the notification? Does the automation will wait forever?

Is it possible to set the notification as ā€œpriority: highā€ for me, the notification comes with a long delay

1 Like

Hi, just gave it a try

Seems to work very nicely, although is it possible to add actions when someone presses the notification itself when using persistent notification.

Thanks for this!

Great blueprint.
I have a couple of question but I will start with one.
In your example you show ā€œClose Garageā€, "Go to HA, and ā€œOpen Tesla Appā€.
I understand how you can call a lovelace view or dashboard and how to call an app. But not sure if about the ā€œClose Garageā€, is this simply calling a view were you can toggle the door or does this close the door if you choose that option. If it closes the garage door, can you explain how to do that?

Yes it will wait forever, or until itā€™s triggered again. You can enable persistent notifications, so it cannot be dismissed.

It does a service call, or whatever you set it in the Action. So itā€™s the same as the action part of an Automation.

According to the documentation, iOS requires configuration in Home Assistant in advance, so itā€™s more complicated and I donā€™t have a device to test it.

2 Likes

Iā€™m afraid this is not possible

1 Like