HA + ESPhome hybrid irrigation system

Hi,

Let me share my recent hobby project, how to modernized my home.

Short project intro: The aim is to get smart a controlled lawn sprinkler system, with super optimal water usage. So far I spent about 75 USD and used lot of existing resources which are not counted to the costs.

If I would happy without having soil moisture introduced to the decision then project can stand for about 20 USD only (10 USD for the relay board + the price of the installation box (let’s say another 10 USD)). Depending you have some jumpers, leftover PCB pins to solder in, soldering station, jumpers, etc. Also presuming you have an up and running Home Assistant (HA) on your home network.

If I would replace my non connected controller with vendor’s off the box Wi-Fi enabled controller solution, it would cost me around like 220 USD plus possible subscription fee for cloud based services.

Project Status:

Prototype is ready on the desk, with some successful dry run tests, but need a few more testing for safety (ie: never leave open any valves and starts watering every case when it needs)

(Budgeting note: I will still need to chose and buy a proper plastic mounting house for the new controller PCB board and probably an external Wi-Fi antenna. In case of the Wi-Fi signal would too weak at the installation place.)

This is more likely a high level project documentation and has no examples. I will have the next document which is a kind of step-by-step howto for the project.

Detailed project document

Background intro and my goals with the project: I have an old Hunter 6ch controller for 10 years or so which is still works perfectly. I even use 4 channels only, given I have 4 valves to control lawn watering in my yard.

As I said the Hunter controller is working well, the only issue I almost always forgot to go to the small wooden house for tools in the back of the yard (where the controller is installed) to adapt the irrigation volume to the current weather conditions. It’s even have a rain sensor (Hunter Rain Click) connected which can disable the irrigation while the felt discs are wet inside. However since years it unfortunately looks almost useless. Probably I could install the rain sensor to a non optimal location only, where rain sensor gets direct sunshine and the felt discs inside drying too fast.

A few months ago I have started to get friendly with Home Assistant, so I have got some basic monitoring experience, and it is the time to start to control something.

Setting the goals for the smart irrigation control :

  • Give enough water to my lawn (let it not to dry neither to be thirsty)
  • Make sure no more water being spent than really needs by lawn

What to measure for control the volume of water:

  • Soil moisture
  • Highest temperature for the past days (since last irrigation)
  • Amount of rain fallen (since last irrigation)
  • Predicted precipitation (how much rain we can expect in the next 7 days)
  • Chance of prediction in percentage (We can correlate it to the expected rain volume)

Let’s take them in order:

Moisture Sensor (Fineoffset-WH51):

