Skip to content
Go back

Rain sensor for automatic irrigation systems

Published:  at  05:00 PM

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

TypeHow it measuresAdvantageDrawback
Tipping bucket rain gaugeA bucket that fills up and tips overRobust and cheapNeeds a level spot and open space
Capacitive probeCapacitance change with water on the boardNo moving partsCosts more and gets dirty
Built-in device sensorThe device itself measures rainNo installationDepends 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.

Rain sensor diagram: the rain gauge tips, the ESP32 reads the change, checks whether it has rained and skips irrigation
The sensor doesn't prevent irrigation: it decides whether the irrigation that's due is needed.

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

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

The homeiotguide editorial team

Editorial lead: Néstor Espuch


Suggest changes
Share this article on:

Previous article
DIY weather station to make your irrigation decisions
Next article
Soil moisture sensor: capacitive vs resistive