Possible to wrap the persistent notifier to allow clearing?

Hi everyone:

I’m trying to set up an Alert in Home Assistant for unavailable entities and I’ve run into a snag with clearing notifications.

I want the alert to work on both my iPhone and the web UI (Persistent Notifications). To get the iPhone to dismiss the notification when the alert is fixed, I’m using “done_message: clear_notification”. The problem is that while the phone clears it perfectly, the web UI just creates a brand new notification that literally says “clear_notification” instead of dismissing the old one.

I tried to fix this by creating a “Notify Group” that points to a script. The script is supposed to look at the message, and if it says “clear_notification”, it calls the dismiss service using a notification_id. Otherwise, it creates the notification. Code below:

alias: Persistent Notifier with Clearing
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ message == 'clear_notification' }}"
        sequence:
          - data:
              notification_id: >-
                {{ data.notification_id if data is defined and
                data.notification_id is defined else 'generic_alert' }}
            action: persistent_notification.dismiss
      - conditions:
          - condition: template
            value_template: "{{ message != 'clear_notification' }}"
        sequence:
          - action: persistent_notification.create
            data:
              title: "{{ title }}"
              message: "{{ message }}"
              notification_id: >-
                {{ data.notification_id if data is defined and
                data.notification_id is defined else 'generic_alert' }}

However, I can’t seem to find a way to add it as a notifier ready to be used by Alert integration.

Has anyone found a clean, generic way to make Persistent Notifications honor the clear command like the mobile app does? I want a solution where I can pass a notification_id through the alert data so I don’t have to write a separate script for every single alert I have.

Any ideas on a better way to do this or how to fix the notify group error? Appreciate your help!

Can you share the Notify Group config? And the Alert config as well. So we can see all the pieces of the puzzle.

Hi @Didgeridrew :

I’m actually looking at your post here In Alert call script via notify - #13 by Sargon
And I think it will solve my issue - what I esentially need is to call script/automation to send/clear notificaction.