I’ve been using a quite old version of HA, 2023.5.4, but today I decided to step up my game and upgrade. I’m also running Node Red, that I also upgraded. Everything works nicely, after a bit of clean up, but there’s one thing that I can’t get back up and running.
In node red I had an automation that sent me an alert on “persistent_notification.http_login”, that was triggered when someone tried to log in but failed. I also had one for “persistent_notification.ip_ban”.
I used to have these as entity id in node red, but those aren’t there any more after upgrading.
I’ve been able to use the “all events” node and receive a manually pushed persistent notification, but for some reason the http_login and ip_ban won’t show up.
Any ideas?
2023.6 removed states from persistent notifications. You could use the file integration to watch the ip_bans file. Idk about the logins. There maybe something in this post.
Thanks, that pointed me in the right direction. I don’t think it’s possible to receive these notifications in Node Red any more (correct me if I’m wrong!) but I managed to make a yaml automation to do what I needed.
For anyone looking to do the same, here’s what I did:
alias: Notify on failed login
triggers:
- trigger: persistent_notification
update_type:
- added
- updated
conditions:
- condition: template
value_template: "{{trigger.notification.notification_id in ['ip-ban','http-login']}}"
actions:
- data:
title: |
{% set title = trigger.notification.title %} Home assistant: {{title}}
message: >
{% set message = trigger.notification.message %}
{% set now = now().strftime('%d %b: %X') %}
Login notification other: {{now}}: {{message}}
action: notify.slack
mode: queued
Strange that this information is so buried. I needed to use the api to get the notification_id
. There is a sensor that has a count of persistent notifications. When that changes/updates it will fetch the list from the api, split the array and then filter by notification_id
.
[{"id":"5f71c95c46e740fe","type":"inject","z":"0a325c35fc29f44e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":680,"wires":[["fd3c863a6008778c"]]},{"id":"fd3c863a6008778c","type":"ha-api","z":"0a325c35fc29f44e","name":"","server":"","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{ \"type\": \"persistent_notification/get\" }","dataType":"jsonata","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":550,"y":720,"wires":[["f7b997b76221dab2","f75c82cee63feb9c"]]},{"id":"f7b997b76221dab2","type":"split","z":"0a325c35fc29f44e","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload","x":690,"y":720,"wires":[["08c4b615c1cb6b95"]]},{"id":"08c4b615c1cb6b95","type":"switch","z":"0a325c35fc29f44e","name":"","property":"payload.notification_id","propertyType":"msg","rules":[{"t":"eq","v":"http-login","vt":"str"},{"t":"eq","v":"ip-ban","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":810,"y":720,"wires":[["f75c82cee63feb9c","745d4b91ecac2cd4"],["745d4b91ecac2cd4"]]},{"id":"745d4b91ecac2cd4","type":"debug","z":"0a325c35fc29f44e","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":720,"wires":[]},{"id":"ac8d956b089012e4","type":"server-state-changed","z":"0a325c35fc29f44e","name":"","server":"","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["sensor.persistent_notifications"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":240,"y":720,"wires":[["fd3c863a6008778c"]]}]