I try to use the dismiss of a persistent notificaiton as a trigger for an automation.
At first i start with something like this:
- alias: 'Test.'
trigger:
platform: state
entity_id: persistent_notification.test
from: "notifying"
action:
test
This didn’t work because the entities state is not available anymore because after you dismiss the notitifacion the enity is gone.
So maybe I can do something with event as a trigger?
There is an event type persistent_notifications_updated but I did not know how to implement this in my automation.
I only need the part to see if the persistent notification ist deleted. But I need to know which persistent notification is deleted. Did you know how to archieve this? All of my persistent notifications have an id.
I’ll take a guess that the notification_id is accessible via trigger.event.data.notification_id so you can create a Template Condition to check if it matches the one you want.
Actually, that’s not the reason. It should work, but doesn’t because a bug was introduced a year ago when they started introducing code to track the context of events, etc. See PR #16415. The bug is on this line:
When the notification is dismissed, to_s is None, and so to_s.context causes an exception.
Here is the corresponding state_changed event (where to_s in the code corresponds to new_state in the event):
Oops, my bad. @123’s suggestions, of course, are another perfectly fine way to solve the problem. I was more commenting on the bug that prevented your first attempt from working.
I ended up coming up with a slightly different take on this one. Basically the tack as @pnbruckner’s solution, I justed tested for an unknown state in the condition to differentiate the notification being created or dismissed. Seems to work well enough.
But this automation gets trigered every 10-20 minutes 0o I really dont understand why:o The good thing is: Its working when the correct persistent notification gets dissmissed. But its a little bit odd to get all these messages the whole day:D