Wait_template does not work

Hi,

I am working on an automation to switch on/off a fan in our basement, to reduce humidity. My first approach does work, but not as smoothley, as I hoped. (-> Reduce humidity in basement - automation does not work)

I want to try a different approach, but I am struggling with the “wait_template” in my automation.

My idea:

  • My automation does start the fan as expected.
  • To switch the fan off, I added two conditions in the wait_template. If one or the other is true, the fan should stop. Unfortunately, there seems to be something wrong and the fan never stops.

Any help is very much appreciated.

alias: Garage Lüfter Steuerung v2
description: Schaltet Lüfter, um Raum zu entfeuchten
trigger:
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    from: 'on'
    to: 'off'
    for: '00:15:00'
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
    from: 'on'
    to: 'off'
condition:
  - condition: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    state: 'off'
  - condition: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
    state: 'off'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.tasmota_2
  - wait_template: >
      "{{ is_state("binary_sensor.openweathermap_dewpoint_trend_rising", "on")
      or is_state("binary_sensor.tasmota_am2301_dewpoint_2_vs_garten", "on") }}"
  - service: switch.turn_off
    target:
      entity_id: switch.tasmota_2
mode: single
action:
  - wait_for_trigger:
      - platform: state
        entity_id: 'binary_sensor.openweathermap_dewpoint_trend_rising'
        from: 'off'
        to: 'on'
      - platform: state
        entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
        from: 'off'
        to: 'on'
  - service: switch.turn_on
    target:
      entity_id: switch.tasmota_2
mode: single

thank you very much for your quick help. Do I understand this correctly, that the two conditions in the wait_for_trigger are AND-conditions? How do I make it OR?

I think it will work

alias: Garage Lüfter Steuerung v2
description: Schaltet Lüfter, um Raum zu entfeuchten
trigger:
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    from: 'on'
    to: 'off'
    for: '00:15:00'
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
    from: 'on'
    to: 'off'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.tasmota_2
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
        from: 'off'
        to: 'on'
      - platform: state
        entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
        from: 'off'
        to: 'on'
  - service: switch.turn_off
    target:
      entity_id: switch.tasmota_2
mode: single

Try removing the quotes-

alias: Garage Lüfter Steuerung v2
description: Schaltet Lüfter, um Raum zu entfeuchten
trigger:
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    from: 'on'
    to: 'off'
    for: '00:15:00'
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
    from: 'on'
    to: 'off'
condition:
  - condition: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    state: 'off'
  - condition: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
    state: 'off'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.tasmota_2
  - wait_template: >
      {{ is_state("binary_sensor.openweathermap_dewpoint_trend_rising", "on")
      or is_state("binary_sensor.tasmota_am2301_dewpoint_2_vs_garten", "on") }}
  - service: switch.turn_off
    target:
      entity_id: switch.tasmota_2
mode: single

Note that wait_template does not survive Home Assistant reboot/crashes.

It’s better if you do specify all the triggers (OFF and ON) and use choose action-

trigger:
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    from: 'on'
    to: 'off'
    for: '00:15:00'
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
    from: 'off'
    to: 'on'
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: >-
              {{ trigger.to_state.state == 'off' }}
          - condition: state
            entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
            state: 'off'
          - condition: state
            entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
            state: 'off'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.tasmota_2
    default:
      - service: switch.turn_off
        target:
          entity_id: switch.tasmota_2

Thank you both for your inputs, very much appreciated!

ardysusilo
Try removing the quotes

I ended up editing my automation in the file-editor-app in HA. there, the syntax highliting seems to be okay, when using this. I will test it and report back, if it works.

  action:
  - service: switch.turn_on
    target:
      entity_id: switch.tasmota
  - wait_template: "{{ is_state('binary_sensor.openweathermap_dewpoint_trend_rising', 'on') or is_state('binary_sensor.tasmota_am2301_dewpoint_vs_garten', 'on') }}"
  - service: switch.turn_off
    target:
      entity_id: switch.tasmota

I do not yet fully understand your second proposal, but I tried to create an automation according to my understanding.

- id: '1629661133929'
  alias: Garage Lüfter Steuerung v4
  description: Lüfter in Garage steuern
  trigger: # all relevant triggers are mentioned here
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising # if dew point outside is rising above a defined rate, fan should be switched off - else switched on
    from: 'on'
    to: 'off'
    for: 00:15:00
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten # of dew point outside rises above dew point inside, fan should be switched off - else switched on
    from: 'on'
    to: 'off'
  - platform: state
    entity_id: binary_sensor.openweathermap_dewpoint_trend_rising # see first trigger
    from: 'off'
    to: 'on'
  - platform: state
    entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten # see second trigger
    from: 'off'
    to: 'on'
  condition: []
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
        state: 'off'
      - condition: template
        value_template: "{{ states('sensor.tasmota_am2301_dewpoint_2')|float > states('sensor.openweathermap_dew_point')|float }}"
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.tasmota_2
    - conditions:
      - condition: state
        entity_id: binary_sensor.openweathermap_dewpoint_trend_rising
        state: 'off'
      - condition: state
        entity_id: binary_sensor.tasmota_am2301_dewpoint_2_vs_garten
        state: 'off'
      sequence:
      - service: switch.turn_on
        target:
          entity_id: switch.tasmota_2
    default:
    - service: switch.turn_off
      target:
        entity_id: switch.tasmota_2
  mode: single

I will test this for at least 24h and report back.

Unfortunately, this does not work. It never triggers the action to stop.
But the other automation with the “choose”-function seems to do the job.