I bought a rain gauge from china, just google “rain gauge sensor aliexpress” for the product, it was round about 15€.



For my test-setup, I simply cut off the connector and connected the wires directly to GND and GPIO4 and used the internal pull-up resistor:

Adding it to esphome is straight forward and easy. I’m using the pulse counter component, it can use the pulse counter peripheral of the ESP32 and can work in standby-modes:
substitutions:
update_interval: 5s
sensors:
- platform: pulse_counter
name: "Rainfall Pulse Counter"
id: rainfall_pulse_counter
use_pcnt: true
count_mode:
falling_edge: INCREMENT
rising_edge: DISABLE
pin:
number: GPIO4
inverted: true
mode:
input: true
pullup: true
unit_of_measurement: "mm"
icon: "mdi:water"
update_interval: ${update_interval}
filters:
- multiply: 0.367
- debounce: 10ms
total:
name: "Rainfall Total Pulses"
The value “0.367” is explained here:
https://community.home-assistant.io/t/how-to-measure-integration-of-rain-pulse-counter-into-daily-value/136709
Then I created two utility meters that convert it to a daily and hourly basis within homeassistant like this:
