ESPHome automated plant waterer

ESP32 Plant waterer, (ESPHome managed device with Home Assistant automation)

This is a simple low-cost automated plant watering system, designed to work with Home Assistant based on ESP32 configuration and Over-The-Air (OTA) updates and management from the ESPHome plugin.

The setup uses MQTT protocol to publish sensor data allowing Home Assistant to monitor and trigger watering automations based on automation patterns described in this setup.

The setup includes the following instructions and (working) code;

  • ESPHome code that needs to be flashed onto your ESP32 device
  • Home Assistant Dashboard YAML
  • Home Assistant watering automation YAML
  • historical_stat sensor YAML (acts as failsafe for watering automation)
  • Home Assistant Error & Alerting automation YAML

The project and code is built around low cost M Stack Atom Lite, a low cost minature ESP32-pico based board. I originally tested this with smaller ESP-32 pico based boards, however most of these do not have embedded USB ports so an additional USB/ TTL convertor is required to initially flash these devices and potentially a separate power regulator board would be required.

The M5 Atom Lite includes USB-C connector, onboard RGB LED, and exposes enough GPIO pins to support this project in a single 24mm x 24mm package and available for around $7 USD at the time of writing.

At the time of writing M5Stack also have a nicely packaged watering addon retailing at arround $8 USD, which combines a capacitive water sensor (capacitive sensors have a longer lifespan than the cheaper conductive sensors out there) and low powered water pump in a single unit which is designed to plug straight into the M5 range via a Grove connection which makes the hardware easy to assemble.

The M5 Atom Lite can provide enough power to run the water pump, (only tested when plugged into use power).

Bill of materials

  • M5Stack Atom Lite (SKU:C008)
  • Watering Unit with Moisture Sensor and Pump (SKU: U101)
  • 1 x empty water bottle/ container
  • 1 x USB power adaptor

Hardware

Setup is pretty easy – as the M5 Atom Lite and the watering unit both use a compatible grove connector (cable is provided in the watering kit).

Home Assistant Dashboard configuration

ESP32 setup

The easiest way to set this up is to set up a new device in ESPHome and paste the YAML code and run the installation process.

This guide assumes you are familiar with ESPHome, and have installed the MQTT broker service in Home Assistant.

You need to add the “historical_stats” code to Home Assistant “configuration.yaml”, and restart Home Assistant, this sensor monitors the number of times watering automations have run in the last 4 hours, and is used to prevent the automation getting in a loop and overwatering. Also as this project does not have a water level sensor in the resevoir this is also used to raise alerts that the water reservoir has run out or the water pipe or is not spraying water into the plant pot. (this last one could save a whole container of water being fed to your carpet if things go wrong!).

Once complete you should see the device show up in MQTT

The example folder has example YAML for the following;

(working) example dashboard, automation, alerting YAML available in the GitHub link at the top of this page.

6 Likes

You might find this useful. I’ve been working on evaporation rate of water from soil. I have a WeatherFlow Tempest Weather station and all data is local. I currently have only the daily rate of evaporation in mm/day based on a snapshot; ideally I would store that data and add it together and then take into rain accumulation to determine if watering is needed.
This is all in Java-script running in Node-Red at the moment. Let me know if you think this might be helpful to you.

// Inputs for this script are in Imperial, then converted to metric
temp = (msg.temperature - 32) * 5/9 // F to C
rh = msg.humidity
wind = (msg.wind_speed * 0.44704) // mph to m/s
//rain = (msg.rain_today + msg.rain_yesterday) * 25.4 // inches to mm

// Use Hargreaves method to calculate evapotranspiration rate in mm/day
a = 0.0023 * (temp + 17.8)
b1 = temp + 17.8
b2 = rh/3
b3 = Math.abs(b1 - b2)
b = Math.sqrt(b3)
c = (1.6 + 0.01*wind)
evap_rate = a*b*c
evap_rate = Math.round((evap_rate)*1000)/1000
a = Math.round(a*1000)/1000
b = Math.round(b*1000)/1000
b1 = Math.round(b1*1000)/1000
b2 = Math.round(b2*1000)/1000
b3 = Math.round(b3*1000)/1000
c = Math.round(c*1000)/1000

//evap_rate = 0.0023*(temp+17.8)*Math.sqrt((temp+17.8) - (rh/3))*(1.6+0.01*wind);

//msg.payload = "temp=" + temp + " rh=" + rh + " wind=" + wind + " rain=" + rain + " yesterday=" + msg.rain_yesterday + " today=" + msg.rain_today
//msg.payload = "Evaperation Rate = " + evap_rate + "mm/day a=" + a + " b1=" + b1 + " b2="+ b2 + " b3=" + b3 + " b=" + b + " c=" + c
msg.evap = evap_rate
msg.payload = "Evaperation Rate = " + evap_rate + "mm/day"
return msg;

// Plant Watering
evap_rate = msg.evap

// range of 3-5 mm/day is typical for farming to water
if (evap_rate > 5) {
watering = "Water Required";
} else {
watering = "No Watering Needed";
}

msg.payload = watering
return msg;

Do you have any pointers WRT calibration? I’ve implemented this, but the readings are bonkers. Its sitting in moist soil at the moment reading “-93%” moisture value

OK, so waiting a bit helped, presumably thats a feature of some the values in the sensor definition?

Ok, same soil is now reading “-102%” only a few minutes later, with nothing being done to it. :man_shrugging:

This is brilliant. I’ve just received the hardware and will give it a try over the weekend. This could be a great solution to automate my garden plot,

Have you calibrated the sensor? Mine was initially reading 2 % moisture while “sitting idle” in the air and >90 % when in the flower pot.

How this system gets the power it needs? Does the M5 atom lite need to be connected to power outlet via USB? Or how should I do it?