Make greenhouse automation more efficient

I guess there is many ways to make my greenhouse watering automation more efficient and stable so i make a shout and see what you got(i know youre alot more skilled at this than me :wink: )

The system:
I got 12 boxes with a humidity sensor in each and when the level gets low i want to start filling by opening a valve.
function:
I want to fill slow so the sensor got time to feel the change so i don´t overfill. Therefor i have two variables , runtime and a delay between runtime. ofc also what to what level of humidity to fill up to.
one condition is also that only one box can be filled at once so i can mesaure how mutch water each box uses.

so this is what i have done so far and one for each box:
some hate the looping timetrig, and i know why but its a easy solution :wink:
hope you have something good to share

- alias: 'filling box 1'
  description: ''
  initial_state: off
  trigger:
    - platform: time_pattern
      seconds: "/10"
  condition:
    condition: and  
    conditions:
        - condition: template
          value_template: '{{ states.sensor.soilsensor1.state|int>  states("input_number.level")|int }}'
        - condition: template  
          value_template: > 
                {{states.switch.relay2.state == 'off' and
                  states.switch.relay3.state == 'off' and
                  states.switch.relay4.state == 'off' and
                  states.switch.relay5.state == 'off' and
                  states.switch.relay6.state == 'off' and
                  states.switch.relay7.state == 'off' and
                  states.switch.relay8.state == 'off' and
                  states.switch.relay9.state == 'off' and
                  states.switch.relay10.state == 'off' and
                  states.switch.relay11.state == 'off' and
                  states.switch.relay12.state == 'off' }}   
  action:
    - service: switch.turn_on
      entity_id: 
        - switch.relay1
    - delay:
        seconds: "{{ states('input_number.run')|int }}"    
    - service: switch.turn_off
      entity_id: 
        - switch.relay1 
    - delay:
        seconds: "{{ states('input_number.delay')|int }}"  

I have some ideas on how to simplify the automation (including eliminating the Time Pattern Trigger and making it entirely event driven). However, before exploring those ideas I want to draw your attention to how you are controlling the valves.

You’re using a delay to control the amount of time a valve is turned on. Are you aware that automation’s that are in progress (like this automation when it’s waiting for delay to expire) are terminated and reset whenever you restart Home Assistant or simply execute Reload Automations (which happens transparently whenever you use the Automation Editor to save a new or modified automation)?

In other words, there’s the possibility for a valve to be turned on but not turned off according to the value specified by input_number.run.

Let me know if you consider that to be, or not be, a problem for your application

Hi,
yeah, im aware of that the relay can be in state on and of corse its a risk that it wont close the valve so if its possible to make the risk of overfilling smaller im on! ( i havent tried what happend since im aware of the risk but as human i can forgot it also :slight_smile: )

this is the third version of some sort of automated watering solution, and for every version it can only be better(less overfilled boxex :wink: )

so im open for more solutions to improve the function

What are the typical value ranges for input_number.run and input_number.delay?

hi,
Around 10sec running and 30 sec delay.
the value for stop(input_number.level) did i hope so set for all but since the value is different on each soilsensor do i have to set individual values for each box