Reservoir solenoid valve open based on sensor template

Hey all, I’m rather new to home assistant, and am working on automating an irrigation reservoir. My intent is for when I set the helper to my desired volume and hit run, a script will run that open the valve until the volume sensor template goes above the value set via helper, then shut off. Here is the yaml, not sure if i’m using the right functions

fillrez_script:
  alias: Fill Rez
  sequence:
  - type: turn_on
    device_id: 6c01e1f5318ceb498c44ad72ef1e4cf9
    entity_id: switch.rez_valve
    domain: switch
  - wait_for_trigger:
    - platform: numeric_state
      value_template: "{{ sensor.upstairs_volume }}"
      above: '{{ states(''input_number.desiredrezvolume'') | int }}'
  - type: turn_off
    device_id: 6c01e1f5318ceb498c44ad72ef1e4cf9
    entity_id: switch.rez_valve
    domain: switch
  mode: single
  icon: mdi:water-pump

Switch the valve on directly (no need for a helper). Then use an automation to shut it off once the desired level is reached:

trigger:
  - platform: numeric_state
    entity_id: sensor.upstairs_volume
    above: input_number.desiredrezvolume
action:
  - service: switch.turn_off
    target:
      entity_id: switch.rez_valve

Note this will not switch off the valve if you change the input number to below the tank level after the valve is already on (the trigger only monitors for changes in the sensor, not the input number). To have that functionality use a template trigger instead:

trigger:
  - platform: template
    value_template: "{{ states('sensor.upstairs_volume')|float(0) > states('input_number.desiredrezvolume')|float(0) }}"
action:
  - service: switch.turn_off
    target:
      entity_id: switch.rez_valve

thanks for the quick response, this community rocks. That sure seems significantly simpler than my previous yaml, though i’m not quite sure how to fit that into a script

ahh wait this is an automation, not a script. will report back

update: works perfectly, thanks again

1 Like