Wait_for_trigger not working as expected

Hi all,
I have problems doing an automation simply switching on a switch if value is above, and wait for being below to switch it off again. Should be a simple one, but it does not work like I expect it, i.e. the “wait_for_trigger” obviously acts different to what I understand it to.

Here´s my automation yaml:

alias: Solar Charging
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.solar_power_status
    above: 2000
condition: []
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.garage_chargingdevice_switch
    data: {}
  - wait_for_trigger:
      - platform: numeric_state
        entity_id:
          - sensor.solar_power_status
        below: 1500
        for:
          hours: 0
          minutes: 0
          seconds: 0
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - service: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.garage_chargingdevice_switch
mode: single

The result is, that when value is jumping above 2000, the switch gets turned on for 5min, then it gets switched off again - anyway how the value is. I thought it should wait for the value getting below 1500 as stated in the above term - am I wrong in this?

In the trace for this step I see

result: false
state: 2007
wanted_state_below: 1500

The same trigger that fires the automation, cannot get waited for to within the automation. Am I wrong or the system? Bug or me?

I worked around it now by having two automations, one for switching on, one for switching off. But shouldn´t this be the way to do something like that?

Any input appreciated…

BR, Jo

You have a 5 min time out on your wait for.
So after 5 mins it will no longer wait for value to be below.

If you had the wait for trigger but with no timeout it would wait indefinitely for the value to drop before continuing. However this is not great as the automation will stop if you reboot home assistant for example.

If it were me I would use 2 triggers one for above value and one for below value. I would then use a choose option based on above trigger to switch either on or off based on the trigger.

1 Like

The other option is to set the continue_on_timeout option to false.

The wait will still time out after 5 minutes if the value has not dropped below 1500 but the actions after the wait will not be executed.

However your switch may never turn off.

This is by far the best way:

The 5min i´ve set for a try. Before I had zero, then it simply switched on and off immediately again. So you say I have to set the “continue_on_timeout” within the “wait for trigger” to false? will give it a try

As I said, that is a bad idea.

If your solar power does not go below 1500 in 5 minutes the wait will time out and nothing will happen. Your switch will never turn off.

This is the way to do it:

Why not two automations?

1 Like

Indeed. I almost mentioned that.