☔ DIY Zigbee rain gauge

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