Slow PWM with adjustable period and level

I have a problem with my dwel at my summer cabin.
I need to cycle the water on for about 20 minutes and off on for about 120 minutes.
I have a bunch of esp8266, relay modules and some water valves.
I’m in a down period after a stroke and I don’t have the energy to read and focus to much, so I need some help to get started.
I want the period and level adjustable from HA.
I don’t know, I just cant get it together at the moment, so please help!

Edit: Bad spelling…

Slow_pwm is not very well documented, especially use of period. If you can go with fixed period and just adjust duty, it’s convenient though.
Another option would be script that runs repeatedly, something like this:

switch:
  - platform: gpio
    pin: GPIO5
    id: pump
    name: "Pump"

number:
  - platform: template
    id: pump_on_time
    name: "Pump ON Time"
    min_value: 1
    max_value: 120
    step: 1
    restore_value: true
    initial_value: 20

  - platform: template
    id: pump_off_time
    name: "Pump OFF Time"
    min_value: 1
    max_value: 120
    step: 1
    restore_value: true
    initial_value: 120

script:
  - id: pump_cycle
    mode: restart
    then:
      - while:
          condition:
            lambda: 'return true;'
          then:
            - switch.turn_on: pump
            - delay: !lambda "return (uint32_t)(id(pump_on_time).state * 60000);"
            - switch.turn_off: pump
            - delay: !lambda "return (uint32_t)(id(pump_off_time).state * 60000);"

Thanks, I’ll check this out.
I was actually thinking of doing it this way first, since the start time is not a percentage of another time.

And having a device that automatically clears the well would be good.
I think I need to blow the well up again, even if it is fairly new.
They used to use dynamite in the past, but now they just pressurize it with high pressure.

The well is drilled 110 meters and the pump is at 80 meters. The pump capacity is not that high, about 25 liters per minutes, but still it sucks air after about an hour.

Be careful with the valves you want to either buy or use because there are differences where some have a low duty cycle (how much Off time is required per On time) for example I had some cheap ones that would overheat and do a thermal shutdown after 30min of the valve being On/Open and that made them useless for many requirements. Now i just use plain old ball valves like these along with an esp board and a relay or a mosfet module, its pretty simple.

I have som cheap 12V valves. As far I have tested them 6 hours of open state isn’t a problem.
But that could have been a lucky test.

There’s no need to waste time testing them because that sort of information will be included in the specs/docs.

Back in my day, we used to walk 12 miles in the rain to and from school each day, plus i had a full time job trimming dinosaur nails while I was still in school! You dang youngsters… ; )

Well I used walk and take the bicycle from and school, work. But since I moved to the country side this is not an option. I have 20km for shopping and 45km to work.
Adding 20 km to leave a child at the day care.
And I might be older than you…

But thanks, it compiles! Now I just need to build something an put it in a box! :smiley:

If you go with that, add optimistic: true to the template numbers.

Did that, otherwise it wouldn’t compile.
Now I just find the box with 8266’s.
I have a box of 32’s but I think it is bit of overkill…
On the other hand I have +50 of them, got a good price some years ago!