I want to use the name of the trigger in my script to send a notification. The automation has multiple triggers. How can I do this?
{{ ... }}
I want to use the name of the trigger in my script to send a notification. The automation has multiple triggers. How can I do this?
{{ ... }}
There are a bunch of trigger variables available to use in templates:
Edit: wrong link when first posted - sorry:
Here I use the entity name in a notification:
action:
- service: persistent_notification.create
data_template:
message: Sensor {{ trigger.entity_id }} low battery
title: Low Battery Alert
{{ trigger.to_state.name }}
will give you the friendly name of the triggering entity id and fall back to the entity_id if it has no friendly name.
For future reference, these two are different:
You chose tom_l’s post as the Solution so it implies you wanted to know how to get #1.
For future reference, the trigger
object doesn’t always have a to_state
property. It depends on what kind of trigger is used. It’s available for Numeric State, State, Template and Zone Triggers but not for others. For more information, refer to the documentation link in zoogara’s post.