Need help with my pool automation please

I’m trying to find a way to have my pool drain automatically. The code below works to start the pool draining but the condition inside the action does not work as the condition does not see a state change. Can someone suggest a better way using template that will allow the pump to turn on when the pool level is high (with a customized TTS message) and turn off when the pool level returns to normal (with the new message)?

  - alias: 'Pool Pump Auto Drain On'
  # If the pool pump and swimming season input booleans are off and the aggregate pool sensor reads 'high', ##
  # the pool pump will switch on until the aggregate pool level returns a 'normal' value ##
    trigger:
      - platform: state
        entity_id: sensor.aggregate_pool_level
        to: 'High'
    condition:
      - condition: state
        entity_id: switch.pool_pump
        state: 'off'
      # - condition: state
      #   entity_id: input_boolean.pool_pump_auto_drain_pool
      #   state: 'on'  
      - condition: state
        entity_id: input_boolean.swimming_season
        state: 'off'               
    action:
      - service: homeassistant.turn_on
        entity_id: switch.pool_pump
      #- delay: "{{ states('input_number.pump_delay_slider') | multiply(60) | timestamp_custom('%H:%M:%S',False) }}"
      # Waits for the pool level sensor to go from High to Normal and the continues with the next action #
      - service: script.ghm_tts ## Calls the Google Home app group called media_player.tts_homes
        data_template:
          tts: "Uh oh. The pool level is too high. I've started to drain it automatically"
          volume: 0.5      
      - condition: state
        entity_id: sensor.aggregate_pool_level
        state: 'Normal'      
      - service: homeassistant.turn_off
        entity_id: switch.pool_pump
      - service: script.ghm_tts ## Calls the Google Home app group called media_player.tts_homes
        data_template:
          tts: "The pool level has returned to normal. I've switched off the pump"
          volume: 0.5 

The condition in the action doesn’t wait for anything. If the pool level is not Normal, the condition evaluates to false and the action ends there.

What you want isn’t a condition but a wait_template.

This action evaluates the template, and if true, the script will continue. If not, then it will wait until it is true.

      - wait_template: "{{ is_state('sensor.aggregate_pool_level', 'Normal') }}"

Thank you and of course!! Brain fart. I’ve used wait templates in other automations. Added to this one as you suggested and it works a treat. Thanks a heap.

1 Like