☔ DIY Zigbee rain gauge

Thank you again for this great project. I have a little issue with the Rain Intensity sensor. I can’t make it work.

Configuration.yaml
sensor:
  ###### Rain sensor flips count ######
  - platform: history_stats
    name: Rainsensor flips
    entity_id: binary_sensor.aqara_rain_sensor_contact #The aqara sensor
    state: "off"
    type: count
    start: "{{ now().replace(hour=0, minute=0, second=0) }}"
    end: "{{ now() }}"
 
binary_sensor:
  - platform: trend
    sensors:
      rainfall_trend:
        entity_id: sensor.rainfall_today
        max_samples: 2
 
template.yaml:
#Rain sensors
- sensor:
    - name: Rain today
      unit_of_measurement: mm
      state_class: total_increasing
      unique_id: rainfall_today
      state: >-
        {% set count = states('sensor.rainsensor_flips') | int(0) %}
        {% set mm = count * 0.30303 %}
        {% if count >= 0 %}
          {{ mm|round(1, 'floor') }}
        {% endif %}
      availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"
 
- sensor:
    - name: "Rain intensity hour"
      unit_of_measurement: "mm/h"
      state_class: measurement
      unique_id: rainfall_per_hour
      state: >-
        {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
        {% if rain_hour >= 0 %}
          {{ rain_hour }}
        {% else %}
          {{ 0 }}
        {% endif %}

The sensor showing 0.0 all the time.
Any idea what could be the issue?

Does your binary sensor have a gradient attribute? If yes, does it have a value other then 0?

You can also paste the jinja2 code in the developer tools template thing to see the values of the variables.

I am not sure that I fully understand. Do I need to set the gradient value somewhere? I have just copied the code from your post. Tips and daily rain works just fine, it is only this intensity sensor that is not working.
If I copy the Intensity sensor into the developer tools template thing, it returns 0.0

To debug why it’s showing 0 you need to debug how it’s coming to this value.

{{ state_attr('binary_sensor.rainfall_trend', 'gradient') }}

What does this return when you add it to the developer tools template?

Any errors in the logs?

No errors in the logs that I can see. I have entered the above line and it simply returns “null”

And the entity id for reading the daily rain is correct? sensor.rainfall_today

Yes, you can see my sensors a few comments up. It is an exact copy of your sensors from your post. Everything else is working just fine.

I removed everything from my configuration.yaml and templates.yaml. Restarted HA, added sensors again and now it works. Very strange, but at least I get data now :slight_smile:

Thank you very much for your help and time.

1 Like

Good to hear! :slight_smile:

I need this ZigBee rain gauge sensor please help me

You can create it yourself, the parts are in the first post.

Is anyone running the latest Beta? tips keep setting itself to 1 and won’t reset to 0 at midnight so daily rain is constantly 0.3mm. Is anyone else getting the same?

I once had this problem, and the state of the rain sensor was ‘closed’ instead of ‘open’.
I had to pour some water in the sensor to make it tip, so that the state was ‘open’ again.

Is this not your case?

Unfortunately not, still states it’s open and from what I can tell is still working correctly other than resetting itself to one instead of zero.

Try to create another history stats sensor on another binary sensor and see if it also does not reset this midnight

Good idea, I’ll try that this evening and report back. Cheers

1 Like

So, did it reset?

No it did not, I however deleted my db and everything seems to be resetting again.
Not ideal but it’s a fix if anyone else runs into this.

There goes all the rain data history :frowning:

It actually kept all the utility meter data so no issues there.

1 Like