How to dismiss notification after a period of time?

hello,

i have some automations, where notifications and persistant notifications where dismissed instantly, when a specific state of an sensor is happening.
But how could i delay the dismiss of an notification?
i would like to dismiss a notification, after a period of time (10 minutes), so notification message will be shown for at least 10 minutes, after the dismiss trigger event was fired?

i had tried by myself, but im fully overstrained. either i´m prevented by saving an automation due to errors, or trying by DeveloperTools/Template i got only errors.

here my automation, without any dismiss delay…

alias: Notify_Floodwarning_V01
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 1
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 15
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition: []
action:
  - service: notify.notify
    data:
      title: |
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
             FLOOD WARNING!! since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% else %}
          no flood!
        {% endif %}
      message: |
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
          {% if is_state("binary_sensor.aqara_ws_95_water_leak", "on") %}
             FLOOD WARNING!! since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
          {% else %}
            clear_notification
          {% endif %}
        {% else %}
          clear_notification
        {% endif %}
      data:
        ttl: 0
        priority: high
        tag: |
          {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
            flood_warning
          {% else %}
            flood_entwarnung
          {% endif %}
        color: pink
  - service: persistent_notification.create
    data:
      title: |-
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
             FLOOD WARNING!! since {{ ((now() -
             timedelta(minutes=(trigger.for.seconds // 60))).strftime('%H:%M')) }}h
        {% else %}
          no flood!
        {% endif %}
      message: |-
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
          {% if is_state("binary_sensor.aqara_ws_95_water_leak", "on") %}
             FLOOD WARNING!! 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_ws_95_water_leak" %}
          "pnotify_floodwarning"
        {% endif %}
  - service: persistent_notification.dismiss
    data:
      notification_id: |-
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
          {% if is_state("binary_sensor.aqara_ws_95_water_leak", "off") %}
            "pnotify_floodwarning"
          {% endif %}
        {% else %}
          not found
        {% endif %}
mode: parallel
max: 10

Can someone please help me?
thank you in advance
br
Frank

Persistant notifications are dismissed when you or something automated dismisses them. you need to set a notification _id (lower_case_chase formatted) and you need to use that to dismiss it via another script/automation. They can also be dismissed with a click.

Persistent Notification - Home Assistant.

Creating Unique Names for scene.create, persistant_notification, or Anything Else.

hi @Sir_Goodenough ,

thank you for your answer, but i guess i´m still using notification _id to dismiss pnotify_floodwarning, what works perfectly. but i want to delay the dismiss related to the time the dismiss was triggered.

i think it must be something like this…
and (now() - timedelta(minutes=(trigger.for.seconds // 60))) = 10

      notification_id: |-
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
          "pnotify_floodwarning"
        {% endif %}
  - service: persistent_notification.dismiss
    data:
      notification_id: |-
        {% if trigger.entity_id == "binary_sensor.aqara_ws_95_water_leak" %}
          {% if is_state("binary_sensor.aqara_ws_95_water_leak", "off") 
             and (now() - timedelta(minutes=(trigger.for.seconds // 60))) = 10 %}
            "pnotify_floodwarning"
          {% endif %}
        {% else %}
          not found
        {% endif %}
...

… but i get an error by saving the automation… so something must be wrong?

or may i have the wrong approach?
and i should only change the trigger for: minutes…?

trigger:
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0

sorry, i try to test todays evening… (but it´s hard to test automations, when the sensor is not accessable…) will a set state for an entity in developperTool trigger an automation as well?

sorry, i had an though error.

solution to set trigger “for-time” to 10 minutes should solve my problem, because this trigger for “off” state is used in automation for my dismiss of notification only…

trigger:
  - platform: state
    entity_id:
      - binary_sensor.aqara_ws_95_water_leak
    from: "on"
    to: "off"
    for:
      hours: 0
      minutes: 10
      seconds: 0