☔ DIY Zigbee rain gauge

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

Thanks for this guide. I’ve bought the same bucket, and as I already have a ESP 8266 running Konnected.io nearby, I simply connected the two wires coming out of the bucket into that. After configuring the HA konnected plugin, it’s working immediately, with the bucket acting as the reed switch and HA in “rain” mode acting as a pulse counter.

1 Like

Another good downpour… everything still accurate and working well :ok_hand:

4 Likes

Pretty sure this was working fine until recent updates to HA. Now, on every restart, I get 0.3mm added. Even the reset at midnight started at 0.3mm yesterday …

  - platform: history_stats
    name: Raingauge tips
    entity_id: binary_sensor.zb_rain_sensor
    state: 'off'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'

  - platform: template
    sensors:
      rainfall_today:
        friendly_name: Rainfall today
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('sensor.raingauge_tips') | int %}
          {% set mm_per_pulse = 0.30303 %}
          {% set mm = count * mm_per_pulse %}
          {{ mm|round(1, 'floor') }}
1 Like

Have you tried the retain option? (if you use z2m)

Am using ZHA …

Just tested it on my instance, I don’t have this behavior… ZHA with conbee II

Am on ZHA with Sonoff Tasmota ZB-Bridge … I zero’d it out manually (via dev > state) and restarted (I didn’t zero out the tips though)

… it’s now at 1.5mm … Screenshot 2021-03-07 at 14.51.05

state: "off" was my issue, I think. Makes sense for this to be state: "on" to count tips. I was getting a count at midnight reset and then off state was triggered again on restart.