Hi all,
I’m trying to make a simple automation that tells me when my sensor batteries are low. The idea is that the message would have the sensor name in it so I can have one automation with multiple triggers.
I have found what I thought would work which is to add this template to the message text:
{
“message”: “Battery is Low in one of the sensors: {{ trigger.to_state.attributes.friendly_name }}”
}
But no matter what I’ve tried, I always get this error when the automation is triggered:
NOTE: the trigger is a binary_sensor defined in my configuration file and the states are set by MQTT.
homeassistant.exceptions.TemplateError: UndefinedError: ‘trigger’ is undefined
How is trigger “undefined” if the automation was triggered?
I’ve looked through other posts and haven’t found a clear answer. Is there any other way to capture the trigger name?
of course after many tries, and then right after posting this it starts to work.
I’m thinking I wasn’t reloading the atomations like I thought at first because I was at first using the GUI (configuration -> automations) to create the automation. Then I went into the automation.yaml file to change data to data_template.
I thought I had, but apparently not. Thanks for answering so quickly.
And sorry I didn’t put the whole automation text, It’s not formatting correctly when i try to paste it in here.
Just a note, I did have to change the template part to:
{{ trigger.to_state.name }}” because of the attributes.friendly_name returned a blank.
For future reference you can use the instructions for posting code (at the top of the forum) or if you use 3 backticks on the first line and then 3 backticks after the last line of the code it should post properly. ` next to 1 on keyboard…