☔ DIY Zigbee rain gauge

Hello @FrankRy

The logic in that yearly chart was needed because HA only keeps montly statistics, so I needed to retrieve the highest value from the 12 months in a year, because that would be yearly total.

Here is a monthly chart which is much more simple

type: custom:plotly-graph
title: Rain per month
hours_to_show: 6y
entities:
  - entity: sensor.rain_month
    name: Rain (month)
    period: month
    statistic: state
    type: bar
layout:
  yaxis:
    title: Rain (mm)
1 Like

Thanks @parrel and apologies for the delayed reply…life gets in the way sometimes!

I’ve checked the raw data (binary flips) and you are correct - at the points of interest there are two flips recorded in the same second. I’ve marked 09:49:18AM as the first point of 2 flips in a second, this corresponds with the first spike (RHS).

I’ll have to test out my bucket sensor further for a mechanical/electrical issue, as rain would never be heavy enough to trigger 2 flips per second. I don’t think you could pour water fast enough through the small drip hole to achieve this anyway!

My sensor is a hall-effect type (not reed switch) with a small rectangular magnet attached to the bucket…unsure how I could get a double hit.

If it keeps occurring, you could add a debounce logic, or use another sensor (can recommend Aqara)

1 Like

Goedenavond,

Wie kan mij helpen? Ik kom er niet uit. Wat ik ook probeer het werkt niet.
Zit het in de yaml code? Waar plaats ik deze?
Ik snap het echt niet meer, tuimel ik de tuimelaar dan gaat deze wel van Open naar Gesloten en weer naar Open. Dus de sensor werkt wel.

How to help us help you - or How to ask a good question - Configuration - Home Assistant Community

Hi Ruben

Lets keep it in English as that would allow people all over the world to easily help you :wink:

Good thing the sensor works, that’s the most important part.

The Yaml part would have to be placed in the configuration.yaml file, see Configuration.yaml - Home Assistant

Hi Parrel,
I will do it in English.
But can you tell me where to put it? I’ve already done this, but it doesn’t work. Yaml isn’t really my thing yet.
Thanks.

If you read the link above and then move on to the related topics “yaml syntax” you will have an idea of where the code goes.

If you have any more questions please ask.

Hi Arh,
I understand that. I’m putting the code in the config.yaml.
But then it doesn’t work at all, and I don’t understand that. Meanwhile, the flip count works, but I don’t see a rain sensor. Strange, right?
So what am I doing wrong?

Which bit of code are you trying to put in your config.yaml file? Please post the text, not images/screenshots.

Hai Sparkydave, this code:

1. Zählt die “Flips” des Regensensors seit Mitternacht

sensor:

  • platform: history_stats
    name: Rainsensor Flips Today
    entity_id: binary_sensor.regensensor_opening
    state: ‘off’
    type: count
    start: “{{ as_timestamp(now().replace(hour=0, minute=0, second=0, microsecond=0)) }}”
    end: “{{ as_timestamp(now()) }}”
    unique_id: rainsensor_flips_today

2. Berechnet die tägliche Regenmenge und die Intensität

template:

  • sensor:

    Sensor für täglichen Regen

    • name: Rainfall today
      unique_id: rainfall_today
      unit_of_measurement: ‘mm’
      state_class: total_increasing
      state: >-
      {% set count = states(‘sensor.rainsensor_flips_today’) | int(0) %}
      {% set mm_per_flip = 0.30303 %}
      {{ (count * mm_per_flip) | round(1, ‘floor’) }}
      availability: >-
      {{ states(‘sensor.rainsensor_flips_today’) not in [‘unknown’, ‘unavailable’] }}

    2b. Aktuelle Regenintensität in mm/h

    • name: “Rain intensity”
      unique_id: rainfall_per_hour
      unit_of_measurement: ‘mm/h’
      state_class: measurement
      state: >-
      {% set gradient = state_attr(‘binary_sensor.rainfall_trend’, ‘gradient’) | float(0) %}
      {% set rain_hour = (gradient * 3600) | round(1, ‘floor’) %}
      {% if rain_hour >= 0 %}
      {{ rain_hour }}
      {% else %}
      {{ 0 }}
      {% endif %}
      availability: >-
      {{ state_attr(‘binary_sensor.rainfall_trend’, ‘gradient’) is not none }}

3. Trend-Sensor zur Berechnung der Änderungsrate der täglichen Regenmenge

binary_sensor:

  • platform: trend
    sensors:
    rainfall_trend:
    entity_id: sensor.rainfall_today
    max_samples: 4

4. Zähler für wöchentliche, monatliche und jährliche Regenmengen

utility_meter:
rain_week:
source: sensor.rainfall_today
cycle: weekly

rain_month:
source: sensor.rainfall_today
cycle: monthly

rain_year:
source: sensor.rainfall_today
cycle: yearly

Can you please properly format the code for the forum. (highlight it and click on the gear / cog icon, followed by selecting ‘preformatted text’)

I don’t quite understand it, but the code I had turned out to be incorrect. The code for this project is correct, and everything works now. Thanks anyway.

1 Like

How to format your code for the forum:

It’s been 5 years since I introduced the rain gauge, and it’s still going strong on the original battery! Incredible really.

I am on the 3rd battery in mine in about 5 years, but then I do live on the edge of Wales. :slight_smile:

2 Likes

I just got my “hardware device” from AliExpress and I only did some indoor tests (Works fine with a 3D printed holder for the Aqara sensor!), and I was wondering if the sound of the tipping is an issue out in the wild? It seems quite loud inside… Did a neighbour or so ever complain?

1 Like

Good to hear it’s working!

But I cannot relate to the loud sound, I mean, you can hear the click, but only when outside, and it does not tip a lot, during light rain maybe 4 times an hour. During heavy rain it wouldn’t be hearable outside as well. Let alone inside. :laughing:

1 Like

Hi, I never got around to thanking you for this thread. I replicated your setup about a year ago and have been tweaking it occasionally since then.

I’m using a Tuya Zigbee door sensor from Aliexpress and it works OK. I recently connected it to my ZHA network instead of the Tuya integration so it keeps working when there’s no internet available. This required a ZHA quirk to get the battery voltage coming though correctly.

Some features I’ve used or added:

  • 15 minute rainfall intensity
  • Instantaneous rainfall intensity, calculated using the time between bucket tips. I have this automatically resetting to zero after 30 minutes of no rain.
  • A rainfall event total. This resets automatically after 6 hours of no rainfall.
  • A manually resettable rainfall total.
  • Statistics sensors for the maximum rainfall intensities in the last 12 hours.
  • A switch to disable the rain gauge and prevent any rainfall being recorded when setting up/testing the tipping bucket.

I can post my configuration yaml if needed.





2 Likes

Thanks for the inspiration! That’s a lot of rain for 1 day by the way!