Problem with wait for trigger

Hello,

I have a little problem with my climate automation. Basically, if an open window is detected, it should turn the heater off and then wait for the window to be closed again before turning the heater on again.

It works fine until the “wait for trigger” action. Even when the window is closed again, it doesn’t trigger. What do I have to put into the entity_id?

  - id: '1636659488289'
    alias: Tado Fenster offen
    trigger:
    - platform: state
      entity_id:
        - binary_sensor.badezimmer_open_window
        - binary_sensor.buro_open_window
        - binary_sensor.flur_open_window
        - binary_sensor.kuche_open_window
        - binary_sensor.zimmer_1_open_window
        - binary_sensor.zimmer_2_open_window
      from: 'off'
      to: 'on'
    action:
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.{{trigger.to_state.entity_id|replace('_open_window','')|replace('binary_sensor.','')}}
        data:
          hvac_mode: 'off'
      - wait_for_trigger:
        - platform: state
          entity_id: trigger.entity_id
          from: "on"
          to: "off"
      - service: climate.set_hvac_mode
        target:
          entity_id: climate.{{trigger.to_state_entity_id|replace('_open_window','')|replace('binary_sensor.','')}}
        data:
          hvac_mode: 'auto'
    mode: parallel

You can’t template the entity_id field on triggers. Not to mention, you didn’t even template it, you just have an invalid entity_id but I believe your intentions were to template that field by extracting the trigger’s entity_id.

You’ll have to make a full template trigger.

also, your second template has a typo.

Is it even possible, to get the entity_id inside the wait for trigger section which originally triggered the automation?

I tried it with different trigger.X commands, but no one worked.

- wait_for_trigger:
  - platform: template
    value_template: "{{ is_state('trigger.to_state.entity_id','off') }}"

Do you know the command which I’m missing?

Use wait_template.

- wait_template: "{{ is_state(trigger.entity_id, 'off') }}"

Yes

- wait_for_trigger:
  - platform: template
    value_template: "{{ is_state(trigger.to_state.entity_id,'off') }}"

The change is subtle, but notice how trigger.to_state.entity_id not in quotes. Also, you can just grab the entity_id directly from the trigger

- wait_for_trigger:
  - platform: template
    value_template: "{{ is_state(trigger.entity_id, 'off') }}"
1 Like

Thank you both! Now it works as it should.