Store persistent notifications

Does anyone know how to create a flow that stores persistent notifications?

I get the idea, starting from listening to call service events modify an entity/sensor whatever that will store those notifications.

image

[{"id":"74f777ea67012fb7","type":"server-events","z":"66b702e7.2af0fc","name":"","server":"9405c3fe.d0a6c","version":3,"exposeAsEntityConfig":"","eventType":"call_service","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":1470,"y":1440,"wires":[["311cf50e76974799"]]},{"id":"311cf50e76974799","type":"switch","z":"66b702e7.2af0fc","name":"","property":"payload.event.domain","propertyType":"msg","rules":[{"t":"eq","v":"persistent_notification","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1595,"y":1440,"wires":[["fd0ee8d59d8d5593","4489c2a8b97d2d3f"]],"l":false},{"id":"4489c2a8b97d2d3f","type":"switch","z":"66b702e7.2af0fc","name":"service","property":"payload.event.service","propertyType":"msg","rules":[{"t":"eq","v":"create","vt":"str"},{"t":"eq","v":"dismiss","vt":"str"},{"t":"eq","v":"dismiss_all","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1700,"y":1440,"wires":[["e0cff51cd254b801"],["22727c3d9f6b9a65"],["7de2c0e74f29467d"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Main problem is I don’t know how to store pairs of values. Every notification mainly consists (in my case) in a pair of values (notification_id and title).

image

How can I add up them in an array so they always work? I mean…when there’s only 1 value, how can I create an array of just 1 pair of values? when another notification adds up, how can I create the new array so values don’t duplicate?

I’m really lost, I tried achieving it by piling them in a string but ended up in a dead end.

any help will be appreciated

You can use an API node with the endpoint persistent_notification/get to get all current persistent notifications.

image

lol, you are the best. You just saved me 95% of the work. Thanks a lot.

How are you getting the persistent notification in the first place? I can’t figure out how to trigger a node when a notification is received.

Try this

[{"id":"0224b915f6f93307","type":"server-events","z":"3a44d3fc.6dcf5c","name":"","server":"","version":3,"exposeAsEntityConfig":"","eventType":"call_service","eventData":"{\"service\":\"persistent_notification\"}","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":440,"y":860,"wires":[["d55fae42a591c475"]]}]

No. I called the persistent notification service and this node was not triggered.

From what I am reading, what is in the data field, if it matches is omitted. So remove that and use a switch set to the path, looking for "persistent_notification" in payload.event.domain

Sorry I was zoomed out of the browser window, it’s emitted not omitted.

Try this

[{"id":"5a1775687acac933","type":"server-events","z":"60f2d2277843c698","name":"","server":"6b1110b5.183a4","version":3,"exposeAsEntityConfig":"","eventType":"call_service","eventData":"{\"domain\":\"notify\",\"service\":\"persistent_notification\"}","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":250,"y":1700,"wires":[["dcb05f04e5f5a6f5"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

Sorry, I forgot that persistent notifications can be created in two different ways.

This should work for you.

[{"id":"0224b915f6f93307","type":"server-events","z":"3a44d3fc.6dcf5c","name":"","server":"","version":3,"exposeAsEntityConfig":"","eventType":"call_service","eventData":"{\"domain\":\"persistent_notification\",\"service\":\"create\"}","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"$outputData(\"eventData\").event_type","valueType":"jsonata"}],"x":700,"y":750,"wires":[[]]}]

A small improvement. This should be triggered with both persistent_notification.create and notify.persistent_notification.

[{"id":"6bd7cd8c77474eab","type":"server-events","z":"3a44d3fc.6dcf5c","name":"","server":"","version":3,"exposeAsEntityConfig":"","eventType":"call_service","eventData":"","waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"$outputData(\"eventData\").event.domain in [\"notify\", \"persistent_notification\"]?$outputData(\"eventData\").event.service in [\"create\", \"persistent_notification\"]?$outputData(\"eventData\")['payload']","valueType":"jsonata"}],"x":1750,"y":1040,"wires":[["62212613bb6dda27"]]}]