Use Xiaomi temperature/pressure sensor as water tank level sensor

Whilst there are other water tank level sensor solutions kicking about (see edit below), I had an idea to try use a xiaomi temperature/pressure sensor . Note I think only the square Aqara ones do pressure.

I thought it was worth a try because:

  • I had one anyway
  • they are pretty cheap
  • it’s a battery operated solution with good battery life
  • you get water temp too as a bonus (as someone else pointed out)

My two use cases are:

  • use as coffee machine water reservoir sensor
  • use for my balcony irrigation reservoir water level sensor (this is basically a 15lt jerry can)

My dev waterproofing is a few layers of the fingers of latex and washing up gloves with knots tied in them (I had these on hand). Not sure how good that will be long term.
I also put a few coins in there as sinkers just in case it wanted to float.

My initial findings are:

  • the sensor does have the precision and range for the job
  • I think the size of the background variations in atmospheric pressure will pollute/affect the readings.
  • Looks like there’s some bedding in aspects, maybe when temperature stabilises (declining readings after first few ‘fills’)?

First chart: 90 days of pressure when the same sensor was on my balcony before it got repurposed)

2nd chart: Annotated with water level height (measured with ruler in 10LT bucket)

If anyone has any ideas on how to overcome this background variation issue, let me know. I guess one solution would be another sensor in ambient conditions then subtract the two for the water level reading?

Thoughts welcome.

Edit: 2020-11-20
Some other good threads on alternative level detection approaches (Ultrasonic, float switches)
Interesting.

Still waiting on required sensors to arrive because I forgot to actually order them:)

4 Likes

Very much rounding, 20cm of water is going to contribute about 2kpa. A standard Atmosphere is 100 kpa, although this varies with weather conditions - look at a weather map. The one I am looking at has pressure bars between 100.8 and 103.2. so atmospheric conditions will drown out your measurement.

Comparing pressure inside and outside the water is the better idea. But you’ll need to make sure the 2 sensors are well calibrated to each other.

1 Like

Thanks. I have another sensor on the way in snail mail. So I’ll have a go at a 2 sensor approach when it arrives.

How about instead of dropping the pressure sensor in the tank, put it in a camber that is pressurized by the tank and is also above the maximum water level.

If one was to plumb a pipe from the bottom of the tank, which would not need to be big, then run this to a height that was above the max water line then it attach to a close chamber that the sensor could be placed in, this should be able to read the pressure exerted by the water in the tank.

