Please help with automation that re-evaluates conditions

Hi, I’m still learning the best way to automate in HA. can someone please assist with the following example?
Essentially we have a dishwasher with a button to queue up remote start. We finish loading the dishwasher and add soap, then hit the button and it goes into “ready mode” This is my trigger. but I want it to wait until several conditions are met… like solar production over 2000w, Hot water availability at least at 40%. Then run the dishwasher.
The below code works, If I manually trigger it when all conditions are true. I know I need some kind of wait/loop command to have it re-evaluate the conditions over some kind of timeframe so the action will run once those conditions are met. I just don’t know what the most elegant way to do it is.

alias: DishwasherTest
description: ""
trigger:
  - type: turned_on
    platform: device
    device_id: 493ccf96f114a939039cd7f77f4f4257
    entity_id: binary_sensor.azidishwasher_remote_start
    domain: binary_sensor
condition:
  - type: is_value
    condition: device
    device_id: 10b1c10e044030a0f136bb1c1d6b9dd8
    entity_id: sensor.aziwaterheater_available_hot_water
    domain: sensor
    above: 39
  - type: is_value
    condition: device
    device_id: 50edeb035bd96c9ec3e2ba9a4ff8ffbd
    entity_id: sensor.envoy_current_power_production
    domain: sensor
    above: 2000
  - condition: template
    value_template: >-
      {% if not is_state('sensor.azidishwasher_operation_state', 'Run') %}true{%
      endif %}
action:
  - type: turn_on
    device_id: 493ccf96f114a939039cd7f77f4f4257
    entity_id: switch.azidishwasher_power
    domain: switch
  - delay:
      hours: 0
      minutes: 0
      seconds: 3
      milliseconds: 0
  - type: turn_on
    device_id: 493ccf96f114a939039cd7f77f4f4257
    entity_id: switch.azidishwasher_program_auto2
    domain: switch
mode: single

Add all the sensors involved in the “several conditions” as triggers, so it will re-evaluate the conditions every time one of those sensors change and will run as soon all the conditions are met.

Try this:

alias: DishwasherTest
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.azidishwasher_remote_start
    to: "on"
  - platform: numeric_state
    entity_id: sensor.aziwaterheater_available_hot_water
    above: 39
  - platform: numeric_state
    entity_id: sensor.envoy_current_power_production
    above: 2000
  - platform: state
    entity_id:
      - sensor.azidishwasher_operation_state
    not_to: "Run"
condition:
  - condition: state
    entity_id: binary_sensor.azidishwasher_remote_start
    state: "on"
  - condition: numeric_state
    entity_id: sensor.aziwaterheater_available_hot_water
    above: 39
  - condition: numeric_state
    entity_id: sensor.envoy_current_power_production
    above: 2000
  - condition: not
    conditions:
      - condition: state
        entity_id: sensor.azidishwasher_operation_state
        state: "Run"
action:
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.azidishwasher_power
  - delay:
      seconds: 3
  - service: switch.turn_on
    data: {}
    target:
      entity_id: switch.azidishwasher_program_auto2
mode: single

Basically, when any of the conditions are met, it will test all the conditions…

1 Like