I have an automation that triggers when an illegal login attempt is made to my HA instance, the automation works perfectly every time, however I get an error in the logs when it runs and wondered if someone can tell me what I have done wrong here…
Automation relevant section:
- service: notify.mobile_app_picoiphone
data_template:
title: Hold down to view log
message: '{{ state_attr(''persistent_notification.http_login'', ''message'') }}'
data:
actions:
- action: URI
title: Open Url
uri: /config/logs
push:
sound:
name: default
critical: 1
volume: 1
And the errors:
Illegal Login Notify : Choose at step 1: choice 1: Error executing script. Invalid data for call_service at pos 1: template value is None for dictionary value @ data[‘message’]
Illegal Login Notify : Error executing script. Invalid data for choose at pos 1: template value is None for dictionary value @ data[‘message’]
One thing that could cause that error is if the entity persistent_notification.http_login doesn’t exist.
So it’s possible that the automation is triggering before the persistent automation has been created or it has been dismissed by the time it has triggered
Thanks for the input
I was concentrating on this bit to be honest and the only part that has message is the above…
I will post full automation below just in case
Since you are not using the from or to option in the trigger, this will fire on any update to the entity. For persistent notifications it appears that this includes dismissing the notification (which also removes the entity).
So, assuming that you dismiss the persistent notification, it is likely that this is causing the automation to fire again and causing the error (as the entity now no longer exists).
You can avoid this by changing the trigger to
trigger:
- platform: state
entity_id: persistent_notification.http_login
to: notifying
id: login attempt failed
- platform: state
entity_id: persistent_notification.ip_ban
to: notifying
id: 'ip address banned '
so that it will only trigger when the state of the persistent notification goes to notifying, which won’t be the case when you dismiss it.
Thanks, you were spot on, I have just had a chance to test this and no error in logs follow the actual notification / event, it is intact when I dismiss the notification that the error takes place.