ESPHome Sprinkler controller

Progress bar is actually a slider (mushroom number card) to choose runtime between 1-15 mins

Scheduler is also an add on via HACS

I am looking for some help with the ESPHome Sprinkler Component and based on Robert Blackwell’s yaml, modified to include a pump start relay and 4 valves. I’m about 90% to where I want to be with the project, but I am not able to restore the valve run time settings between reboots.

The relay board is a Lilygo ESP32 T Relay 8. T-Relay 5V 8 Channel Relay – LILYGO®

I have default run_durations set in the valve definitions of the controller. I am able to modify the run durations via HA and the updated run times are maintained… until the device reboots (power failure, forced reboot, etc.). Then the default run durations are restored, not the ones used prior to the reboot.

Any thoughts on what I need to do are welcome. Thanks for your help & suggestions!

Can you post your configuration YAML, at least the sprinkler section?

Absolutely! Here is the sprinkler section.

sprinkler:
  - id: $devicename
    main_switch:
      name: "Start/Stop/Resume"
      id: main_switch
    auto_advance_switch: "Lawn Sprinklers Auto Advance"

    pump_start_pump_delay: 3s
    pump_stop_valve_delay: 3s
    valve_overlap: 3s

    valves:
      - valve_switch: $zone_1_name
        enable_switch: Enable $zone_1_name
        run_duration: 4s
        pump_switch_id: pump_valve_id
        valve_switch_id: ${devicename}_1

      - valve_switch: $zone_2_name
        enable_switch: Enable $zone_2_name
        run_duration: 4s
        pump_switch_id: pump_valve_id
        valve_switch_id: ${devicename}_2
        
      - valve_switch: $zone_3_name
        enable_switch: Enable $zone_3_name
        run_duration: 4s
        pump_switch_id: pump_valve_id
        valve_switch_id: ${devicename}_3
        
      - valve_switch: $zone_4_name
        enable_switch: Enable $zone_4_name
        run_duration: 4s
        pump_switch_id: pump_valve_id
        valve_switch_id: ${devicename}_4

and, if it helps, here is a portion of the number section–the other valves are similar, of course.


number:
  - platform: template
    id: $zone_1_valve_id
    name: $zone_1_name
    min_value: 1
    max_value: 60
    step: 1
    unit_of_measurement: $uom
    icon: "mdi:timer-outline"
    mode: box # Defines how the number should be displayed in the UI
    lambda: "return id($devicename).valve_run_duration(0);"
    set_action:
      - sprinkler.set_valve_run_duration:
          id: $devicename
          valve_number: 0
          run_duration: !lambda 'return x;'

If there’s anything else, please let me know . And thank you in advance for your help!!!

uom is defined to be Min

It appears that you started from an ‘old’ example configuration, which required separate number components to achieve the result. The current version of the sprinkler component has direct support for number components, and I’ve posted an example here.

Using the new features will greatly simplify your configuration and solve the ‘restoration on reboot’ problems.

1 Like

Thanks, I was not aware of the changes. I will study your post & give it a shot. Is your March 1 post sufficient or should I go from your .txt file on March 4?

Either one should be informative; they are fairly close to what I run in production.

Thanks, again! I shall dive in.

I followed your posts and things are working much better now! Changes are saved as expected & kept through reboots & power cycling. Thank you!

There is one “interesting” issue I’m having. It may be a result of setting pump_start_delay, pump_stop_valve_delay, and valve_overlap times (all 3 seconds).

When the controller progress percentage is initially reported for each valve, the percentage reported is 71582788% until the overlapping valve is turned off. It also occurs when first valve–which opens prior to the pump starting, until the pump_start_delay expires. Perhaps an overflow in the value because the time(s) are added together?

The yaml for computing the percentage complete is below.

  - platform: template
    id: progress_percent
    name: $upper_devicename Progress %
    update_interval: $sensor_update_frequency
    icon: "mdi:progress-clock"

    lambda: !lambda |-
      auto ctrl = id($devicename) ;
      auto active = ctrl->active_valve();

      if (!active.has_value()) {
        return std::string("--");
      }
      auto time_remaining = ctrl->time_remaining_active_valve();
      if (!time_remaining.has_value()) {
        return std::string("00");
      }
      auto duration_adjusted = ctrl->valve_run_duration_adjusted(active.value());
      auto percent_complete = 100.0 * (duration_adjusted - time_remaining.value()) / duration_adjusted;
      if (percent_complete > 100) {percent_complete=100;}
      return std::to_string((uint32_t)(100.0 * (duration_adjusted - time_remaining.value())) / duration_adjusted) +"%";
    disabled_by_default: false


Never mind–I had a brain fart & meant to return the percent_complete, not the re-computed value. Better now!

Is it possible to include a sensor that is visible in HA that lets you know the state of a pump start relay? I’d like to add it to my sprinkler dashboard, if possible.

The pump’s yaml in the switch section is below and the pump_valve_id is defined in the substitution section.

Thanks!

switch:
  - platform: restart
    name: "Restart $devicename"
   
#
#   Pump Start Relay
#
  - platform: gpio
    name: Relay 0
    restore_mode: RESTORE_DEFAULT_OFF
    id: pump_valve_id
    on_turn_on:
      - binary_sensor.template.publish:
          id: lawn_high_speed_update
          state: ON
      - binary_sensor.template.publish:
          id: garden_high_speed_update
          state: ON
    on_turn_off:
      - delay: 3500ms  #  Delay for valve stop delay plus a little
      - binary_sensor.template.publish:
          id: lawn_high_speed_update
          state: OFF
      - binary_sensor.template.publish:
          id: garden_high_speed_update
          state: OFF
    pin: GPIO33
    internal: true
1 Like

You shouldn’t run irrigation in the evening FYI. Leaving you lawn wet overnight is a recipe for fungus and disease issues. If you absolutely need to do it twice a day, you should do it early enough that it has time to dry out before it gets dark.