ESPHome Sprinkler controller

Ideally I’d like Time Remaining and Progress % to update once per second but only when a sprinkler is active. I haven’t figured out how to do that yet.

Thanks for all the info and just if someone finds this thread, here is how I solved the challenge regarding the update_interval:

First set the “update_interval” of both sensors to a high number, e.g. 10000s (I haven’t tested “never”)

Then create a “binary_sensor template” in esphome

binary_sensor:
  - platform: template
    name: "${friendly_name} High Speed Update"
    id: high_speed_update
    on_state:
      - lambda: !lambda |-
          // This is to revert back to the default update interval when needed
          static uint32_t default_time_interval = id(time_remaining).get_update_interval();
          static uint32_t default_percent_interval = id(progress_percent).get_update_interval();

          // 1000 = 1 secs = New "high speed" interval
          int update_time_interval = x ? 1000 : default_time_interval;
          int update_percent_interval = x ? 1000 : default_percent_interval;

          id(time_remaining).set_update_interval(update_time_interval);
          id(progress_percent).set_update_interval(update_percent_interval);

          id(time_remaining).call_setup();
          id(progress_percent).call_setup();

You can also set the parameter “internal” to true to hide it from HA. I haven’t done that to easily see that it is working :slight_smile:

Finally, in the “on_turn_on” and on “on_turn_off” actions of the valves switch the binary_sensor:

switch:
  - platform: gpio
    pin: GPIO22
    id: relay01
    restore_mode: RESTORE_DEFAULT OFF
    on_turn_on:
      - binary_sensor.template.publish:
          id: high_speed_update
          state: ON
      - text_sensor.template.publish:
          id: valve_status
          state: "Drip Active"
    on_turn_off:
      - text_sensor.template.publish:
          id: valve_status
          state: "Idle"
      - binary_sensor.template.publish:
          id: high_speed_update
          state: OFF

I found this piece of code in this post: Dynamically change update_interval - #10 by 0x3333 provided by @0x3333

1 Like