Automation to check two sensor till both conditions are true

Hey there,

in my kitchen I have a switch, which should trigger an automation, when switched off.
The automation should first switch off the plug for my dishwasher and then check two different sensor values till both are true. Then the same plug should be switched on again.

This is my YAML:

alias: Spülmaschine - Programm Solar
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: 33ce7e76787d742c0ea5380685c4c9c2
    entity_id: switch.wallplug_multisteckdose_2
    domain: switch
condition: []
action:
  - type: turn_off
    device_id: 75dfa78875f42726cf89cb81b2174bd4
    entity_id: switch.spuelmaschine
    domain: switch
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.battery_soc
        above: '25'
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.solar_production_2
        above: '3000'
  - type: turn_on
    device_id: 75dfa78875f42726cf89cb81b2174bd4
    entity_id: switch.spuelmaschine
    domain: switch
mode: single

The wait for trigger function seems to work in both cases but at the end the plug will not be turned on.

Any ideas?
Thanks!

Have you examined the automation’s trace to determine why it fails to turn on the switch?

With one sensor it works fine…

With a second sensor in a row it stops without any message. Although the second sensor becomes/ is above the target value nothing happen.

“becomes” and “is” are two different things. “Becomes” will trigger the wait for trigger. “is” will not. Triggers are events, not states.

Use a wait template instead. This will wait until the two conditions are true, they can be true already and the wait will finish:

wait_template: "{{ states('sensor.battery_soc')|float(0) > 25 and states('sensor.solar_production_2')|float(0) > 3000 }}"

Note: it is not wise to wait in automations for long periods of time. The chances of you reloading automations or restarting (cancelling the automation) become more likely the longer you wait.

It would be wiser if you triggered a separate automation to turn the switch back on.

You can ensure both sensor values are true like this:

trigger:
  - platform: numeric_state
    entity_id: sensor.battery_soc
    above: 25
  - platform: numeric_state
    entity_id: sensor.solar_production_2
    above: 3000
  - platform: homeassistant
    event: start 
condition:
  - condition: numeric_state
    entity_id: sensor.battery_soc
    above: 25
  - condition: numeric_state
    entity_id: sensor.solar_production_2
    above: 3000
  - condition: state
    entity_id: switch.wallplug_multisteckdose_2
    state: 'off'
action:
  - service: switch.turn_on
    target:
      entity_id: switch.spuelmaschine
1 Like

The simplest is usually the best way!

Thanks for your assistance and input. With two automations it works like charm.

Cheers.

1 Like