Wait Template help

Hi,

In the below, I am trying to develop logic so if the washing machine is not operational and solar surplus is > 2000 then the dishwasher turns on instantly. Otherwise, it will wait for the timeout of the two wait templates.

What I am finding is that even though the states of “sensor.washing_machine_operational” and “sensor.solar_power_surplus_2000” are False and True respectively the Dishwasher is not instantly turning on. What am I doing wrong with the wait templates?

- id: '1609363796977'
  alias: 'ON: Dishwasher  if Solar is available '
  description: ''
  trigger:
  - entity_id: sensor.solar_power_surplus_2000
    for: 0:05:00
    from: 'False'
    platform: state
    to: 'True'
  condition:
  - condition: state
    entity_id: sun.sun
    state: above_horizon
  action:
  - wait_template: '''{{ is_state(''sensor.washing_machine_operational'', ''False'')
      }}'''
    timeout: 00:10:00
    continue_on_timeout: true
  - timeout: 00:20:00
    wait_template: '''{{ is_state(''sensor.solar_power_surplus_2000'', ''True'') }}'''
    continue_on_timeout: true
  - data: {}
    entity_id: switch.dishwasher
    service: switch.turn_on
  mode: single
  initial_state: true

This looks screwy, why are you using a sensor for sensor.solar_power_surplus_2000 rather than a simple binary sensor ?

Does this matter? It works correctly and toggles between False and True.

Well, it very wasteful of resources storing text values instead of 0 or 1

Your other wait statements look garbled too

Isn’t how I’d write it but looks okay, though verbose as continue_on_timeout: true is the default

Is just wrong, timeout is a child of wait_template not the other way round
And

Is just gui mangling, though the yaml is correct

Is setting up problems for the future as this implies you switch off automations (bad idea). But more importantly erases the automation last triggered attribute on a restart

But you know better, that’s fine

I’ve worked out what the error is. I had single quotes in the gui around the wait_template. This translated to triple single quotes which I assume was treating everything as a string and not a template?

Solution:-

  - wait_template: '{{ is_state(''sensor.washing_machine_operational'', ''False'') }}'
    timeout: 00:10:00
    continue_on_timeout: true

Thanks for your feedback on the other segments, although I can write yaml I use the gui and agree it is a bit garbled however works.

Doesn’t it have to be a sensor since I’m evaluating an attribute from a smart plug and when the integer is greater than 2000W it changes state.

You could dispense with creating a sensor and simply use a Numeric State Trigger in the automation.

  trigger:
  - platform: numeric_state
    entity_id: switch.my_smart_plug
    attribute: power_whatever
    above: 2000
    for: '00:05:00'