☔ DIY Zigbee rain gauge

For those who have been using this setup for awhile now, you have no issue with the sensor being under the sun for a good amount of hours per day? This is my first sensor being expose to the sun and where I am from, summer gets very hot AND humid.

Hi @parrel I just noticed that my rain tips and rainfall today are not resetting to 0.0mm. Is my code wrong or does my HA need a kick ? Pretty sure it did before.

# Garden Rain Sensor 1 Amount of Tips
  - platform: history_stats
    name: Garden Rain Sensor 1 Tips
    entity_id: binary_sensor.garden_rain_sensor_1_contact
    state: 'off'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'
    
# Garden Rain Sensor 1 Rainfall today
  - platform: template
    sensors:
      garden_rain_sensor_1_rainfall_today:
        friendly_name: Garden Rain Sensor 1 Rainfall Today
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('sensor.garden_rain_sensor_1_tips') | int(0) %}
          {% set mm = count * 0.30303 %}
          {% if count >= 0 %}
            {{ mm|round(1, 'floor') }}
          {% endif %}
        # If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
        availability_template: "{{ (states('sensor.garden_rain_sensor_1_tips') not in ('unknown', 'unavailable')) }}"
1 Like

I have it for 1,5 years and have had no issues with the Aqara sensor. I think, if you use the lid like I did in the original post, you shouldn’t have problems.

1 Like

I don’t see anything wrong there

1 Like

That is good to hear. I mimic exactly your setup.

I am assuming you don’t have power nearby up on the roof. How did you create your power line to power the esp8266?

My ESP8266 is inside my “summer kitchen” which is still in construction phase. ESP is inside in the cabinet, it’s connected to the electrical socket. The cable to the sensor goes through the hole in the wall outside and the sensor is screwed to one brick (wind) and it’s on the brick fence :grinning_face_with_smiling_eyes:

3 Likes

Hello there. I am not following. I’ve tried this below, but it is not triggering. I want the get notify after first flip from zero.

  - alias: Rain Detected Home
    trigger:
      - platform: state
        entity_id: sensor.rainfall_today
        from: '0'
        to: '0.3'
    action:
         blah.blah...

Trigger it from raingauge tips from “0” to “1” Maybe?

Remove to: so there is only from: 0

1 Like

@BigG @johannwilken
Do you both have the Retain option checked in zigbeemqtt? It stills a tip for every reboot for me.
This is my code:

# Garden Rain Sensor 1 Amount of Tips
  - platform: history_stats
    name: Garden Rain Sensor 1 Tips
    entity_id: binary_sensor.garden_rain_sensor_1_contact
    state: 'off'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'
    
    
# Garden Rain Sensor 1 Rainfall today
  - platform: template
    sensors:
      garden_rain_sensor_1_rainfall_today:
        friendly_name: Garden Rain Sensor 1 Rainfall Today
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('sensor.garden_rain_sensor_1_tips') | int(0) %}
          {% set mm = count * 0.30303 %}
          {% if count >= 0 %}
            {{ mm|round(1, 'floor') }}
          {% endif %}
        # If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
        availability_template: "{{ (states('sensor.garden_rain_sensor_1_tips') not in ('unknown', 'unavailable')) }}"

I can’t enter a availability template for the history_stats platform, and i have a feeling because of the aqara door sensor going from open - close or vice versa it increases tips, and as a result increases the daily rainfall/rainfall today sensor. Maybe setting that to retain will resolve it?

Hi atv,
No I don’t have Retain checked in zigbeemqtt.
I know when I first set this uo it took me a while to fix the reboot issue, from memory I checked the history of the sensor to see the exact state the it went through during reboot and I wasn’t testing for the correct state.

ok. Got it working thx.
So, if the rain continues past 00:00:00 time, it will trigger again since it reset to 0 at midnight??

Yes it will trigger every time it changes from 0 to something else.

Thanks @BigG. Is your code same or similar to mine ?

Hi @atv this is my code.

  - platform: template
    sensors:
      rain_gauge_invert:
        value_template: >-
          {{ is_state('binary_sensor.rain_gauge_contact', 'off') }}
        device_class: door 
 
  - platform: history_stats
    name: Daily Gauge Flips
    entity_id: binary_sensor.rain_gauge_invert
    state: 'on'
    type: count
    start: '{{ now().replace(hour=0, minute=0, second=0) }}'
    end: '{{ now() }}'
 
  - platform: template
    sensors:
      daily_rain:
        friendly_name: Daily Rain
        unit_of_measurement: mm
        value_template: >-
          {% set count = states('sensor.daily_gauge_flips') | int(0) %}
          {% set mm_per_pulse = 0.30303 %}
          {% set mm = count * mm_per_pulse %}
          {{ mm|round(1, 'floor') }}
        availability_template: "{{ (states('sensor.daily_gauge_flips') not in ('unknown', 'unavailable')) }}"
1 Like

Hmm i see you created an inverted sensor. I’ll add that and see if that resolves it. I had the availability sensor already, thought that would suffice.

I get this error when using that code:

The system cannot restart because the configuration is not valid: Invalid config for [sensor.template]: expected SensorDeviceClass or one of 'apparent_power', 'aqi', 'battery', 'carbon_monoxide', 'carbon_dioxide', 'current', 'date', 'duration', 'energy', 'frequency', 'gas', 'humidity', 'illuminance', 'monetary', 'nitrogen_dioxide', 'nitrogen_monoxide', 'nitrous_oxide', 'ozone', 'pm1', 'pm10', 'pm25', 'power_factor', 'power', 'pressure', 'reactive_power', 'signal_strength', 'sulphur_dioxide', 'temperature', 'timestamp', 'volatile_organic_compounds', 'voltage' for dictionary value @ data['sensors']['garden_rain_sensor_1_inverted']['device_class']. Got 'door'. (See ?, line ?).

Update: NM i had to place the first part of that code in my binary_sensors.yaml file.

Everything is working now, thanks to that inverted sensor. I do still see after a restart, a marker in the graphs but the value does not change. Ideally that would also not be displayed but that’s an artefact of the history_stats platform i think.

UPDATE: Nope, i spoke too soon. Still get a tip per reboot, sigh. And these forecast trends don’t look right either. 46.555.9 ? The forecast trend also stays like that for a way to long time in my opinion.

1 Like

The trend spike is caused by the false tip.

Unfortunately I can’t help you solve that, I cannot reproduce it

Having built and calibrated my Raingauge 6 weeks ago, today was the first significant rain since I installed it. All I can say is its totting up the rainfall without issue. 15.4 mm so far today. Nice to see it finally working.

2 Likes