☔ DIY Zigbee rain gauge

Could you tell me what’s not working in the Original Post? :slight_smile:
This is what you can use to measure weekly, monthly and every year.

utility_meter:
  regen_week:
    source: sensor.regenval_vandaag #your daily rainfall sensor
    cycle: weekly
  regen_maand:
    source: sensor.regenval_vandaag
    cycle: monthly
  regen_jaar:
    source: sensor.regenval_vandaag
    cycle: yearly
1 Like

Apparently nothing is wrong with the OP, maybe I configured something wrong, now it works. I also set up the utility meter to your suggestion and its great:

image

Now I did some manual testing, is there a way to reset the daily rainfall and delete its recordings?

I changed one small thing in the original post, maybe that was the cause :slight_smile:

Actually I was testing yesterday as well and I found out it’s pretty hard to reset this daily sensor. What I did was remove the states from the states table with SQL, for both the binary sensor and the daily sensor.

To reset the utility meters, use the utility_meter.reset service.

1 Like

When I do that that manually configured utility_meters dont show up?! I go into yaml mode and enter their entity_ID manually but that doesnt reset them either…

OK I used the service to calibrate the utility_meters and set them to 0, so that worked. Also a good way to maybe manually subtract a certain amount of mm if you one did some manual testing

1 Like

I got a good downpour tonight, that allowed me to test the rainfall per hour sensor. I’ve added the code to the original post. :slight_smile:

Thanks so much @parrel for sharing this project! I’ve been subscribed to it for a long time until I got some free time to work on it.
Since I don’t have an issue to have a device inside my home and put the cable throught the wall out to the device on the roof, I chose not to go with battery-powered device but rather ESP8266 running ESPHome.

The installation was simple - I’ve connected the red cable from the device to D7 and green to GND and I’ve configured the device like below.

substitutions:
  device_name: rainfall-sensor
  friendly_name: Rainfall sensor

esphome:
  name: "${device_name}"
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: !secret wifi_not_ssid
  password: !secret wifi_not_password
  power_save_mode: none

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "${friendly_name} AP"
    password: !secret wifi_not_password

status_led:
  pin:
    number: GPIO2 #D4 #BUILTIN_LED
    inverted: True

captive_portal:

# Enable logging
logger:
  level: DEBUG

# Enable Home Assistant API
api:
  password: !secret api_ota_password

ota:
  password: !secret api_ota_password

time:
  # Sync RTC time with HA
  - platform: homeassistant
    id: homeassistant_time

binary_sensor:
  # HA sensor showing if device is connected
  - platform: status
    device_class: connectivity
    name: "${friendly_name} Status"

  - platform: gpio
    name: "${friendly_name} Raindrops sensor"
    pin:
      number: D7
      inverted: true
      mode: INPUT_PULLUP

sensor:
  - platform: wifi_signal
    name: "${friendly_name} WiFi Signal"
    update_interval: 60s

  # Reports how long the device has been powered (in seconds) since last reboot
  - platform: uptime
    id: sensor_uptime
    name: "${friendly_name} Uptime Seconds"
    icon: mdi:clock-outline
    update_interval: 60s

  - platform: uptime
    name: "${friendly_name} Uptime Sensor"
    id: uptime_sensor
    update_interval: 60s
    on_raw_value:
      then:
        - text_sensor.template.publish:
            id: uptime_human
            state: !lambda |-
              int seconds = round(id(uptime_sensor).raw_state);
              int days = seconds / (24 * 3600);
              seconds = seconds % (24 * 3600);
              int hours = seconds / 3600;
              seconds = seconds % 3600;
              int minutes = seconds /  60;
              seconds = seconds % 60;
              return (
                (days ? to_string(days) + "d " : "") +
                (hours ? to_string(hours) + "h " : "") +
                (minutes ? to_string(minutes) + "m " : "") +
                (to_string(seconds) + "s")
              ).c_str();

text_sensor:
  # Sensor with esphome version and fw build time
  - platform: version
    name: "${friendly_name} Version"
  
  # Extra wifi info from device
  - platform: wifi_info
    ip_address:
      name: "${friendly_name} IP"
    ssid:
      name: "${friendly_name} SSID"
    bssid:
      name: "${friendly_name} BSSID"

  # Uptime text sensor which is updated by the sensor id: uptime_sensor
  - platform: template
    name: "${friendly_name} Uptime"
    id: uptime_human
    icon: mdi:clock-start
    entity_category: diagnostic

button:
  - platform: restart
    name: "${friendly_name} Restart"

Then in the HA I’ve followed your guideline and created the counting and trend sensors. I’ve just added also the intensity sensor. I’m looking forward for the first rain!

Once again, thanks so much!

3 Likes

You’re welcome, thanks for sharing the ESPHome method :slight_smile:

This is brilliant! However I cant get my aqara door sensors to work reliable wirh my tasmota flashed sonoff zigbee bridge and HA :confused: i get them connected but they become unresponsive after a whole, so I doubt this will be working for me :frowning:

Oh that’s no good :frowning:

Do you have enough extenders/main powered devices near the aqara sensor?

I use a Conbee II with ZHA and have no problems

I actually placed the aqara next to the bridge for testing :frowning:

Cant rturn the bridge ad I flashed it already and dont want to buy a second one. Already have that one and Hue now already :smiley:

But technically it should work with any windows sensor where I can find the contacts, I think…?

Yes! But it should not have a debouncer or otherwise it wont work properly

Okay. However I would still prefer to get the Aqaras working… eill do some research, other people seem to experience dame problems with that bridge…

1 Like

I didn’t realized you can use an esp8266 for this. Have you fully tested with rain yet?

As long as the binary sensor works properly, it should work the same as the aqara sensor.
If it doesn’t, you’re probably able to tweak it with all the settings that EPSHome provides :slight_smile:

@duceduc Yes, it works properly with ESPHome. 5mm of rain this night :star_struck:

1 Like

Rain has never been more exiting

2 Likes

Got my Aqaras working, did a OTA update for the Sonoff bridge, now they work.

But ESP might be an option for me, too - cheaper and I have some lying around.

1 Like

It seems this happens for all zigbee sensors. They go to unavailable, then back to the last state. As a result, my automations run after a restart, same as with the rain sensor. There must be a more elegant solution then having to create inverted triggers for all (don’t get me wrong, great solution, but not sure i want to create one for every zigbee sensor.

Maybe for regular automations one would trigger on a state but not unavailable, and for something like this an inverted sensor would be the solution.

This line in the daily rain sensor will probably solve these issues

availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

Personally I’ve never had the issue