The plastic tubing used to plumb water lines to ice makers in refrigerator could be used. For the chamber a section of 110mm (4") PVC pipe with a screw on cap to seal it.

Two valves would be needed one where the pipe comes out of the tank to shut off the water from the tank and a second at the bottom of the tubing that would allow draining all the water out.

This way when starting the system or when you need to check on or replace batteries you could shut off the water and drain any water from the tubing. Once you have done your maintenance, closed the threaded cap and the drain valve, you could then open the water shut off valve to allow water to flow into the tubing to pressurize it.

Without this whenever you would open the threaded cap you would set the current water height in the tank to be equal with no pressure instead of the height when the tank is full.

You may still want to put your sensor in something to protect it from the wet environment but in this setup it would not be underwater if it sprung a leak.

Thanks for your thoughts and ideas , but I think that solution is more complex than I would like for my application (from my perspective :). For my use cases/solution, my main challenges are simple and effective waterproofing of the sensor (which I think should be solvable) and isolating the effects of background atmospheric pressure variations. I am curious if the solution you described is still susceptible to the latter?

Thanks @Mahko_Mahko for asking the question about barometric pressure affecting the pressure readings of water level in an open tank. I was on my list of items to research in any case. Here is what I figured out from my research.

TLDR; It depends on if you have the correct type of pressure sensor. Hint: a barometer is not the correct type. A gauge or differential pressure sensor will give correct readings, or one can correct the measurement of their in-tank barometer by subtracting the reading of a second barometer reading local air pressure from it in Home Assistant leaving only the pressure of the water column.

There are three types of pressure sensors: absolute, gauge, and differential. The difference is their reference pressure

  • Absolute - absolute zero pressure (a vacuum on the sensor)
  • Gauge - atmospheric pressure (has two ports but one is normally just a hole)
  • Differential - has two ports and gives the difference in the pressure between the two.

More information: Absolute Pressure vs Gauge Pressure vs Differential Pressure Measurements

To make this a bit confusing a barometer is reading local air pressure relative to absolute zero pressure. So a barometer is an absolute pressure sensor.
More Information: What is absolute pressure?

To measure the volume of water in an open container and not have barometric pressure affect it you would need to use a gauge pressure sensor. Why is this?

With an absolute pressure sensor it is comparing the pressure to a vacuum on the chip, 0. The pressure from the water in the tank plus the air in the atmosphere on top of it exert pressure on the sensor that gets measured relative to 0.

With a gauge pressure sensor and the differential sensors, you have two ports on the sensor. On the gauge sensor one is just a hole while on the differential sensor both will have ports to attach to the containers with pressure to be compared.

The gauge sensor measures relative to the current barometric pressure, thus eliminating the influence of the atmospheric pressure on the sensors reading and in our application of measuring water in an open tank only reads the pressure that the water exerts on the sensor.

However you cannot seal a gauge or differential sensor in a bag, rubber glove, etc and put it at the bottom of your tank. The second port has to be exposed to the atmosphere to get the correct reading. You would get no or weird reading doing this. (I actually found a Youtube video of someone that did this not realizing how they work.) The reason it works with your barometer is because it is comparing the pressure to an internal vacuum on the pressure sensor.

@Mahko_Mahko The other solution to the issue of barometric pressure affecting your readings, by possibly around up to ~ 30 cm, is to have a second barometer reading the local air pressure then subtract this from your barometer’s reading at the bottom of the water tank in Home Assistant. But I see from this forum thread that you have already surmised this to be the case.

As to water proofing the barometers you have, in the past I have seen cases of various sizes to take to the beach or lake made of plastic that have a rubber seal and snap latches to put items in that you do not want to get wet. I have to wonder if these would work and make it easier to change the battery when need be. I have to wonder if condensation could also be an issue too. Maybe save the silica gel packs that come with stuff to keep it dry and add one to the case before submerging.

AdaFruit makes a ported absolute pressure sensor on a breakout board with I2C but this is an absolute pressure sensor. I want to find a gauge pressure sensor that has I2C and pair it with an ePaper display that has a ESP32 chip. ESPHome list this display on its Waveshare E-Paper Display (esphome .io / components/display/waveshare_epaper.html) page in the first paragraph as the 2.13” TTGO module. However my application is for a large rainwater storage tank. I understand that with the ultrasonic sensor that over 2 meters the reading tend to be unreliable, which in this use case is where you most need them to be reliable as you get closer to the bottom of the tank.

1 Like

Here is a link to a very good video about how to choose and setup an ultrasonic sensor as a level gauge. It explains the basics principals.

However I see that Home Assistant has support for Time of Flight sensors that use lasers to measure distance.

These do not cost much and have a four meter range and use the I²C interface for communication. I think that combing one of these with either a ESP32 or a ESP8266 would be a good setup.

I found this article VL53L0X Time-of-Flight sensor and ESP8266 with a working example to measure distance.

In its description it says:

Can be hidden behind many cover window materials

So even though it is not water proof it looks like it should not be too hard to make a box for it. The documentation also says:

uses ST’s latest generation ToF technology which allows absolute distance measurement whatever the target color and reflectance.

So it looks like using it to measure water height should not be an issue.

ESPHome lists the VL53L0X which only has a two meter range but the VL53L1X has a 4 meter range but use a different API. Polou that sells both on break out boards has libraries for both on GitHub (VL53L1X library).

ESPHome currently does not support the VL53L1X, but I have filed a feature request asking to support it. It maybe just a matter of switching out the libraries to support the different APIs.

1 Like

I actually have a VL53L0X that’s been sitting around that I’m intending on using with Esphome. I’m still waiting on my Aqara sensors, which I thought I ordered but didn’t (!), but are now in snail mail. My prototype waterproofing failed after about 6 weeks, so will have to rethink that (interestingly the sensor was fine after it dried out). I’m still keen on the my pressure sensor solution due to simplicity, easy power supply, easy to mount etc. I’m thinking about giving the sensors a dip in aquarium grade silicone for next waterproofing attempt.

How about this one?

UART/PWM 3-450cm Ultrasonic Sensor Probe Module Waterproof Ranging Sensor Distance Sensor

I have tried normal version(HC-SR04) with some hot glue and nail paint but it died after a month probably due to humidity
Then another waterproof version(JSN-SR04T) but it’s minimum range is low and sometimes shows false readings
It’s waterproof but shows correct data only when its out of water, inside water gives random readings
Will try this new one later…

Interesting. But there are some other good threads on the ultrasonic (and float switch) approaches.

My additional sensors arrived a while back and I finally got around at “waterproofing attempt take 2”, which involved some very small glass dishes (which provide good water proofing assurance on those surfaces) sealed in with aquarium grade silicone (there’s a bit of debate around whether that is food safe). Obviously replacing batteries is a bit of a hassle with this approach, but I thought I’d give it a go… I think the water proofing is pretty solid.

But I think I’ll abandon the idea as I found that even with a “control/calibration device” the variation between devices (production/sensor quality?) and changes in pressure that I think are caused by temperature changes of the sensors micro-environment and the “ diaphragm effect” of the new water casings renders the approach unusable.

You win some, you lose some.

unnamed

so what’s your next approach ? or live with it ?

I think I’ll abandon the pressure sensor approach, and maybe have a go at using this technique of hacking a Xiaomi door sensor with a float switch.

Still battery operated, but you only get a binary measurement and it is intrusive on the water tank (needs to be plumbed in).

https://www.aliexpress.com/item/32894861981.html?spm=a2g0o.productlist.0.0.a5aecf1bFQjfz6&algo_pvid=c38b6654-e0b4-4975-b3c2-e22db5a722de&algo_expid=c38b6654-e0b4-4975-b3c2-e22db5a722de-12&btsid=0b0a555516124727106762580e0616&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

In the meantime, I’ve also created a method to sense the water level of my (rain)water well.
It’s using a pressure sensor approach, all seems to work fine and integrates in home assistant.

See the detailed explanation here:
https://github.com/goosst/WaterLevelDetection

1 Like

Nice! Looks very interesting. Sensors seem a little pricey though?

I take it these sensors somehow aren’t susceptible to background atmospheric pressure (wasn’t immediately obvious to me at a quick read).

Nice! Looks very interesting. Sensors seem a little pricey though?

The price of the sensor seem to have increased significantly compared to the moment I bought it …

I take it these sensors somehow aren’t susceptible to background atmospheric pressure (wasn’t immediately obvious to me at a quick read).

It’s a good remark indeed, I’ll add one of those cheap barometric sensors to my little PCB for monitoring and compensation.

1 Like

Might be worth putting your eyes on how the “compensation sensor” and the master sensor “move together” without any water present and calibrate on that.

I found in my instance that the difference in their measurements rendered my control device ineffective/inaccurate. But I think it might be better with your use case as I was trying to measure small depths (0 ~ 30cm), so variation due to atomospheric pressure is likely smaller relatively to variation in water level?

But I think it might be better with your use case as I was trying to measure small depths (0 ~ 30cm)

If you can add a tube and want to tinker, a (selfmade) capacitve based sensor would probably be better for this depth/needed accuracy … (and with some relatively constant temperature)

1 Like