Get trigger name that triggered the automation in YAML

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?

{{ ... }}

1 Like

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
3 Likes

{{ 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.

8 Likes

For future reference, these two are different:

  1. The name of the entity responsible for triggering the automation.
  2. The name of the trigger.

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.

2 Likes