Accessing trigger.entity_id inside a wait_for_trigger?

In the wait action you are defining a new trigger that has not happened yet so there is no trigger.entity_id.

You may be able to get around it with a variable to store the first trigger’s entity_id (untested):

trigger:
  - platform: state
    entity_id: binary_sensor.test_device
    to: 'on'
condition: []
action:
  - variables:
      first_trig_entity_id: "{{ trigger.entity_id }}"
  - service: notify.signal_group_debug
    data:
      message: "{{ trigger.to_state.name }} was left open"
  - wait_for_trigger:
      - platform: state
        entity_id: >
          {{ first_trig_entity_id }}
        to: "off"
  - service: notify.signal_group_debug
    data:
      message: "{{ trigger.to_state.name }} was closed"

I also removed the device trigger as I hate them (for good reason).

If you are going to add a list of entities in the trigger you need to run this automation in parallel mode. So that each door event gets it’s own wait for close. The default automation mode is “single”. In single mode if one door opens then another opens before the first door is closed the automation will ignore this second trigger.

1 Like