I’m trying to setup a notification to change my door lock battery if it goes below 20%. However, I want the notification to include which lock it is actually low. Looked around the examples and they all seem to point to {{ trigger.name }} but it’s not working. The notification comes through but the entity name string is not being substituted in. Can anyone provide some guidance?
If you tested it with the Run command then it’s not an effective test for this particular application.
The Run command only executes the automation’s actions, not its triggers. Your notify action refers to the trigger variable which only exists when the automation is triggered by one of its triggers. Otherwise, it’s undefined.
I want to change it so that it’d nag me to about the battery. Just to test I changed the trigger to time_pattern that fires every minute. However, it doesn’t seem to be triggering the notification at all anymore. Furthermore, if I move the entities to the conditions field, I’m guessing I need to change the template for the entity names?
Your new automation will only run if one of those sensors is actually reporting below 20. Is it?
The new automation also has no trigger.to_state because the trigger is not a state trigger.
Finally, the original automation you posted will only run when the state goes from above 20 to below 20. If the hardware is reliable, that will happen exactly once (until you replace the battery and it drops down to 20 again). If you want the automation to nag you, presumably you want it to do so more than once per battery replacement cycle—so what you want is probably a version of the time_pattern trigger set to fire as often as you want to be nagged, with the conditions correctly specified.
Yes I’d like it to nag as often as I want, which I can adjust via the time_pattern. As you said, the original version will only notify when it went from above 20 to below 20. Which will only happen once, which I don’t want to miss changing the battery for. That said, if I’m to go with the new version, how do I make it notify and state which entity is low on battery?
With the current approach of using a time_pattern trigger with conditions, you will need an if: statement in your automation’s action block to check the individual battery states. In a way, it might seem redundant with the conditions block where you are already checking the inequality, but the conditions block only controls whether the automation runs. Once it runs, it needs to again consult the state or the batteries to figure out which battery/ies are low.
Alternatively, you can have a separate automation (with its own conditions block) for each battery.
Your automation will trigger 525600 times a year to detect potentially 2 instances of “low battery”?
I suggest creating a Trigger-based Template Binary Sensor that uses a Numeric State Trigger to detect when the battery level decreases below 20 plus another trigger as backup to handle the rare possibilty that the Numeric State Trigger is missed.
The “backup trigger” can fire when some sort of occasional, benign event occurs (like when automations are reloaded or even when a door opens). The template checks both battery levels and if either are below 20, sets the state to on.
The Alert integration monitors the Trigger-based Template Binary Sensor’s state and, when on, warns you repeatedly (plus it provides better control of the alerting behavior).
It appears the OP intends to use a Time Pattern Trigger.
They want it because of a concern that the Numeric State Trigger might fail to fire.
If the intent is to reduce the polling frequency to once an hour, that’s still 8760 times a year just to mitigate the unlikely possibility that a Numeric State Trigger will fail to trigger.
Plus if the goal is to send repeated reminders, its frequency is currently tied to the Time Pattern Trigger’s frequency. Ideally it should be managed separately (such as with the Alert integration).
True but I didn’t see a constraint that it must be done exclusively with an automation.
It’s a few lines of YAML that provides superior functionality and control of the notification process. It decouples the task of detecting a low-battery condition from the task of repeatedly reporting it (along with the ability to acknowledge and dismiss it).
FWIW, Didgeridrew already suggested the use of the Alert integration.