Now that most functionality is correct, there is one more thing ( there always is…):
Upon restart, the notification tray is empty, and in the former implementation of Pers. notifications, the system would no longer have ‘notifying’ notifications. However, the trigger template still shows the state that it was in before restart, as it is restoring per design.
That is ok in itself, maybe even better than the core Pers. Notifications, but it is no longer in sync.
Also clearing the notifications now does Not work, and the last state remains. Apparently the ids are no longer in the system, so the clear does not know what to clear?
That could be an issue.
Wonder what to do. Maybe add homeassistant start to the triggers for the template?
That would probably make it sync . I do like the ‘memory’ it now displays though , but don’t like we can not clear …
No, adding the homeassistant start trigger is not perfect either, it now errors on:
Template variable error: 'dict object' has no attribute 'notification' when rendering '{% set msgs = this.attributes.get('notifications', []) %} {% if trigger.update_type == 'added' %} {% set new = [{ "id": trigger.notification.notification_id, "title": trigger.notification.title, "message": trigger.notification.message, "created_at": trigger.notification.created_at.isoformat() }] %} {{ msgs + new }} {% else %} {{msgs | rejectattr('id', 'eq', trigger.notification.notification_id) | list }} {% endif %}'
so apparently even the [] in the getter does not help here
- trigger:
- platform: homeassistant
event: start
- platform: persistent_notification
update_type:
- added
- removed
sensor:
- unique_id: persistent_notifications_overview
device_class: timestamp
state: >
{{now()}}
attributes:
notifications: >
{% set msgs = this.attributes.get('notifications', []) %}
{% if trigger.update_type == 'added' %}
{% set new = [{
"id": trigger.notification.notification_id,
"title": trigger.notification.title,
"message": trigger.notification.message,
"created_at": trigger.notification.created_at.isoformat() }] %}
{{ msgs + new }}
{% else %}
{{msgs | rejectattr('id', 'eq', trigger.notification.notification_id) | list }}
{% endif %}