DIY Connected Rain Gauge

Tuesday, Apr 8, 2025 | 6 minute read | Updated at Tuesday, Apr 8, 2025

Squwal
DIY Connected Rain Gauge

Building a low-cost rain gauge connected to Home Assistant. A project I’ve had in place since 2021.

Introduction

With the goal of optimizing my garden watering, I wanted to know the amount of rainfall on my garden. Indeed, weather reports are not necessarily accurate depending on your distance from the sensors.

I looked at what was available commercially and found the Netatmo Weather Station. It seemed perfect as it includes all the sensors one could want: an indoor temperature sensor, an outdoor one, a rain gauge, and even an anemometer. But this station is particularly expensive (around €200 for the base station, €80 for the rain gauge extension, €100 for the anemometer module).

I therefore decided to turn to less expensive solutions, and after several searches, I came across this ingenious solution. There are several versions of this tutorial online, some involving soldering. Here I present the simple solution that I implemented at home.

Materials

That’s all you need to complete this project ;-)

Assembly

First, remove the rain gauge cover by pressing the two tabs at the base.

Tabs to press to remove the rain gauge cover

Tabs to press to remove the rain gauge cover

Next, unclip the cover containing the magnetic sensor in the plastic column and remove the small board. You can cut the wire to remove the assembly, as we won’t be reusing any of it.

Cover to open

Cover to open

Now for the door sensor. Disassemble the door sensor by starting with removing the cover. There is a notch to access the battery.

Notch of the Aqara door sensor

Notch of the Aqara door sensor

Using a screwdriver, remove the plastic cover and retrieve the sensor board. You can also put the battery back in place.
Sensor cover

Sensor cover

I recommend pairing the door sensor with Home Assistant before the next step, whether through Zigbee2Mqtt or ZHA. This will allow you to ensure that the rain gauge works correctly before closing everything up. Now you need to position the door sensor board in the plastic column of the rain gauge. Place the board vertically, so that the Hall effect sensor (circled in red in the image) is facing the top of the pivoting part of the rain gauge.

The Hall effect sensor of the door sensor

The Hall effect sensor of the door sensor

Alignment of the board with the tipping bucket

Alignment of the board with the tipping bucket

Finally, to keep everything in position, I suggest simply stuffing the cavity with cardboard. Moisture is not supposed to enter this part. Close the column cover, then put the rain gauge cover back on.

Home Assistant

If you use Zigbee2mqtt, I recommend checking the “Retain” box in the parameters of the newly added Aqara sensor. Take the opportunity to rename your sensor, for example to “rain_gauge”.

Creating Virtual Entities

We will create a counter that will increment each time the rain gauge’s tipping bucket activates the door sensor. Go to the Home Assistant settings, then “Devices & Services” and finally to the “Helpers” tab.

Create a counter type entry, and name it for example “rain_gauge_tips”.

Creating a counter

Creating a counter

Creating Automations

For the counter to increment, you need to create an automation that will activate with each tip of the rain gauge. In the Home Assistant settings, go to the “Automations & Scenes” tab, then to the “Automations” tab. Create a new automation from scratch. In the “When” block, add a trigger, choose “Entity”, then “State”. Select the “rain_gauge” entity (its name and type should be similar to binary_sensor.rain_gauge). In the “And if” block, don’t add anything. In the “Then do” block, search for “counter” and select “Counter: Increment”. Then click on the “Choose entity” button in the “Targets” line. Select the newly created “rain_gauge_tips” counter entity. Save the automation under a descriptive name, for example “Rain gauge counting”.

Now create a second automation following the same procedure. In the “When” block, add a “Time & Location” trigger, then choose “Time”, and finally set it to midnight.

Triggering at midnight

Triggering at midnight

In the “And if” block, don’t add anything. In the “Then do” block, search for “counter” and select “Counter: Reset”. Click on the “Choose entity” button in the “Targets” line. Always select our “rain_gauge_tips” counter entity. Save the automation under a descriptive name, for example “Rain gauge reset”.

Now we have a rain gauge tip counter that increments with each tip and resets at midnight. But how do we convert this to rainfall amount?

Interpreting Pulses

Let’s do some math (nothing too difficult, I assure you). The collection surface of our rain gauge is 5 cm by 11 cm, giving a total surface area of:

\[S = 5 \text{ cm} \times 11 \text{ cm} = 55 \text{ cm}^2\]

Relationship Between Collection Surface and Water Volume

When it rains 1 mm, it means the water height is 0.1 cm over the entire surface. The volume of water collected is therefore:

\[V = S \times h = 55 \text{ cm}^2 \times 0.1 \text{ cm} = 5.5 \text{ cm}^3 = 5.5 \text{ mL}\]

Thus, 1 mm of rain corresponds to 5.5 mL of water in our collector.

Calibration of Pulses

If we pour 10 mL of water into the collector, we can observe that the sensor will generate 6 pulses, which gives:

\[\frac{10 \text{ mL}}{6 \text{ pulses}} = 1.67 \text{ mL/pulse}\]

Conversion Factors

To convert pulses to rainfall height, we calculate:

\[\text{Pulses per mm} = \frac{5.5 \text{ mL}}{1.67 \text{ mL/pulse}} = 3.3 \text{ pulses/mm}\]

Conversely, to convert pulses to rainfall height:

\[\text{mm per pulse} = \frac{1}{3.3} = 0.30303 \text{ mm/pulse}\]

This conversion factor (0.30303 mm/pulse) is the value we will use in our code to transform the counted pulses into precipitation measurement.

Creating the Sensor

I suggest creating a new entity using the Home Assistant template integration.

In your Home Assistant yaml configuration file, add the following code:

- platform: template
  sensors:
    todays_rainfall:
      friendly_name: Today's Rain
      unit_of_measurement: mm
      value_template: >-
        {% set count = states('counter.rain_gauge_tips') | int %}
        {% set mm_per_pulse = 0.30303 %}
        {% set mm = count * mm_per_pulse %}
        {{ mm|round(1, 'floor') }}        
      availability_template: >
        {% if is_state("counter.rain_gauge_tips", "unavailable") %}
          false
        {% else %}
          true
        {% endif %}        

We now have an entity called sensor.todays_rainfall that contains the value of the amount of rain that has fallen during the day.

Evolution of daily rain and reset at midnight

Evolution of daily rain and reset at midnight

Weekly Display

Here’s the code for a card to display the evolution of the amount of rain that has fallen during the week:

type: custom:mini-graph-card
icon: mdi:weather-rainy
aggregate_func: max
hours_to_show: 168
group_by: date
show:
  graph: bar
entities:
  - entity: sensor.todays_rainfall
    color: aqua
Weekly view of rainfall

Weekly view of rainfall

Note the dependency on the mini-graph-card. Remember to add it to your Home Assistant beforehand.

Conclusion

I hope this tutorial has been useful. I’ve tried to gather here the information I found at the time to offer a simple and economical solution. Feel free to recreate it at your home, and remember to place the rain gauge flat towards a clear area of sky.

© 2025

🌱 Powered by Hugo with theme Dream.

About me

Welcome to Squwal’s blog ! This blog is dedicated to domotique, electronics and embedded software, with a focus on the design and development of sensors. I am an engineer in embedded software, and I share my projects here to keep track of my work and allow others to inspire themselves.

Do not hesitate to ask questions in the comments, by email or by exploring my GitHub for more information! 🚀