☔ DIY Zigbee rain gauge

I decided that I wasn’t ok with the Rain Intensity sensor keeping its last non-zero value until either more rain comes or the clock strikes midnight. See the 3rd graph below:

So I made a new history_stats sensor to track the amount of rain that’s fallen in the last 10 minutes. Here’s the (sensors.yaml) YAML code:

- platform: history_stats
  unique_id: RainSensorBucketTipsLast10MinutesDebug
  name: Rain Sensor Bucket Tips Last 10 Minutes - Debug
  entity_id: binary_sensor.rain_bucket_tipped_debug
  state: 'on'
  type: count
  start: '{{ (now() - timedelta(minutes=10)) }}'
  end: '{{ now() }}'  

From there, I modified my Rain Intensity template sensor to look like this. Here’s the (templates.yaml) YAML code:

- sensor:
    - name: Rainfall Intensity - Debug
      unit_of_measurement: mm/h
      state_class: measurement
      device_class: precipitation_intensity
      unique_id: RainIntensityDebug
      state: >-
        {% set rainfall_gradient_hourly = ((state_attr('binary_sensor.rainfall_today_trend_debug', 'gradient') | float(default=0)) * 3600) | round(1, 'floor') %}
        {% if states('sensor.rain_sensor_bucket_tips_last_10_minutes_debug')|float(default=0) > 0.000 %}
          {{ max(rainfall_gradient_hourly, 0) }}
        {% else %}
          0
        {% endif %}

And here’s what the new behavior looks like when I artifically made it rain by tipping the bucket a bunch of times manually:

image

Essentially, when the rain stops, the Rain Intensity sensor holds its value for 10 minutes and then drops to zero. I might set the “10 minute” value to something lower eventually, but for now, it seemed like a reasonable starting point.

4 Likes

Looks really nice and many thanks for sharing your code. Unfortunately I don’t really get how to add this. I’ve added both code snippets to the appropriate yaml files, but can’t seem to figure out where to hook up the rain flips sensor.

The rainfall debug sensor is available in HA, but since I have nowhere a match with my rain flips sensor, it stays 0.

Does anyone have an STL file for an equivalent of the Misol housing?

Or even the fairly detailed dimensions so I can CAD one up to share?

Is there a way to delete the old data used for testing at all

hello,
nice project and thanx to all crazy guys here with all this crazy ideas and solutions!
as a hassio fool, it was really hard, but i was happy to get this project run :slight_smile:

i tried @erikg s solution, to reset the Rain Intensitiy after 10min, when no rain falls, but i cant get it working.
with Template Editor i always getting “5”, doesnt matter if i use < or > in the if statement?
sensor.regensensor_flips_zero_resets shows me “0” in the DevTools States
even when i change state with SetState to other values, i never get another result than 5?? why?
i had tried |int() as well?

herer is the part from the TemplateEditor…

          {% if states('sensor.regensensor_flips_zero_reset')|float(0) > 0.000 %}
            {{ max(rain_hour, 0) }}
          {% else %}
            5  #5 just for testing, should be 0
          {% endif %}

what i made wrong?
thank you in advance
br
Frank

hello i tried al lot, but won´t get it…

both binary_sensor.rainfall_trend gradient and sensor.regensensor_flips_zero_reset are 0 at this moment (as Development/States show me)
TemplateEditor shows me the correct result = 0 for the following expression…

          {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if states('sensor.regensensor_flips_zero_reset')|int() > 0 %}
            {{ max(rain_hour, 0) }}
          {% else %}
            0
          {% endif %}

…but the template sensor Rain intensity still remains at its last state (i had manually set per development/states)…see image?

template:
  - sensor:
      - name: "Rain intensity"
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: rainfall_per_hour2
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if states('sensor.regensensor_flips_zero_reset')|int() > 0 %}
            {{ max(rain_hour, 0) }}
          {% else %}
            0
          {% endif %}

here my reset sensor

  - platform: history_stats
    unique_id: RegensensorFlipsZeroReset  
    name: Regensensor Flips Zero Reset
    entity_id: binary_sensor.regensensor_contact_invert 
    state: 'on'
    type: count
    start: '{{ (now() - timedelta(minutes=10)) }}'  
    end: '{{ now() }}'  

what have I done wrong?
thanx
br
Frank

this solution for resetting the intensitiy sensor does not work for me… the rain instensity stays at 0, when its raining…

