Notify service: can't dismiss notification using clear_notification

Hello,

I have an automation that sends a notification on my and my wife’s phones when a window is left opened for more than 15 minutes if the climate instance is not preset to OFF. Each window uses its own notification tag, so I can manage notifications independently for each window.

alias: Chauffage chambres - notifications
description: ''
trigger:
  - platform: state
    entity_id:
      - binary_sensor.fenetre_chambre_damis
      - binary_sensor.fenetre_chambre_dapolline
      - binary_sensor.fenetre_chambre_parentale
    from: 'off'
    to: 'on'
    for: '0:15:00'
  - platform: state
    entity_id:
      - binary_sensor.fenetre_chambre_damis
      - binary_sensor.fenetre_chambre_dapolline
      - binary_sensor.fenetre_chambre_parentale
    from: 'on'
    to: 'off'
    for: '0:01:00'
condition:
  - condition: and
    conditions:
      - condition: not
        conditions:
          - condition: state
            entity_id: climate.netatmo_couloir
            attribute: preset_mode
            state: 'off'
      - condition: time
        before: '17:00:00'
        after: '5:00:00'
action:
  - service: notify.notify
    data:
      title: >
        {% if trigger.entity_id == "binary_sensor.fenetre_chambre_damis" %}
          Fenêtre chambre d'amis
        {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_dapolline"
        %}
          Fenêtre d'Apolline
        {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_parentale"
        %}
          Fenêtre parentale
        {% else %}
          Pas compris
        {% endif %}
      message: >
        {% if trigger.entity_id == "binary_sensor.fenetre_chambre_damis" %}
          {% if is_state("binary_sensor.fenetre_chambre_damis", "on") %}
            Il est temps de fermer la fenêtre de la chambre d'amis pour ne pas chauffer les moineaux.
          {% else %}
            clear_notification
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_dapolline"
        %}
          {% if is_state("binary_sensor.fenetre_chambre_dapolline", "on") %}
            Il est temps de fermer la fenêtre de la chambre d'Apolline pour ne pas chauffer les moineaux.
          {% else %}
            clear_notification
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_parentale"
        %}
          {% if is_state("binary_sensor.fenetre_chambre_parentale", "on") %}
            Il est temps de fermer la fenêtre de la chambre parentale pour ne pas chauffer les moineaux.
          {% else %}
            clear_notification
          {% endif %}
        {% else %}
          Pas compris
        {% endif %}
      data:
        ttl: 0
        priority: high
        tag: >
          {% if trigger.entity_id == "binary_sensor.fenetre_chambre_damis" %}
            fenetre_amis
          {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_dapolline"
          %}
            fenetre_apolline
          {% elif trigger.entity_id == "binary_sensor.fenetre_chambre_parentale"
          %}
            fenetre_parentale
          {% endif %}
        color: yellow
mode: parallel
max: 10

The automation works really well when dealing with one window. The notification appears when the window is left open, and is dismissed when the window is closed
If I open two windows, I get one notification for each window, as expected. When I close one window, its notification is dismissed correctly, but when I close the second window, its notification is not dismissed anymore.

I tried to also use channels, but the issue persists.

What’s wrong with the second “clear_notification” message ?

Isn’t someone facing the same issue ?
Should I submit a bug ?

I have the same issue. I’m also trying to delete a notification for an open windows. No luck clearing the notification on iPhone.

Where you able to make it work?

I opened this issue on the Github issue tracker for Android mobile app. It was a bug in the app.

For iOS app, you may look in the dedicated documentation for the mobile app here :

And anyway, make sure to use exactly the same tag to be able to clear it.

Doesn’t work here either. iOS 15.3, HA 2021.12.10.

No new development on this?

It’s working perfectly fine on Android

for me clear_notification is only working if im in my home Wifi and local push is activated!

Is there any activity on this issue?
According to this thread, the issue seems to be considered as solved. However, for me clearing notifications does not work reliably at all (on four different android devices). The same goes, btw, for replacing existing modifications with a new one with the same tag.

hello,
i have this automation, and both, notification and persistant_notification work quit well on my android 12. both updating massages according tag or notification_id, both are dismissed correctly.

