☔ DIY Zigbee rain gauge

Rain has never been more exiting

Last updated: July 2024
Sensor has been running on the same battery since December 2020

Today I want to share with you how I made a wireless battery powered Zigbee rain gauge for $20. It measures the rainfall amount in mm or inches. Furthermore, the battery life is +2 years!

The raingauge with a lighter and a pen for size comparison

Daily and monthly measured rainfall in mm

Modify the Rain Gauge

What you need:

This is the rain gauge from the outside. Now lets take it apart by taking the top case off.

The gauge works with a reed switch, that closes and opens again when the bucket tips. You can pull out the board and see the sensor.

To make it wireless, we have to cut the wire! I cut it about this length. Then carefully strip the wires till you see some copper.

The next step is to solder the wires to the Aqara door sensor.
Normally there is a reed sensor there but I desoldered it for another project. I would suggest you desolder it, so it can not interfere with the magnet of the rain gauge.

If that’s done, it looks like this. You can now test it. If you didn’t yet, pair the sensor to ZHA, Z2M, Deconz etc.

Then you just insert the Aqara sensor in the casing. Notice the wire goes over the casing. I couldn’t get it in there, so I marked the spot where the wire goes over the frame, and made a cutout. This way I can still get the top back on.


Calculate rainfall per gauge tip

So how do we calculate the rainfall? I found a useful amazon review from ‘packetrat’ for this rain gauge here. He explains how to calibrate the sensor.

You do need to calibrate it by measuring the surface collection area, and putting in a controlled amount of water from a syringe, etc. while counting the pulses. I measured mine at 5cm x 11cm, and 6 pulses per 10mL => 10/6 = 1.67mL per pulse.

1mm rain = 0.1511cm = 5.5 mL
1" rain = 2.54511cm = 139.70 mL

@ 6 pulses per 10mL => 10/6 = 1.67mL per pulse

pulses / mm = 5.5 / (10/6) = 3.3
pulses / in = 139.7/(10/6) = 83.82

mm / pulse = 0.30303
in / pulse = 0.01193

I also got 6 tips per 10ml so I used 0.30303mm per tip. If you use inches, it’s 0.01193 inch per tip. We can use that in a sensor to calculate the rainfall today, or in a week, or month, etcetera.

I set up two sensors to calculate this. One to count the times the state of the rain gauge was ‘closed’ today:

  - platform: history_stats
    name: Rainsensor flips 
    entity_id: binary_sensor.rainsensor_on_off #The aqara sensor
    state: 'off'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

And one that calculates the daily amount of rainfall

  - sensor:
      - name: Rainfall today
        unit_of_measurement: mm
        state_class: total_increasing
        unique_id: rainfall_today
        state: >-
          {% set count = states('sensor.rainsensor_flips') | int(0) %}
          {% set mm = count * 0.30303 %}
          {% if count >= 0 %}
            {{ mm|round(1, 'floor') }}
          {% endif %}
        # If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
        availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

That’s it! Time to test it out under the tap and see the rainfall sensor increase!


Measure rain of a specific period

You can use the Utility Meter to measure Weekly, Monthly and Yearly rain. More options can be found here.

Weekly, Monthly and Yearly rain in Dutch

    source: sensor.rainfall_today 
    cycle: weekly
    unique_id: rainfall_week
    source: sensor.rainfall_today 
    cycle: monthly
    unique_id: rainfall_month
    source: sensor.rainfall_today 
    cycle: yearly
    unique_id: rainfall_year

Measure rain intensity (mm/h)

During a heavy storm

  - platform: trend
        entity_id: sensor.rainfall_today
        max_samples: 2
  - sensor:
      - name: "Rain intensity"
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: rainfall_per_hour
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if rain_hour >= 0 %}
            {{ rain_hour }}
          {% else %}
            {{ 0 }}
          {% endif %}

Show your numbers in a graph

Visualise the daily rain of a month in a graph with the Apexcharts-card

type: custom:apexcharts-card
graph_span: 30d
  show: true
  title: Rainfall
  show_states: true
  start: day
  offset: '-29d'
  - entity: sensor.rainfall_today
    color: aqua
    type: column
      func: max
      duration: 1d

