Hey community,
I wanted to measure my stormwater soak-drain changes (rises quickly, falls slowly, does it overflow?), and solve a rain-water tank problem measurement for a relative.
Journey
There’s a dearth of good water/liquid depth sensors that are pre-integrated into esphome, and certainly none pre-packaged that’ll measure levels that I could find. I think this is mainly because it’s a hard problem to solve in a general sense (how deep, which liquid, etc), but also because the best sensors out there for this purpose are non-trivial to connect to (powered, analog).
I chose the 4-20mA variant sensor immersion sensors after reading way too much here and elsewhere (ultrasonic dead zones, waterproofness, ripples etc and trying to solve for both my use cases). On my research journey I found integrations for current sensors directly onto esp32 boards that required discrete circuitry, but that plus getting the (recommended for this sensor) 24v near the esp32 didn’t seem like a great idea. There are also super-cheap (like $5) industrial sensor->RS-485modbus modules though that can take 2(+) sensor inputs, and are designed to be permanently installed and robust to mistreatment/lightning/etc. So I took that option.
Then there’s RS-485 which has been around forever but I’d not appreciated it as useful for IoT until now. There also esp32 integrations/sub-boards for RS-485. And then there’s the Lilygo T-CAN485 which has an nicely isolated RS-485 interface on it already, and means I didn’t need another board. They do other boards with RS-485 too, but every single one is different.
For this project I decided that the water sensor could be remote, and the esp32 etc could be further away from the water, and then just running 12v to it would be easiest.
Materials
(no affiliate links, but links might be country-dependent)
There are many liquid sensors of this submersible kind. Not all are equal (reports are that some rust) and I believe this store is the OEM and not a re-reseller. These sensors are quite a bit bigger and more hefty than they look in the photos. Ensure the cable length is long enough as it’s got a pressure-equalisation tube inside it that needs to be kept out of the water(discussed above), I guess they can be cut down (but I didn’t) but extending could be problematic. They want 24v but will apparently run on 12v.
Pictures
Testing in my water bottle.
Sensor, 18650 for size reference
Sensor is quite heavy.
Installed, working, with ferrules even. Cable management could be better…
esphome configuration
Modbus configuration of the T-CAN485 board is a little annoying and was undocumented outside of the Arduino examples. It works though, just needs some pins flipped high. Feedback welcome…
Full yaml here
Got the RGB LED working properly too.
Results
It verks!
And installed and on a dashboard.
Final Thoughts
I like using these off-the-shelf components. They’re robust although not that space efficient. I am thinking about why I don’t have an RS-485/modbus bus loop around my house now too. I have no real-world experience with it yet but now I see why there is an RS-485 version of my weather station (Ecowitt), and it looks like I could loop in my aircon and solar inverter too.
The industrial 4-20mA current sensor approach is something I’d do again for remote sensors because after the “why did they make it so complicated?” thoughts subsided I realised that this range stays ~static regardless of the length of the wire to the sensor (unlike say 0-5v), and probably other good reasons too. It’s clearly not a low-power (uA) consumption approach though, so you do need a stable power source. Once 4-20ma sensor integration is solved for one type we can apply this to other types of sensor like this as well as well…
The “12 bit” RS-485 sensor converter is using less than 12 bits because it uses 2621 values for the 4-20mA range of the sensor, which is not 4096 (12 bits). Still enough values for sufficient precision for my purposes. Docs went through Google Translate fine. Can’t beat the price, and there’s space for another sensor.
The sensor is (a few days in) awesome. Came well packaged, calibrated to the values engraved, and just works. It will take some years to prove them out completely, but it looks like the real thing. I could have ordered the RS-485 version (and avoided a box), but I these are more common and replaceable. Seems ~stable across temp and barometric changes at least within 2mm change.
The case probably needs a vent as so the barometric compensation works properly, but it’s not wildly varying (my XT60 hole may be providing this). I’ve ordered some cable glands with vents…which are a thing. TIL.