the only thing i wonder: i have an rasppi with hassio only available as an localhost in my local network.

So if im not in my local wifi, i will not be able to access homeassistant anymore (via browser url and via android app), what is correct!
But if i disconnect from my wifi and im triggering this automation, i will get an notification on my smartphone as well? how could this happen?

alias: Notify_Windows_OPEN_persistV2
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.aqara_dw_28_contact
      - binary_sensor.aqara_dw_29_contact
      - binary_sensor.aqara_dw_27_contact
      - binary_sensor.aqara_dw_26_contact
    from: "off"
    to: "on"
    for: "0:30:00"
  - platform: state
    entity_id:
      - binary_sensor.aqara_dw_28_contact
      - binary_sensor.aqara_dw_29_contact
      - binary_sensor.aqara_dw_27_contact
      - binary_sensor.aqara_dw_26_contact
    from: "on"
    to: "off"
    for: "0:01:00"
condition: []
action:
  - service: notify.notify
    data:
      title: |
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
             Window OPEN Bad since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
             Window OPEN Klo since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
             Window OPEN SchlafZi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
             Window OPEN Wozi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% else %}
          all Windows Closed
        {% endif %}
      message: |
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
          {% if is_state("binary_sensor.aqara_dw_28_contact", "on") %}
             Window OPEN Bad since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
         {% else %}
            clear_notification
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
          {% if is_state("binary_sensor.aqara_dw_29_contact", "on") %}
             Window OPEN Klo since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            clear_notification
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
          {% if is_state("binary_sensor.aqara_dw_27_contact", "on") %}
             Window OPEN SchlafZi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            clear_notification
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
          {% if is_state("binary_sensor.aqara_dw_26_contact", "on") %}
             Window OPEN Wozi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            clear_notification
          {% endif %}
        {% else %}
         nothing found
        {% endif %}
      data:
        ttl: 0
        priority: high
        tag: |
          {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
            window_bad
          {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
            window_klo
          {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
            window_schlafzi
          {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
            window_wozi
          {% endif %}
        color: yellow
  - service: persistent_notification.create
    data:
      title: |-
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
             Window OPEN Bad since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
             "Window OPEN Klo since" {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}"h"
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
             Window OPEN SchlafZi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
             Window OPEN Wozi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% else %}
          all Windows Closed
        {% endif %}
      message: |-
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
          {% if is_state("binary_sensor.aqara_dw_28_contact", "on") %}
             Window OPEN Bad since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
         {% else %}
            
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
          {% if is_state("binary_sensor.aqara_dw_29_contact", "on") %}
             Window OPEN Klo since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            
         {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
          {% if is_state("binary_sensor.aqara_dw_27_contact", "on") %}
             Window OPEN SchlafZi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
          {% if is_state("binary_sensor.aqara_dw_26_contact", "on") %}
             Window OPEN Wozi since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            
          {% endif %}
        {% else %}
          not found
        {% endif %}
      notification_id: |-
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
          "pnotify_window_bad"
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
          "pnotify_window_klo"
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
          "pnotify_window_schlafzi"
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
          "pnotify_window_wozi"
        {% endif %}
  - service: persistent_notification.dismiss
    data:
      notification_id: |-
        {% if trigger.entity_id == "binary_sensor.aqara_dw_28_contact" %}
          {% if is_state("binary_sensor.aqara_dw_28_contact", "off") %}
            "pnotify_window_bad"
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_29_contact" %}
          {% if is_state("binary_sensor.aqara_dw_29_contact", "off") %}
            "pnotify_window_klo"
         {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_27_contact" %}
          {% if is_state("binary_sensor.aqara_dw_27_contact", "off") %}
            "pnotify_window_schlafzi"
          {% endif %}
        {% elif trigger.entity_id == "binary_sensor.aqara_dw_26_contact" %}
          {% if is_state("binary_sensor.aqara_dw_26_contact", "off") %}
            "pnotify_window_wozi"
          {% endif %}
        {% else %}
          not found
        {% endif %}
mode: parallel
max: 10