Why the rain sensor is the part that saves the most water
A well-tuned controller can irrigate every three days, same as last month, but it doesn’t know that yesterday or the day before there was a downpour of 40 litres per square metre. That’s the difference between irrigation that works and irrigation that adapts: the rain sensor is the only component that says “there’s no need to water today” without anyone telling it to.
In Spain, where part of the territory gets most of its rain in a few episodes a year, that decision is worth more than any fine-tuning of the controller.
Three ways to measure rain
| Type | How it measures | Advantage | Drawback |
|---|---|---|---|
| Tipping bucket rain gauge | A bucket that fills up and tips over | Robust and cheap | Needs a level spot and open space |
| Capacitive probe | Capacitance change with water on the board | No moving parts | Costs more and gets dirty |
| Built-in device sensor | The device itself measures rain | No installation | Depends on the model |
The tipping bucket is the classic: a container with a funnel that, on reaching a set amount of water, tips and empties a small chamber. Each tip is a pulse. If it also has a reed switch, it tells you whether it’s raining right now or whether it only rained a while ago.
Where to place it, which is half the installation
The most common mistake is putting the rain gauge next to the board or in a corner. If the sensor is under an eave, a plant or a tree, it will measure less than what falls and irrigation will trigger even when it isn’t needed. If it’s in direct sun, water evaporates and it also measures badly.
The right position is an open spot with no obstructions within 45 degrees all around, and as close as possible to the garden you’re irrigating. The electronic board, on the other hand, should go in the shade and protected from rain: that’s the part that can’t get wet.
How to read a rain gauge with the ESP32
If the rain gauge has a pulse output, you connect the contact to a digital input pin on the ESP32 and count the pulses. Each tip is a known volume of water, and from there you can calculate millimetres with a simple proportion. The pulse_counter component does that counting for you:
sensor:
- platform: pulse_counter
pin: GPIO27
name: "Pluviómetro (pulsos)"
update_interval: 60s
filters:
- multiply: 0.2 # 1 pulso = 0,2 mm en el pluviómetro del ejemplo
With a single pin you don’t need to wire anything else: the “is it raining now”
state is derived from the sensor itself with a
sliding window moving average filter
or with a lambda that compares the value with a threshold, not with a second
contact.
If the rain gauge has an analogue output, the cable goes to an ADC on the ESP32 and you measure the voltage; the ESPHome ADC explains the configuration:
sensor:
- platform: adc
pin: GPIO34
name: "Pluviómetro (señal cruda)"
update_interval: 60s
filters:
- calibrate_linear:
slope: -0.14
offset: 100
And if you buy a sealed rain sensor, such as the Hydreon, there’s a component made for it and you don’t have to calibrate anything: hydreon_rgxx.
The rule that decides: recent rain, not rain right now
A well-placed rain gauge activates the contact while it’s raining, but water keeps falling afterwards and for a while longer. If your rule is “don’t irrigate while the sensor is active”, you’ll overwater. The rule that works is time-based: if it has rained in the last three or four hours, skip irrigation.
The margin is adjusted to the climate. With fine, long rain, three hours may be too few; with a brief downpour, three hours is plenty. The way to find your number is to look at the log after a rain event.
How long the water lasts: deep sleep
A rain gauge in the sun, with the board next to it, is the worst possible place for a battery. If you use batteries or a small pack, ESPHome can sleep between readings and wake up every few minutes to check the sensor. The deep_sleep component is designed for that, and it’s the difference between a sensor that lasts for months and one that runs out of batteries in a month. Always configure it with the right wake-up time, because each ESP32 boot takes a few seconds.
Integrating it into Home Assistant
With the ESPHome node already on the network, Home Assistant can create an automation that switches irrigation off when the sensor is active. The ESPHome integration in Home Assistant explains how the entities appear, and the detail of the decision logic is in the guide to automating irrigation.
Mistakes that ruin a rain sensor
- Putting it under an eave. It measures less than reality and irrigation isn’t cut off.
- Confusing “sensor active” with “recent rain”. Without the time margin, you irrigate after the shower.
- Not cleaning it. Leaves, cobwebs and sand build up in the funnel and distort the measurement.
- Leaving the board outdoors. An unprotected ESP32 doesn’t survive even one season.
- Having no manual fallback. If the sensor fails, irrigation must be able to continue on its schedule. Never leave a plant in the hands of a single sensor.
- Trusting historical rainfall. Looking at the station’s rainfall figure is useful, but the soil sensor is the one that knows whether that rain reached the root.
Maintenance
Check the funnel and the rain gauge filter every two months, check that the bucket tips with a little water and that the switch changes state. If you use batteries, change them before they run out and remember that cold drains them faster. All of this is cheap compared with a soaked plant.
Sources and next step
To see how a smart home device measures and exposes rainfall you can consult Espressif’s documentation for the Matter rain sensor, which describes the event type. For the irrigation logic, Home Assistant documents automations and ESPHome the deep sleep component that makes a battery node last.
External sources
- Espressif: Matter rain sensor — how the rain event is defined and exposed on a smart home device.
- ESPHome: deep_sleep component — how to configure periodic wake-ups and their effect on consumption.
- ESPHome: pulse_counter sensor — pulse counting from a tipping bucket rain gauge and conversion to millimetres.
- ESPHome: adc sensor — reading an analogue rain gauge and calibrating with
calibrate_linear. - ESPHome: hydreon_rgxx component — direct integration of already calibrated Hydreon rain sensors.