☔ DIY Zigbee rain gauge

Mine arrived today on the slow boat from China, One month 8 days :roll_eyes:
Installed right next to my other gauge so should be a good test on accuracy.

Awesome diy thanks verry much

2 Likes

Really nice! What’s the name of your weather station?

It’s a Holman, Does the trick but now I get the results even when not at home thanks mate.

1 Like

I did the same with the Aqara door sensor. Works great.

2 Likes

It is also possible to display rainfall pr hour if we measure the time between two tips.

    - platform: trend
      sensors:
        rain:
          entity_id: sensor.rainfall_today
          min_gradient: 0.000138889
    rain_pr_hour:
        friendly_name: "Rain pr hour"
        unit_of_measurement: 'mm/h'
        value_template: >-
          {% if state_attr('binary_sensor.rain','gradient') > 0 and state_attr('binary_sensor.rain','gradient') < 0.0278 %}
          {{ (state_attr('binary_sensor.rain','gradient')*3600) | round(1) }}
          {% else %}
          {{ states('sensor.rain_pr_hour') }}
          {% endif %}

sensor.rain_pr_hour is between 0 and 100mm/h

4 Likes

Hello,

Thanks for your sharing.
I have an issue, if home assistant or zigbee2mqtt restart, the counter increase and rainmeter also…
Have you seen that ?
Do you have any ideas to resolve it ?

Thank you in advance .
Tuiting.

I suspect that this is caused by the history sensor. When you restart z2m, it might report ‘off’ for a second, causing the history sensor to increase. I don’t have this issue with ZHA. Maybe you need to add something to the mqtt settings to have it remember the last state?

Thank you for your reply. Indeed, I saw the option “retain” and everything works perfectly.

devices:
  '0x00158d0005225c0d':
    friendly_name: DO_RAIN
    retain: true

Thank you so much.

3 Likes

If I try your Rain per hour sensor, I get the following error in the log:

homeassistant.exceptions.TemplateError: TypeError: '>' not supported between instances of 'NoneType' and 'int'

I have done some changes and my template is now like this:

      rain_today:
        friendly_name: Regn i dag
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('sensor.regnsensor_vippe') | int %}
          {% if states.sensor.date_time_iso.last_changed - states.sensor.regn_i_dag.last_changed > timedelta(minutes=60) %}
          {% set mm_per_pulse = 0.303 %}
          {% else %}
          {% set mm_per_pulse = 0.30303 %}
          {% endif %}
          {% set mm = count * mm_per_pulse %}
          {% if states('sensor.regnsensor_vippe') != 'unknown' %}
          {{ mm }}
          {% else %}
          {{ states('sensor.regn_i_dag') }}
          {% endif %}
      regn_pr_hour:
        friendly_name: "Regn pr time"
        unit_of_measurement: 'mm/h'
        value_template: >-
          {% if state_attr('binary_sensor.regn','gradient') != None and state_attr('binary_sensor.regn','gradient') > 0 and state_attr('binary_sensor.regn','gradient') < 0.0278 %}
          {{ (state_attr('binary_sensor.regn','gradient')*3600) | round(1) }}
          {% else %}
          0
          {% endif %}
- platform: trend
      sensors:
        rain:
          entity_id: sensor.rain_today
          min_gradient: 0.000138889
          max_samples: 3

The trend sensor doesn’t update when it stops raining so I made a change to the tamplate to handle that. You can use sensor.time or sensor.date_time_iso as I did.

2 Likes

88.1mm today and it didn’t miss a beat, :ok_hand:

2 Likes

That’s A LOT of rain! Most I’ve had here was like 16mm a day. Good to hear it works great :slight_smile:

@bergasha by the way, how accurate is it compared to your weather station?

Damn! Almost 9cm in one day… where do you live @bergasha ? :slight_smile:

If I wanted to change the rain tips sensor to record from 9am for 24 hours could you suggest what the code is please?

My local govt weather reports since 9am and the previous 24 hour periods for up to a week.

NB… I am a horrible coder, but like to tinker.

This should work :slight_smile:

sensor:
  - platform: history_stats
    name: Raingauge tips
    entity_id: binary_sensor.raingauge_on_off
    state: 'off'
    type: count
    start: '{{ now().replace(hour=9, minute=0, second=0) }}'
    duration:
      hours: 24
1 Like

@parrel Weather station is 86.9 so I would say pretty accurate :ok_hand:

@Shaad Brisbane Australia

2 Likes

Hi all. I made the rain gauge and used the yaml code at the top of this thread. It works as intended but I noticed a lag of quite some time between the Xiaomi binary sensor (open/close/open) and the two sensors (history_stats and calculation to mm). In my example it’s about 24 seconds.

Schermopname 2021-02-03 om 16.14.13

Does anybody noticed that also? And does anybody has an explanation for this behaviour?

Hi, I also have a small delay now and then. But thats like 3 seconds. Does not really matter for me.

The delay is probably caused by the history sensor. I don’t know how HA handles the updates of the history sensor.

Mine also has a slight delay (under 10 sec) I did notice if it tips again before it updates it will add the two tips onto the history do I don’t believe it misses any.

For those interested, here is a card to see the rainfall of the past days, made with mini-graph-card.

type: 'custom:mini-graph-card'
icon: 'mdi:weather-rainy'
aggregate_func: max
hours_to_show: 730
group_by: date
show:
  graph: bar
entities:
  - entity: sensor.regenval_vandaag
    color: aqua

I keep my history for a month (730 hours) but if you keep yours less it might show less bars.

8 Likes