Restoring persistent notifications on restart

Replace the original condition.

That indicates that only notifications created with notification_id that matches the first 5 characters (myha_) are saved and restored.

      - service: persistent_notification.create
        data:
          title: "Bresser 3CH"
          message: "Sensor Timeout"
          notification_id: "myha_bresser_notify"

All right I think I understandā€¦ but it isnā€™t working. The notifications do publish to the mqtt broker but when I restart home assistant they do not restore. In my logs I am seeing the following error:

Error during template condition: UndefinedError: 'dict object' has no attribute 'event'

when I run the template thru the template editor I get this:

Error rendering template: UndefinedError: 'trigger' is undefined

When I restart I get the following message with no content on my mqtt broker:

Message 19 received on home-assistant/notifications/config_entry_discovery at 8:36 PM: QoS: 0 - Retain: false

This is my full config:


automation:
  - id: save_notification_create
    alias: Save Notifications on Create
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: call_service
        event_data:
          domain: persistent_notification
          service: create
    condition:
      - condition: template
        value_template: >
          {{ trigger.event.data.service_data.notification_id[:5] == "kyle_" }}          
    action:
      - service: mqtt.publish
        data_template:
          topic: "home-assistant/notifications/{{ trigger.event.data.service_data.notification_id }}"
          payload: >-
            {
              "notification_id" : "{{ trigger.event.data.service_data.notification_id }}",
              "title" : "{{ trigger.event.data.service_data.title }}",
              "message" : "{{ trigger.event.data.service_data.message }}"
            }
          retain: true
  
  - id: save_notification_dismiss
    alias: Removed Saved Notifications on Dismiss
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: call_service
        event_data:
          domain: persistent_notification
          service: dismiss
    action:
      - service: mqtt.publish
        data_template:
          topic: "home-assistant/notifications/{{ trigger.event.data.service_data.notification_id }}"
          retain: true
  
  - id: restore_notifications
    alias: Restore Notifications
    initial_state: 'on'
    trigger:
      - platform: mqtt
        topic: home-assistant/notifications/+
    condition:
      - condition: template
        value_template: >
          {{ trigger.event.data.service_data.notification_id[:5] == "kyle_" }}          
    action:
      - service: persistent_notification.create
        data_template:
          title: >-
            {{ trigger.payload_json.title }}
          message: >-
            {{ trigger.payload_json.message }}
          notification_id: >-
            {{ trigger.payload_json.notification_id }}

EDIT: This works if I use your condition for the ā€˜createā€™ automation but use the original condition for the ā€˜restoreā€™ automation. Weird.

EDIT 2: Oh wow I am stupid. I just re-read your post and you never said to use it in the restore automation. Jesus. Thanks for your help!!!