the instensity sensor itself seems to work correctly, when i set sensor.regensensor_flips_zero_reset manually it changes to values > 0

          {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if states('sensor.regensensor_flips_zero_reset')|int(0) > 0 %}
            {{ max(rain_hour, 0) }}
          {% else %}
            0
          {% endif %}

but this sensor.regensensor_flips_zero_reset seems never count be itself?

  - platform: history_stats
    unique_id: RegensensorFlipsZeroReset  
    name: Regensensor Flips Zero Reset
    entity_id: binary_sensor.regensensor_contact_invert     #siehe config.yaml
    state: 'on'
    type: count
    start: '{{ (now() - timedelta(minutes=10)) }}'   
    end: '{{ now() }}'  

it stays always at 0
when i set it manually, it changes back to 0 after a couple of seconds, what might be correct, when no rain had fallen in the last 10 minutes and binary_sensor.regensensor_contact_invert hadn´t changed yet…
but when i manually set binary_sensor.regensensor_contact_invert to “off”, “on”, “off” to simulate some flips, the sensor.regensensor_flips_zero_reset never reacts? it stays always at “0”??

anybody and idea why?
thanx
br
Frank

So pleased I have this all working , many thanks to parrel for sharing this and helping me when I got stuck.
I am using the Apexcharts card to show the daily rainfall for a month and I wonder if any kind person could show me how to modify it to show weekly rainfall over a yearly period? It is probably not possible but it would be really great if it could be made to be a “rolling” chart where the oldest week data gets removed as the new week data arrives so that the chart is always showing the last 52 weeks.
Thank you to anyone who can help.

1 Like

Thanks for the kind words.

This may be what you need, not sure if it’s accurate

chart_type: bar
period: week
type: statistics-graph
entities:
  - sensor.rain_week
stat_types:
  - state
title: Rain per week
days_to_show: 365

Thanks, will try that.

I am a beginner in home assistant and want to build this rain gauge, but how do I get the, I presume, YAML code into Home assistant and how do I get it to work?

This might be a good point to start

If you are more of visual learning instead of reading, take a look on YouTube.

The YAML in the original post is basically copy/paste but you will need to change the entity id of the rainsensor to the entity id that you are using.

Thank you I will give it a go

Oke I am stuppid but is it in Jinja or in YAML?

Can someone make a print screen where I have to put in de the YAML or jinja code? I have done 3 hours of useless tutorials now and I still dont know where to start. I do not now If I have to use the File editor or developers tool?

Please a little bread crum in the right direction would help

Go to settings->addons-> search for studio code server and install the addon

This will install a code editor, that allows you to edit the configuration.yaml file, the file where all the YAML should be added to.

In the addon you can edit this file and add the YAML to it.

YAML is for configuration and is static
Jinja2 is more like programming and calculating

At some places in YAML you can add a template that contains Jinja2 that will be executed runtime

Start by installing the addon and playing with configuration.yaml

Hi @parrel :slight_smile: Thanks for a great tutorial;) I have just built the rain gauge ( but I did use the insert adapter here - Rain Gauge (Aqara door sensor support) Pluviomètre Aqara by waazdakka - Thingiverse ) it makes the whole project pretty clean. Anyways - I have set up the gauge using your yaml. I did have some issues - when I pour 10 ml. of water down the funnel I get 4 tips on my gauge (I may be measuring the 10 ml. wrong, but I think it should be right). I can see you are going with 6 tips for 10 ml. of water, by taking the tutorial from the reviewer from amazon. The value that are going in the yaml code. 0.30303 - something - where does this value come from? the calculation pulses / mm = 5.5 / (10/6) = 3.3 I understand (where I in my case should replace 6 with 4 instead. But how is the value calculated, that goes into the code - I don’t get it :smiley:

Oke so I copy the codes somewhere in the configuration.yaml ? I did this and nothing is happening. (I am smart enough to change the sensor id’s)
I can someone make a screenshot so I get the whole picture and not a part of the picture, please

Be sure to restart home assistant after the change, then check the logs or entities if they are added

@Shellfishgene, @doubleUS would you mind sharing some photos of your setup? I am sorry, but I am having a hard time visualizing it and since I do not have soldering equipment, I would be inclined to try out your way of setting this up.

I’m sorry. I’m on holiday right now. As soon as I’m home I will make some pictures.