I’ve been fairly successful in writing code to control four irrigation control valves. From within HA I’m able to control a lawn sprinkler and initiate automatic advance on three garden sprinklers. Sliders to adjust the time multiplier are present in HA. What I cannot figure out is how to get the “on duration” to show up in HA as an adjustable field. My code is below. Would you mind having a look and advising how it must be changed to accomplish what I’m after?
esphome:
name: irrigation-ctrl-south
platform: esp8266
board: d1_mini
comment: Four Valve Irrigation Control - South Side
project:
name: "Robert.Four Valve Irrigation Control - South_Side"
version: "1.0.0"
# WiFi connection, replace these with values for your WiFi.
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable logging
logger:
# Enable over-the-air updates.
ota:
password: !secret ota_password
# Enable Web server.
web_server:
port: 80
# Sync time with Home Assistant.
time:
- platform: homeassistant
id: homeassistant_time
# Text sensors with general information.
text_sensor:
# Expose ESPHome version as sensor.
- platform: version
name: irrigation_south ESPHome Version
# Expose WiFi information as sensors.
- platform: wifi_info
ip_address:
name: irrigation_ctrl_south IP
ssid:
name: irrigation_ctrl_south SSID
bssid:
name: irrigation_ctrl_south BSSID
# Enable On-Board Status LED.
status_led:
pin:
# Pin D4
number: GPIO2
inverted: true
sensor:
# Uptime sensor.
- platform: uptime
name: irrigation_ctrl_south Uptime
# WiFi Signal sensor.
- platform: wifi_signal
name: irrigation_ctrl_south WiFi Signal
update_interval: 60s
# Enable Home Assistant API - Lawn Sprinklers
api:
encryption:
key: "NrqRy0rxGHnQKpRlierCyVlUaN6Nhi8tqy3FI29ODb0="
services:
- service: set_multiplier
variables:
multiplier: float
then:
- sprinkler.set_multiplier:
id: garden_sprinkler_ctrl
multiplier: !lambda 'return multiplier;'
- service: start_full_cycle
then:
- sprinkler.start_full_cycle: garden_sprinkler_ctrl
- service: start_single_valve
variables:
valve: int
then:
- sprinkler.start_single_valve:
id: garden_sprinkler_ctrl
valve_number: !lambda 'return valve;'
- service: next_valve
then:
- sprinkler.next_valve: garden_sprinkler_ctrl
- service: previous_valve
then:
- sprinkler.previous_valve: garden_sprinkler_ctrl
- service: shutdown
then:
- sprinkler.shutdown: garden_sprinkler_ctrl
# Set multiplier via number - Garden Sprinklers
number:
- platform: template
id: lawn_sprinkler_ctrl_multiplier
name: "Lawn Sprinkler Controller Multiplier"
min_value: 0.1
max_value: 10.0
step: 0.1
lambda: "return id(lawn_sprinkler_ctrl).multiplier();"
set_action:
- sprinkler.set_multiplier:
id: lawn_sprinkler_ctrl
multiplier: !lambda 'return x;'
- platform: template
id: garden_sprinkler_ctrl_multiplier
name: "Garden Sprinkler Controller Multiplier"
min_value: 0.1
max_value: 10.0
step: 0.1
lambda: "return id(garden_sprinkler_ctrl).multiplier();"
set_action:
- sprinkler.set_multiplier:
id: garden_sprinkler_ctrl
multiplier: !lambda 'return x;'
sprinkler:
- id: lawn_sprinkler_ctrl
valves:
- valve_switch: "Front Lawn"
run_duration: 20s
valve_switch_id: lawn_sprinkler_valve_sw0
- id: garden_sprinkler_ctrl
main_switch: "Garden Sprinklers"
auto_advance_switch: "Garden Sprinklers Auto Advance"
valve_open_delay: 5s
valves:
- valve_switch: "Front Garden"
enable_switch: "Enable Front Garden"
run_duration: 20s
valve_switch_id: garden_sprinkler_valve_sw0
- valve_switch: "South Garden"
enable_switch: "Enable South Garden"
run_duration: 20s
valve_switch_id: garden_sprinkler_valve_sw1
- valve_switch: "Rear Garden"
enable_switch: "Enable Rear Garden"
run_duration: 20s
valve_switch_id: garden_sprinkler_valve_sw2
switch:
# Exposed switches.
# Switch to restart the irrigation_ctrl_south ESP8286.
- platform: restart
name: "irrigation_ctrl_south Restart"
# Hidden switches.
# Switch to control sprinkler valve relays
- platform: gpio
name: Relay Board Pin IN1
internal: true # Prevents GPIO switch NAME from showing up in Home Assistant
id: lawn_sprinkler_valve_sw0
pin: 12 # D6
- platform: gpio
name: Relay Board Pin IN2
internal: true # Prevents GPIO switch NAME from showing up in Home Assistant
id: garden_sprinkler_valve_sw0
pin: 13 # D7
- platform: gpio
name: Relay Board Pin IN3
internal: true # Prevents GPIO switch NAME from showing up in Home Assistant
id: garden_sprinkler_valve_sw1
pin: 14 # D5
- platform: gpio
name: Relay Board Pin IN4
internal: true # Prevents GPIO switch NAME from showing up in Home Assistant
id: garden_sprinkler_valve_sw2
pin: 15 # D8
Hi @rcblackwell - good to see you here!
I had the same question. @kbx81 helped me out with his example config including a Nextion Display - what is absolutely amazing!
The relevant part is to create a number for each duration of the valves. Here is a part of my config. You can find the complete code I am playing with here.
Hi @SmartLiving.Rocks , Thank you for sharing your code and that of @kbx81. I think the code snippet provide will help me create what’s missing from my code; adjustable run_duration.
I don’t know how to display time remaining or total time. These would be great additions to my own program. If i figure out how to add this as a feature, I’ll let you know.
I have an example of how you’d get the time remaining here. I have this in an included header file, but you can use this in a display lambda, etc. just the same. It is also possible to get the total run duration for any given zone using the valve_run_duration() or valve_run_duration_adjusted() functions.
Can you give us an example in a display yaml ?
I tried figuring out how to add this to my LCD display but failed during compile, I suspect I don’t understand how to get at the value from an internal register in ESPhome (error reports that ‘valve_run_duration_adjusted’ was not declared in this scope). The code for displaying the value of Zone 1 state does work.
Here is what I tried.
# 16x2 LCD config
display:
- platform: lcd_pcf8574
dimensions: 16x2
address: 0x27
lambda: |-
// Print the zone switch status of valve x
it.printf(0, 0, "Zone1: %s", id(zone_valve_sw1).state ? "ON" : "OFF");
//Print the time duration for valve x
it.printf(0, 1, "Duration: %3f", id(valve_run_duration_adjusted(1)).state);
Yes, of course, happy to.
See examples I have here
The key part that I think you are looking for is id(sprinkler_ctrlr).valve_run_duration_adjusted(0). You’re on the right track, just your syntax/parameters were a little off.
Having some odd issues with first zone running the default 900s runtime regardless of what I set in the HA frontend. Will check all my syntax.
Edit: Found my issue with first zone not running the right runtime. I had not taken into account that my first zone (Zone 1) is actually internally referenced as valve 0. So in lambdas I need to use 0-7 instead of 1-8.
This seems to do it, but displays whole minutes only in HA. I’d like to have this displayed as minute with one decimal (easier to see the last minute that way), if anyone knows how to do that let me know
- platform: template
name: Time Remaining
id: time_remaining
unit_of_measurement: Min
icon: mdi:progress-clock
accuracy_decimals: 2
lambda: |-
return id($devicename).time_remaining().value_or(0)/60;
update_interval: 5s
I’d like to see the display updated every second, with minutes and seconds displayed. So far I’ve been unable to figure that one out.
I did notice that setting the update_interval to 1s causes the template to spew out data every second. Should be okay when a sprinkler is running but I don’t think constantly updating HA when no sprinkler is running is appropriate. Any ideas as to how this can be configured to send updates only when a valve is open?
Hey, thanks for asking. But I am not sure how I can help you. My Lovelace is just standard buttons - nothing special. I get some inspiration here:
Lately I was thinking to do a Kickstarter or any other fundraising for a professional sprinkler control including pump and cistern control, water level sensor, freshwater pump (to fill up the cistern before sprinkler starts) and of curse some BT flower Sensors to kick right into the Bluetooth trend:
The two buttons are a brainstorming result. I have figured out that if you need a “Single” valve you just have to trigger/toggle the valve and it runs for the set time and also opens the master valve. So actually it i s obsolete.
Intensive+
I worked together with a professional gardening company and we made a nice garden with different plant for a customer. Here I have learned that the “young plants” need more water in the seeding phases on as well as more often.
So, my idea is to make different “programs” for the different phases of a plant/ flower. A washing machine has programs for different types of clothe that mixes soap, powder, softener and impregnate liquid in the right amount at the correct temperature. And so the watering system should also have different programs that coordinate water, ph regulator and nutrition for the different phases. Now I have a dropdown helper with the following options:
Sprout
Seedling
Vegetative
Budding
Flowering
Ripening
Combine it with flower sensor
Of curse, we all want to have a fully automated system, therefore we need some data of the flower e.g. using a sensor like this one GitHub - rbaron/b-parasite: 🌱💧 A Bluetooth Low Energy (BLE) soil moisture sensor. - also including weather forecast and
With that data, the above-mentioned “programs” will be adjusted accordingly +/- water/nutrition/ph-regulator etc.
Where are the plants
Nowadays, it becomes more and more popular to grow your own food, herbs, etc. indoor. That would also mean that you can combine the different programs adjusting the lights (more blue, more green etc.)
For those of you who are typically used to minutes for irrigation systems as opposed to seconds, here are some sample equivalent configurations for relevant esphome sprinkler entries.