Problem
Spring 2023 Update See below
A couple of years ago, the sump pump in my basement backed up after some heavy rain, and the basement flooded with several inches of water. Needless to say, this was not an experience I wanted to re-live, so I installed a backup pump and replaced the partially clogged drain pipe on the outside of the house. However, these measures were not enough to keep me from becoming very anxious anytime it rained heavily - you might say that it left me in a sump pump slump.
I started thinking about ways that I could monitor the water level in the sump pit, perhaps even track it over time, to see if the data could allow me to enjoy the sound of rain on the roof again. Thinking back to my college experience with ultrasonic sensors, I figured I could mount a sensor in the pit, write a little code, and send the data to an InfluxDB database in my homelab. I custom-designed and 3d printed a chassis for the sensor, mounted it, got the data pushed to the DB and… I kept getting inconsistent readings. My theory is that the sound waves got deflected off the other objects in the pit too regularly and would confuse the sensor. I tried compensating by slowing the polling rate and averaging readings, but to no avail. The data was good enough to see when graphed, but was consistently inconsistent enough to prevent other analytics.
It was some time later that I discovered a pack of cheap float sensors on Amazon and inspiration struck me again. I realized that I could mount the switches at different “intervals” and thus monitor the water levels that way. I designed and printed another mounting system (.stl file here), and wired up the switches to the raspberry pi using some ethernet cable and interfacing with a couple of extra keystone jacks I had lying around.
After installing the new sensor setup in the pit, I updated the code to account for the new sensors.
With the float switches, I was able to poll at a very high rate, trading water level precision for timing precision, accuracy and reliability. The data also turned out to be very consistent, and I was able to easily distinguish when the sump pump ran, and determine other information from that. I figure if the discharge pipe ever gets clogged, I’ll start to see an increase in the time that it takes to empty all of the water from the pit.
The python code is not fancy, but it works. I’ll leave it below in case someone wants to attempt a similar project of their own.
Click to show code
Spring 2023 Update
Since writing this, my primary sump pump failed again, and so I put in a name brand pump as a replacement, and the float switch assembly no longer fit in the pit with how the new pump was set up. I stumbled upon this writeup and have since implemented it, though I’ve already had to replace the depth sense already. I think the issue was with the water getting grimy - chlorine tablets seem to help. Because the controller uses an esp32 chip, it was easy to modify the configuration to include a few extra calculations that then automatically sync back up to Home Assistant (without having to go through an intermediate InfluxDB).