App Notification That Actually Opens the App When Clicked

Trying to understand the process of getting a notification that will open the HA app on my phone to the correct screen. (Reading here: Actionable Notifications | Home Assistant Companion Docs)

In my case I’m trying to get my door locks to all automatically lock at night, and then report to my phone if there’s a problem (ie Lock is jammed or didn’t lock due to door being open, etc). This is the default action for my “choose” tree. When it executes, I get the notification on my Android (Samsung S21 Plus) but clicking on the notification doesn’t cause it to go to the app. I’ve tried a handful of format changes and nothing has gotten it working. Any insight?

default:
  - service: notify.mobile_app_russ_phones21plus
    data:
      message: >-
        SECURITY ALERT<br> {% if is_state('binary_sensor.alarm_side_entry_door',
        'off') and is_state('lock.side_door_lock','locked') and
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','off')
        %} Side Door is Locked  {% elif
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','on')
        %} Side Door is JAMMED {% else %} Side Door is Unlocked {% endif %}
      title: SECURITY ALERT
      data:
        sticky: true
        action: URI
        title: "Open Security Tab"
        uri: "/lovelace/security"

I have also tried these

default:
  - service: notify.mobile_app_russ_phones21plus
    data:
      message: >-
        SECURITY ALERT<br> {% if is_state('binary_sensor.alarm_side_entry_door',
        'off') and is_state('lock.side_door_lock','locked') and
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','off')
        %} Side Door is Locked  {% elif
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','on')
        %} Side Door is JAMMED {% else %} Side Door is Unlocked {% endif %}
      title: SECURITY ALERT
      data:
        - actions: 
            sticky: true
            action: URI
            uri: "/lovelace/security"

this one doesn’t give me any errors when saving, but doesn’t actually send the message either.

default:
  - service: notify.mobile_app_russ_phones21plus
    data:
      message: >-
        SECURITY ALERT<br> {% if is_state('binary_sensor.alarm_side_entry_door',
        'off') and is_state('lock.side_door_lock','locked') and
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','off')
        %} Side Door is Locked  {% elif
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','on')
        %} Side Door is JAMMED {% else %} Side Door is Unlocked {% endif %}
      title: SECURITY ALERT
      - actions:
        sticky: true
        action: URI
        uri: /lovelace/security

This post helped me a lot to understand the new actionable notifications:

https://community.home-assistant.io/t/easier-notifications-in-ios-2021-5/306952

For android, here’s an example from my own automations:

        - service: notify.all_mobile
          data:
            title: "Security Alert"
            message: "The Garage Door has been open for <b>{{ (15 + ((repeat.index - 1) * 5)) }}</b> minutes."
            data: 
              image: "{{ states('sensor.snapshot_remote_garage') }}{{ notify_image }}"
              clickAction: "/lovelace/camera_garage"
              ttl: 0
              color: red
              priority: high
              tag: garage_door_open
              channel: Security Alert
              group: Security
              actions:
                - action: "URI"
                  title: "View Camera"
                  uri: "/lovelace/camera_garage"
                - action: "alert_close_garage_door"
                  title: "Close Door"

The URI action launches the HA Companion App on the specified tab (a streamed view of the camera).
Looking at your automations and the documentation you are missing some of the structure - I’m a bit rushed, but the below should work I think:

default:
  - service: notify.mobile_app_russ_phones21plus
    data:
      message: >-
        SECURITY ALERT<br> {% if is_state('binary_sensor.alarm_side_entry_door',
        'off') and is_state('lock.side_door_lock','locked') and
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','off')
        %} Side Door is Locked  {% elif
        is_state('binary_sensor.side_door_lock_access_control_lock_jammed','on')
        %} Side Door is JAMMED {% else %} Side Door is Unlocked {% endif %}
      title: SECURITY ALERT
      data:
        sticky: true
        actions:
          - action: "URI"
            title: "Open Security Tab"
            uri: "/lovelace/security"

Thank you - that does appear to work, albeit not quite how i had pictured.

If I expand the alert on my phone then I get a button i can click and it does open the tab in HA.

I was hoping to have the app open by just clicking on the alert message itself. Is this possible?
I’m looking through the link pedolsky posted as well, but I’m not getting that lightbulb moment.

Using a clickAction instead of action: "URI"should give that functionality. There’s one in the example I posted abovee

Legendary! Thank you!

That was the exact bit I was missing. But now I’m excited about the possibilities with the buttons and responses possible.
Now I can figure out how to add a “lock doors” button so if I can lock the doors when the wife forgets.

My example contains:

That “Close Door” button triggers an automation to close the garage door based on the action (as event_data), removes the “door open” notification identified by it’s unique tag and sends a follow up notification with camera image confirming closure:

- id: actiononalert_close_garage_door
  alias: "Action On Alert - Close Garage Door"
  mode: single
  trigger:
    - platform: event
      event_type: mobile_app_notification_action
      event_data: 
        action: alert_close_garage_door
  condition: []
  action:
    - variables:
        notify_image: "garage_motion_{{ now().strftime('%Y%m%d%H%M%S') }}.jpg"
    - service: cover.close_cover
      data:
        entity_id: cover.garage_door
    - service: camera.snapshot
      data:
        entity_id: camera.garage
        filename: "{{ states('sensor.snapshot_local_garage') }}{{ notify_image }}"
    - service: local_file.update_file_path
      data:
        entity_id: camera.garage_last_motion
        file_path: "{{ states('sensor.snapshot_local_garage') }}{{ notify_image }}"
    - service: input_datetime.set_datetime
      data:
        entity_id: input_datetime.last_garage_motion
        time: "{{ (as_timestamp(now()) | timestamp_custom('%H:%M:%S', true)) }}"
        date: "{{ (as_timestamp(now()) | timestamp_custom('%Y-%m-%d', true)) }}"
    - service: notify.all_mobile
      data:
        message: clear_notification
        data:
          tag: garage_door_open
    - service: notify.all_mobile
      data:
        title: "Garage Door Closing"
        message: "Closing garage door as requested at {{ (as_timestamp(now()) | timestamp_custom('%H:%M', true)) }}."
        data: 
          image: "{{ states('sensor.snapshot_remote_garage') }}{{ notify_image }}"
          clickAction: "/lovelace/camera_garage"
          tag: garage_door_closed
          group: Garage

1 Like