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.
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.
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.
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.