How to push any Persistent Notifications to HA app?

Sometimes I have Persistent Notifications in the HA frontend (like any 3rd party integration requiring some action due to a breaking change or whatever). Or imagine a user login failure, which usually also results in a persistent notification in the frontend only.

Is it possible to push any notifications also to the app? (because I hardly ever look into the frontend in my browser).

I do this with the bad login notification. The same principles can be used for other notifications.

But how can I trigger on any persistent_notification? I would not want to list all of them as a trigger one after the other…

1 Like

Could solve it as follows (though don’t know it it’s the correct way. But it works):

trigger:

event_data:
  domain: persistent_notification
  service: create
event_type: call_service
platform: event

action:

data_template:
  message: '{{trigger.event.data.service_data.message}}'
  title: 'Persistent: {{trigger.event.data.service_data.title}}'
service: notify.mobile_app
10 Likes

Thanks for this, works well.

Whoever is using this, here is the update:

domain: persistent_notification
domain: notify
service: create
service: persistent_notification

1 Like

Thanks! Took me a little bit to figure out the indentation as I’m not that fluent in YAML. For anyone else that wants this. Create a new automation, go into YAML mode, remove everything and paste this in, change the service to your device and save.

alias: Notification Push Persistant Notifications
description: ""
trigger:
  - event_data:
      domain: notify
      service: persistent_notification
    event_type: call_service
    platform: event
condition: []
action:
  - service: notify.mobile_app   # Change this to your device
    data_template:
      message: "{{trigger.event.data.service_data.message}}"
      title: "P: {{trigger.event.data.service_data.title}}"
mode: single

3 Likes

Hi.
Tried this, changing only the device name but got this error:

“Error rendering data template: UndefinedError: ‘trigger’ is undefined”

What I am doing wrong?
Thanks in advance.

Yeah, they changed the persistant notification trigger a while back I think.
Just revisited this and am now able to make it work with the correct data, so thank you for the reminder!

alias: Persistent Notification to phone
description: ""
triggers:
  - trigger: persistent_notification
    update_type:
      - added  # You can add removed, current and/or updated here as well
conditions: []
actions:
  - action: notify.mobile_app_xxx  # Mobile device here
    data_template:
      # This allows you to see the full trigger dict
      # Trigger the automation once and then go to traces and see the data
      message: "{{ trigger }}"   
      title: "P: Notification"
mode: single

For me the data looks something like this:

So I can make the data like this:

    data_template:
      message: "{{ trigger.notification.message }}"
      title: "P: {{ trigger.notification.title }}"
2 Likes

Thanks, it worked perfectly!!

1 Like