I use notifications for many things : person location changes, home activities (door/window, locks, security panel, lighting scenes, etc)
I like to see a Historical Log of what triggered, and when but unfortunately the HA notification doesnt make that easy.
This code only requires 1 helper and 1 automation; easy to ‘see’ it exists, no ‘hidden’ templates sensors in the config.
The included code also writes a Persistent Notification. You can remove that code, or use a template to include/exclude notifications as you wish.
enjoy
-- Automation --
alias: Log All Notifications to Helper
description: Stores All Notifications in input_text.log_all_notifications and creates a persistent notification
trigger:
- platform: event
event_type: call_service
event_data:
domain: notify
actions:
- variables:
notif_data: "{{ trigger.event.data.service_data }}"
notif_service: "{{ trigger.event.data.service }}"
notif_title: "{{ notif_data.title | default('Notification') }}"
notif_message: >-
{{ notif_data.message | default(notif_data.title | default('No content')) }}
notif_target: |-
{% if notif_service == 'notify' %}
All devices
{% elif 'mobile_app_' in notif_service %}
{{ notif_service.replace('mobile_app_', '') | replace('_', ' ') | title }}
{% else %}
{{ notif_service | replace('_', ' ') | title }}
{% endif %}
timestamp: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
full_message: "{{ timestamp }} - {{ notif_title }}: {{ notif_message }} → {{ notif_target }}"
- service: input_text.set_value
target:
entity_id: input_text.log_all_notifications
data:
value: "{{ full_message }}"
- service: persistent_notification.create
data:
title: "Logged Notification"
message: "{{ full_message }}"
mode: queued
-- Dashboard Card : create a Helper for input_text.log_all_notifications --
type: custom:logbook-card
entity: input_text.log_all_notifications
show:
state: true
duration: false
start_date: true
end_date: false
icon: false
separator: false
entity_name: true
desc: true