The lawn field has been split to 3 relative same size of areas. I bought 3 moisture sensor from AliExpress to determine the real moisture conditions in each area. (Misol Wireless Moisture sensor - https://www.aliexpress.com/item/33057534325.html)

These moisture sensors are using ISM 433 MHz band to send the measured values. Receiver could be an WH0291 weather station, but it nothing else like a basic LCD clock. However thanks to the FOSS community here is an another way to get the moisture values which perfectly fits to my goal. I also have a Raspberry Pi 3 installed next to the old Hunter controller. This is running ADS-B receiver Docker container powered by an RTL-2832 SDR USB stick. As this RPi still have a free USB port so, I could order one more RTL-2832 SDR stick (https://www.aliexpress.com/item/32900553328.html) for running the rtl_433 in a docker container. This app can decode a lot of gadgets communicating over 433 MHz ISM band. Thankfully it perfectly decodes the moisture sensors and sends the records to the MQTT running along with HA. My HA is running as a qemu VM in my TrueNAS, so it has the add-on feature. There is an addon called “rtl_433 MQTT Auto Discovery” which creates and updates entities from MQTT. So I have moisture sensors in my HA.

I have stopped at this point, I need to research research what the lawn moisture needs. So this is something yet to add to the irrigation control decision.

Outside Temperature and its peak measurement:

Sensor1: BME280 I have an Air quality sensor for sensor.community, mounted also along to the Rasberry Pi and the Hunter controller, just to the outside. This sensor has a BME280 for Temperature, Humidity and Air Pressure. HA also has an integration for Sensor.Community, so I have reading back my sensor values from Sensor.Community’s cloud.

Sensor2: gas heater’s NTC My gas heater/boiler (Saunier Duval Ecosy 28) has an external NTC sensor for environment tracking. So the boiler can chose the optimum power for the burner, depends on conditions (outside temperature, forward and return water’s temperature and the value set on the thermostat). Saunier Duval and others form Vailant group use something called E-BUS (energie bus) for communicating between their devices (haters, thermostats, etc.). A few enthusiastic folks has created a nice piece of hardware (Welcome to eBUS Adapter {% if site.isold %}3.0{% else %}3.1{% endif %}!) and reverse engineered the E-bus protocol. My ebus adapter is also an esp32 (d1 mini) powered. There is an ebusd container running on my TrueNAS server which is beong feed the messages to the MQTT. HA also has integrations, so I have another temperature source in my HA.

Sensor 3:
OpenWeatherMap. HA has a nice integration for OpenWeatherMap. If you have set the right address for your home during setting up HA, then OpenWeatherMap will provide you a set of weather related value. I was using hourly updates from OpenWeatherMap.

I was decided to split the irrigation controller rules into two parts.

  • A relay board will responsible for:valve controls with safety checks (ie: avoid to leave valves open for any unforeseen reason (power outage, reboot, losing WiFi connectivity between the relay board and HA due to the poor signal, etc))
  • HA is going for run the smart logic to calculate when and how long to spray out the water

Controlling the Valves (ESP12F_Relay_X4): Given the irrigation system itself (pipes, valves, sprinklers) is still so good, I can replace only the controller to get it smart. As I wrote in the intro section, my lawn irrigation system has 4 zones. I have measured the runoff during I built the irrigation system (ie: how much water spraying out in a certain amount of time). You can find water needs given in mm per day (1 mm rain is one liter per square meter), but you can control the valves runtime by time. The runtime to mm is really unique to each systems so it have to test once your irrigation system is deployed.

I have found a pretty cheap ESP12F powered relay board with 4 relays (spent cca $10 including delivery). The relays do have dry contact and they are good to switch 24V AC for longer time periods. The ESP12F also a good choice for the safety. Given it is also a micro controller so some small intelligence you can built into it.

Lessons learned: even it was not on the data sheet, you need to solder in the pins to the PCB. A relay can be controlled by ESP12F only if there is a jumper installed between relay pin and GPIO pin of ESP12F. Also need pins for binary FW upload and put the ESP to FW programming mode.

There are some basic examples for my relay board (ESP12F_Relay_X4) to use it for ESPHome. ESPHome also has a nice sprinkler controller module (Sprinkler Controller — ESPHome) Which pretty much does everything I want (it could do even more). Sprinkler control modules can have overlap or even pause between zones, it could turn on and off a master pump, if you need it. It also makes sure only one zone is running at a time, it can feed back the remaining time to HA and a lot. It has by default some safety controls protect you against leaving valves open forever.

Smart logic running on HA Inspired by Ed, @smarthomejunkie video tutorial - YouTube I could build up the smart logic in HA which calculates on which morning (early hours around sunrise) should run the system, and how long.

I had to create in HA

  • Helpers
  • Scripts
  • Automations
  • Sensors (Templates)
  • Dashboards

Helpers:

  • Last watering day
  • Maximum temperature (since last watering day)
  • Total rain fallen (since last watering day)
  • Watering duration (I plan to create one for each zones)

Scripts

  • Sprinkler reset Helper values
    • Total Rain Fallen and Watering duration to zero
    • Last watering day to the current timestamp
    • Maximum Temperature to the current temperature
  • Water the Garden
    • Feeds the runtime from the logic to the relay board
    • Effectively turns on the relay board’s full cycle switch
    • Wait until relay board full cycle switch turns off (ie: all watering activities have finished for today by the relay board)
    • Calls the Sprinkler reset Helper script to re-initialize the observation cycle.

Automations

  • Add current to the Total Rain Fallen (triggered if OpenWeatherMap Rain changes)
  • Check Maximum Temperature if Temperature changes (triggered if temperature sensor has changing its value and records the new value for maximum if the maximum increasing. Maximum value is relative to last watering day.)
  • Check if garden should be watered (the main logic, calculates the actual runtime, set it to the ESP Relay board’s controller firmware and kick the irrigation run. Then wait irrigation to be completed and reset the helpers to start a new observing period.)

Sensors (templates)

  • Sprinkler Total Expected Precipitation (predicted 7 days rain volume; corrected by precipitation’s probability the from OpenWeatherMap’s prediction)
  • Sprinkler Total Rain Fallen Plus Expected (adds the predicted rain volume to the stored already fallen rain volume)
  • Sprinkler Days since Last Watering Day (Difference in days between the last watering cycle and current timestamp)
  • Sprinkler Current Temperature Is Higher (Boolean: true if current temperature is higher than the stored maximum and maximum needs to be updated with the current temperature.)

Dashboards

  • ESP Sprinkler Controller
  • HA Helpers, automation, scripts.

Summary: Project Status:

  • Last night I have completed with the full basic functional tests. So far everything is working as expected.
  • I spent today for create this document while I have fresh memories from everything. :smile:
  • Switched to local measured temperature from OpenWeatherMap provided temperature.
  • Slightly modified dashboards to include local measured temperatures and soil moisture values
  • The relay board does the basic functions as expected, still want to test the various use cases, to make sure there is no gap in my controller logic and everything is fool safe. (I would like to avoid any interesting conversation with my wife if my hobby project would leave open the tap for any reason.)
  • Once dry tests are done I need to get a plastic box and probably an external Wi-Fi antenna (if the Wi-Fi signal would be too weak and Wi-Fi link of ESP32 Relay Board would unreliable.)

Further Improvements:

  • Find some reliable agricultural study which sets up watering plan for lawn, depend on soil moisture values. (Or at least including soil moisture values).
  • Add the soil moisture to the runtime calculation logic.
  • Watering script can have an additional check to: Wait for relay board has the API connection ready. (in case of can’t connect in x minutes, send an alert notification and aborts.)

Appendix A: Cost analysis

Bill of Materials used for the project:

Item Cost
1 x ESP12F 4Ch relay board 10 USD
1 x RTL2832U & R820T2 DVB-T SDR tuner stick + antenna 14 USD
3 x wireless soil moisture sensor (Ecowitt WH51 clone) 50 USD
Plastic mounting case for relay board (yet to chose and buy) ?? USD
Total 74 USD

Re-Used parts from household (I have had them around, but for a green field project it might need to invest them):

Item Cost
Raspberry Pi 3B+ + original Raspberry PSU
(for running 433 MHz receiver to read the moisture sensors) 72 USD (today price)
3 x USB extension cable (20 cm) 3-5 USD (today price)
3 x AA size Alkaline (high quality) battery for moisture sensors 6 USD (2 USD per each)
1x eBUS adapter 35-40 USD years ago
Total 117-125 USD
  • My Raspberry Pi runs from an M2 SSD living in an external M2 SSD to USB3 case, which is wider and it would blocks the neighbor USB ports on RPi
  • TV Tuner SDR dongles also have wider cases

Note for the moisture sensors:

  • They sold as water proof (irrigation, rain proof, if their installation is correct.)
  • We need temporary remove the sensors before such kind of activities:
    • Lawn mowing
    • Raking
    • Aerating
    • Let children play on the grass
  • I tried to chose a place for the moisture sensor which is bit away (inside) from the lawn edges but it is away from any possible crossing paths, in other words where is less chance to someone would unintentionally kick the sensor or step on the top and breaks it.
3 Likes

Hi, did you end up finishing the project? Would love to test it out