How to get the value of the sensor responsible for triggering an automation action

I want to do an automation for the humidity value of several sensors I have. I can get it to run if I do not show the current value of the sensor but I am trying to show it.

This is the current automation:

alias: "Notify: Humedad muy alta!"
trigger:
  - type: humidity
    platform: device
    device_id: device-id-1
    entity_id: sensor.entity_2
    domain: sensor
    id: room1
    above: 10
  - type: humidity
    platform: device
    device_id: device-id-2
    entity_id: sensor.entity_2
    domain: sensor
    id: room2
    above: 10
  - type: humidity
    platform: device
    device_id: device-id-2
    entity_id: sensor.entity_3
    domain: sensor
    id: room3
    above: 20
condition: []
action:
  - service: notify.mobile_app_my_phone
    data:
      message: |
        The current humidity is of {{ states(trigger.entity_id) }}%
      title: Humidity in {{ trigger.id }} is too high!
      data:
        actions:
          - action: URI
            title: To Home Dashboard
            uri: /lovelace-humedad/default_view
mode: queued
max: 10

I get this error:

Error while executing automation automation.humedad_muy_alta: Error rendering data template: UndefinedError: ‘dict object’ has no attribute ‘entity_id’

I thought the trigger would carry all the info defined in the trigger object but looks like it is not the case (?).

How can I access the value of the trigger sensor dynamically?

As a bonus question, which is the best way to debug this? For example, how can I know what the trigger object contains or what properties are accessible in that context? I can move myself with javascript and typescript but I have negative knowledge of yaml or phyton.

Thanks!

So, I know the basic response… trying to get the trigger info fails when I run the automation manually… this is nice to know…

I still would like how the bonus questions though.

Use the automation’s trace to debug it. However, a trace is produced only if the automation is triggered by one of its triggers (not if you execute the Run menu command or the automation.trigger service call).

It may be challenging to exercise the triggers. For example, your automation is monitoring humidity and it’s inconvenient to alter the room’s actual humidity level to cause triggering. Faced with this situation, you can force an entity’s state value using Developer Tools > States.

  1. Go to Developer Tools > States.
  2. Find sensor.entity_1 in the list and click it.
  3. Its information will appear at the top of the view.
  4. Enter a new value in the State field. For example, a value greater than 10 in order to trigger the automation’s first trigger.
  5. Click Set State button.

This forced value will persist until a new value is received from the actual sensor (or when Home Assistant is restarted).

This trigger provides no entity_id . Have you deleted it accidentally?

Thanks for this explanation! So I kind of have to debug on production :grinning_face_with_smiling_eyes: live and learn!

Yes sorry, I delete it accidentally.