☔ DIY Zigbee rain gauge

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.

Hey,

I kinda just stuffed it in there with some cardboard to fix it in place. You just need to look at the original board, see first post for picture, and make sure that the black bar on the Sonoff (the reed switch) is about in the same position as the reed switch in the middle of the original board is. Just flip the rocker and make sure that the Sonoff fires every time. The magnet on the rocker is behind that little nose on top.

Great advise, the work in configuration.yaml. I lost half of my home-assistant.

Are you in eu? I can print and post this for you for the price of postages.
If you have v2 door sensor.
Send me pm.
And @Shellfishgene too.

1 Like

I’ll take that as a ‘Thank you’ :wink:

Thanks @parrel this is great project. At least for a measuring geek like me :D.

1 Like