Bonus: Add rain precipitation forecast to your graph

Integrate your local weather forecast into the graph with the rain gauge!
The code for this is different for each weather service.

Code for Buienalarm (The Netherlands)

Needs the custom component ‘Neerslag app’.

type: custom:apexcharts-card
graph_span: 24h
  show: true
  start: day
  stroke_width: 2
  - entity: sensor.rainfall_today
    name: Rainfall
    color: '#039ae5'
    extend_to: now
  - entity: sensor.neerslag_buienalarm_regen_data
    name: Precip
    extend_to: false
    color: grey
    unit: mm
    data_generator: |
      if (typeof entity.attributes.data.start == 'undefined') {return []}
      let start_date = entity.attributes.data.start * 1000;
      let start_state = Number(hass.states['sensor.rainfall_today'].state);
      return entity.attributes.data.precip.map((precip, index) => {
        if (index != 0) { start_date = start_date + (5 * 60 * 1000) }
        start_state += parseFloat(Math.pow(10, (precip - 109) / 32)) / 12;
        return [start_date, start_state];

Also interesting

If you’re interested, I also made a wireless battery powered chair occupancy sensor this way.

If you got any questions, feel free to ask them!




Just mounted the rain gauge in the garden! Now we just have to wait for the rain :stuck_out_tongue:.


For the calibration to be accurate don’t you need to take into account the surface area of the collection pan on top?

Or is that included somewhere and I missed it?


To be honest I don’t exactly know how the calculations work, but what I do understand is that 5x11=55 and that then relates to the 5.5 in the calculations.

Ah, OK. I did miss it then.

I didn’t realize the 5.5ml was based on that number.

That’s really cool.

Just ordered the rain gauge. Now the waiting start… I just hope that I remember what I wanted to do with it when I receive the package :crazy_face: #chinesewebshopissues


Lol, relatable. It took about 14 days for me to arrive with aliexpress standard shipping to The Netherlands.

10 out 10 bro like your thinking


I would expect most simple rain sensors to do one tip per “point” (0.01" or 0.254mm) of rain. New ones might natively count in metric e.g. 0.25mm, but I can’t see anyone designing/selling a rain sensor that needs harder maths than that.

I’m not trying to be critical of the methods used, but …

If you are only measuring to one significant digit (5, 11, 6) then the answer can’t have more than one significant digit in it, therefore: mm/pulse = 0.3 , in/pulse = 0.01

You could measure the rain collection area more exactly and allow for the rounded corners, and e.g. measure how much syringe water is needed for 100 tips.


Thanks a lot for your reply. I will dive into this and make it more accurate

This is great. I ordered the same one and connected it to my KNX Bus. Just need to install it on the roof :slight_smile:

Amazing! Will Do that :grin: thanks for that diy

1 Like

Cool! I had to google what KNX was but that’s pretty cool! So this KNX is wired through your house and that way you can connect smart devices to it?

1 Like

Yes. It’s a “Cable Bus” System. Very reliable. As we build a new house this was the only option for me :slight_smile:
You need specific KNX components but it’s an open industry standard.
You get everything from Switches to Smokedetectors. It’s not cheap but as said it’s reliable, exist since over 30 years, has a wide support from all major electrical manufacturers in Europe/Germany and there are a few fancy things available which only exists in the KNX World like this sweet thing which I have in every room :slight_smile:

1 Like

I run the same thing on a knx binary interface. It works nicely since this spring, but it’s accuracy is not so great - always ~ 10% off of a classical measuring cup.
Doesn’t rain that often here so not much chances to calibrate. Did change mm/pulse about 6 times. Landed at 0,275 now.

Thanks for your reply. I’m still waiting for rain, lol. I might print a larger funnel for it later, to increase the resolution. Like this

Had the first real test this night. I have to say, it’s quite accurate with Buienradar (Dutch weather station).


Had quite some rain today, it was really put to the test! Still works great.

1 Like

This is just what I was looking for. I’ve had one of these kicking around in my garage unused for years, it had a standalone battery powered LCD display but had no idea how the gauge part worked and so no idea that it could be integrated in HA.

1 Like