That won’t make any difference. If his code is not working, then your code won’t either. The only difference is that he has a single line template and you’re specifying a multiline template.
Noted. Could it be that the binary sensor is missing the friendly name altogether? If this is a template sensor, the friendly_name is completely optional.
there are many possibilities. Hard to say when we don’t have all the pieces. If the template that I provided returns undefined or None, then he doesn’t have the attribute. In that case he can use this template to get the auto generated name…
{% set domain, object_id = trigger.entity_id.split('.') %}
{{ states[domain][object_id].name }}
Please elaborate on what you mean by ‘doesn’t seem to be rendering’. The action is passing two variables to a script. One of the variables is called message and should contain the binary_sensor’s friendly_name. You’re saying it doesn’t so what does message contain? Some other value or nothing at all?
FWIW, I tested this simple automation and it works. The notification contained the input_boolean’s friendly_name.
- alias: 'test 44'
trigger:
platform: state
entity_id: input_boolean.guest
action:
service: persistent_notification.create
data_template:
title: test 44
message: "Triggered by {{trigger.to_state.attributes.friendly_name}}"
I don’t think the problem is in the automation or the definition of the binary sensor. It must be in the script, which you haven’t shared yet. Please post the script.
Or possibly are you manually triggering the automation? If so, then the trigger variable will not exist, and that will cause it to not work as expected. You must trigger the automation normally, meaning you have to get binary_sensor.mba_bath_sensor_low_battery to change to 'on'. If that isn’t happening on its own, and you want to test the automation & script, then go to the States page and use that to force the state of binary_sensor.mba_bath_sensor_low_battery to change (to 'off', and then to 'on'.)
This is the umpteenth time this week someone has manually triggered an automation then reported the automation doesn’t work correctly.
@FutureTense
As the umpteenth person to have done this, can you suggest where in the documentation this important tidbit of information can be plastered so others can avoid making the same mistake?
Please note that if you click on Trigger of an automation in the frontend, only the action part will be executed by Home Assistant. That means you can’t test your trigger or condition part that way. It also means that if your automation uses some data from triggers, it won’t work properly as well just because trigger is not defined in this scenario.
Also, how did you manually trigger it? From the Lovelace UI (trigger button in the automation’s More-Info box) or by using the Developer Tools > Services page?