Rain Gauge - How to total / increment reed switch

Hi there

I’ve modified my Oregon rain gauge and soldered wires to the reed switch which I’ve then connected to VIN pin and D8 pin on a nodemcu board and using ESPhome with the intention of it recording the amount of rainfall over time.

I’ve set it up using the pulse_counter platform however the issue is that the pulse_counter acts like a counter per minute giving you the number of times the switch is toggled in one minute but then resets to zero after a minute and starts counting again for the next minute, what I need is for it count each time the switch is toggled and increase it by that count so that I am then able to measure rain fall by hour, day, month, year etc…

Is there a way to count and store this information in Home Assistant?

I’ve searched the forum and have come across similar scenarios but haven’t really seen any examples of a reed switch being used to count, its either open or closed and doesn’t need to be accumulated.

Thanks in advance.

sensor:    
  - platform: pulse_counter
    pin: D8
    name: "Rain Gauge"
    icon: "mdi:water"
    unit_of_measurement: "mm"
    accuracy_decimals: 2

image
image
image

Would it be possible to just set it up as a switch and let home assistant trigger every time that switch changes state? Then you can have an automation that counts up the rainfall in home assistant instead of doing the counting in the MCU.

One thing to check is how much rain is in each pulse and what is your highest expected rainfall, to determine if a switch solution is fast enough.

Well for a start Vin is 5V and you are connecting this to a pin that is only rated for 3.3v.

Secondly there is a note on the pulse counter document page that tells you exactly what to do:

Note
See integration sensor for summing up pulse counter values over time.

I suppose this is possible, I’d prefer not to have to setup an automation to do the counting but if its the only option then I can live with it.

Sorry I meant V+ i.e. 3.3v not Vin, I’m running on a battery so input isn’t 5v…

I missed this in the documentation, let me try add the sensor and see if it helps.

Thanks

I’ve spent some time on the integration platform and getting some weird results…

I confirm by the logs of the MCU that we’re getting a reading of 1mm each time the reed switch is toggled so my input data is correct. The integration sensor is increasing each time the switch is toggled BUT not by 1, typically it will increment by 5 but is inconsistent and sometimes increments by 30 for example even though both in the logs and the pulse_counter the increment is 1.

The integration sensor also seems to be only time based so I suspect its expecting time input, I’ve tried dividing by 6, 60 etc… but the data is display data is still not consistent.

image

Extract of my configuration.yaml

  - platform: integration
    name: "Total Daily Rainfall"
    source: sensor.rain_gauge
    unit_time: s

Can it be related to contact bounce in the reed switch? There is a filter feature in the counter you can try to ignore short pulses and see if it helps.

No definitely not, as mentioned the data coming out of the MCU is perfect without any spikes, the issue is on the sensor side its definitely doing some sort of time based increment, I noticed yesterday that if the switch was toggled after an extended period of time i.e. hours one toggle would increment the counter by thousands, I suspect the counter is working in seconds.

Below are images of the sensor as of last night and then this morning after a single toggle.

image
image

image