☔ DIY Zigbee rain gauge

Hi, can you have an instruction on what should be done to read the daily, weekly, monthly, annual rainfall? Thank you greetings.

Worked well for a while (except for reboots I haven’t found a reliable solution), but just recently all previous data went haywire… Anyone have any idea how ?


In this screenshot all the bars at equal height appeared out of nowhere !

Have you set the purge_keep_days of the recorder component to at least the amount of days shown on the chart?

I’ll try that thank you !

1 Like

@czaki
Have you tried Utility Meter - Home Assistant ?

After reading this

and im having a 1/2 knee replacement i have build the knee strength up with no weight

DOC said I have ride a stationary bike

thinking on one of the bike rides " could i do the rain gauge to this.

and my the battery going flat on mine Zigbee Bed occupancy sensor

so tape it to the bike wheel and get a count bugger it worked ok

image

now the maths (im just winging it )

i walk the bike one turn which came to 2.2 mtr

base on the above maths I did

#=======================================================================
#
#=======================================================================

- platform: history_stats
  name: bike turns
  entity_id: binary_sensor.bike_contact
  state: 'off'
  type: count
  start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  end: "{{ now() }}"

- platform: template
  sensors:
    bike_today:
      friendly_name: Bike  Today
      unit_of_measurement: km
      value_template: >-
        {% set count = states('sensor.bike_turns') | int %}
        {% set mm_per_pulse = 2200 %}
        {% set mm = (count * mm_per_pulse) %}
        {% set KM = mm / 1000000 %}
        {{ KM|round(2, 'floor') }}

will add lovelace screen after tomorrow bike ride

here is the lovelace look

image

after some more thinking

3 Likes

Really cool! Let us know the results haha. And good luck with recovering!

Great contribution here! Awesome raingauge.
I’ve also succesfully built it and enjoy the readings.

I’ve also seen the restart hass false flip-count issue. Tried to find a decent solution and I think I have found one. So I’m trying to give something back.

Basically, the problem resides in Hass, when the restart occurs, the binary sensor goes unavailable for a short while, somehow it seems that it is calculated in the history_stats. Not sure if this is expected behaviour or maybe a bug.
However. When you create an inverted binary sensor of your contact-sensor (I’m also using Zigbee2MQTT), then this problem no longer occurs:

- platform: template
  sensors:
    regensensor_contact_invert:
      value_template: >-
         {{ is_state('binary_sensor.regensensor_contact', 'off') }}
      friendly_name: Regensensor
      device_class: door

Edit: please be aware, above is a binary_sensor. The device_class also is important here.

(because we only mirror ‘off’ state, an unavailable state doesn’t mess anything up)
Then all you have to do is alter the history_stats sensor to use this inverted one instead, and ofcourse count state ‘on’ instead, because it’s inverted now (very important):

- platform: history_stats
  name: Regensensor flips
  entity_id: binary_sensor.regensensor_contact_invert
  state: 'on'
  type: count
  start: '{{ now().replace(hour=0, minute=0, second=0) }}'
  end: '{{ now() }}'
3 Likes

I’ve also done this but using a battery operated cheapo 433 door/window sensor.
No need for power or rewiring but you do need a 433 bridge.

I just fitted the sensor inside the casing and added another magnet to the opposite pivot point on the tipper.

I love your brilliant idea! Thanks for posting this.

1 Like

Could show us with some pic

Yes…
I meant to take a photo and post it here but I forgot.
It’s in-situ now but I promise to try and sort it out as soon as I get time.

Sorry
:blush:

sorry for the dumb question.
But where should I integrate this code?
To my config.yaml?
If I save this, there is always an error and I cannot restart my home assistant

no dump question here bro

what are you trying to add

so 1o1 then

glue is looking at the platform that I the Main pointer and that where it all starts

this is basic on my understanding of HA

1st we have

platform: history_stats

that belong with a sensor as its getting data from SOMETHING but we dont know what

that were the platform come in its a pointer

so in my config file I have

image

SHIT I LOVE YAML you can see what you are getting
(note took 2 months to get head around it LOL)

note the sensor bit its point to a sensor folder

sensor: !include_dir_merge_list sensor

so any YAML stuff (file) inside that folder is loading in as a sensor thing (my english LOL)

so base of there file names you get and idea on what im trying to do thanks @frenck for your logic

so the in the statistic.yaml i have the

my logic here i always paste make at top of file easy to find LOL

then my other bits are the the template.yaml file

this is one of the GOOD THING ABOUT HA I can do it MY WAYS as long and i play with in the rules

anymore question just ask bro

1 Like

thanks for that detailed explanation.
But this is a lil bit too much for me :smiley:
can you (simple) explain, where I have to integrate the two codes from the first post?
I added the sensor to my home assistant and I get “open/closed” status…
Now I have to integrate the code, if I understand the proceed correctly?

The code has to be under the sensor: line. If it’s not present, create it :slight_smile:

1 Like

thank you, now it works :slight_smile:


Now I have to figure out, how I can implent this to node red to create a telegram message, if rain starts :slight_smile:

1 Like

okay, today I simulated rain with a watering can :smiley:
I realized that I have an problem with my code, the “Regenfall heute” (rainfall today) doesn’t count…

#Regensensor
  - platform: history_stats
    name: Regenmesser
    entity_id: binary_sensor.regensensor
    state: 'off'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'
  - platform: template
    sensors:
      regenfall_heute:
        friendly_name: Regenfall heute
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('binary_sensor.regensensor') | int %}
          {% set mm_per_pulse = 0.30303 %}
          {% set mm = count * mm_per_pulse %}
          {{ mm|round(1, 'floor') }}

Can you tell me, which sensor I need to implement in 4th last row (current is binary_sensor.regensensor insert)?
Dont know why in the first post is there a second sensor and not the binary_sensor included…

Edit:
Got it!
have to set the sensor.regenmesser

1 Like

Use this :slight_smile:

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

As requested here is my version.

Any questions, feel free to ask

5 Likes

Your idea of inverted sensor works flawlessly. So simple and effective. Thanks for sharing !

1 Like