ESPHome water level sensor

I use the HC-SR04P with a Lolin D32. This ultrasonic sensor model runs on 3.3V and thus does not require any voltage divider. It fairly reliably measures a distance of ~2.5m from above my garage floor. However, this is not waterproof.

Has anyone had any with using water pressure sensors SKU237545? Here is an example of these:

3 Likes


So I went with cheap binary float sensors as a backup for my ultrasonic sensor as I do not trust its reliability to automate pumpsā€¦

4 Likes

@pangit when you are testing these (or any other ultrasonic ranging device) you need to remember that the sensing area is a cone shape with an angle of approximately 50Ā° for this type. So if you are holding it lets say 1 to 1.5 m above ground level and pointing it against a wall then the cone shaped sensing area will start to touch the floor level and/or the ceiling (and send significant reflections back) @ around the 1.5 metre range. Mounted in the centre of a tank say 2.5m high and 3.6m diameter you will be able to get quite accurate readings as long as the 25cm clear space can be maintained.

1 Like


If anyone wants to print a holder for their waterproof ultrasonic sensors atop a tank, send me a private message with your email. Iā€™ll send you the stl file for the one I designed so you can print your ownā€¦
Thanks again to @wellsy for his info.

1 Like

Nice design! These are my go to control deviceā€¦only thing these dont like is snails or debris getting trapped as the sensor opens or closes.

Now waiting for the tank to fill up so I can see how far from the US sensor the ā€œfullā€ binary sensor triggers. I had some false readings with these and had to add a delay in the ESPhome code:

binary_sensor:
  - platform: gpio
    pin: GPIO36
    name: "Water Low"
    filters:
      - delayed_on: 500ms
  - platform: gpio
    pin: GPIO32
    name: "Water Empty"
    filters:
      - delayed_on: 500ms
  - platform: gpio
    pin: GPIO34
    name: "Water Full"
    filters:
      - delayed_on: 500ms

Then again, since these are rated for 110-220V, am mighty glad they work reliably with the 3.3V Iā€™m throwing at them! 3$ a pop is good tooā€¦

1 Like

This shows how 4 of this type of sensor can be used to return both an approximation of the litres stored and also act as reliable control devices. This graph shows how I stop filling @ 800 litres and restart filling @ 400 litresā€¦the very end reading shows how I was shifting water to the main storage tank. All that is automated.

I like your delay you have built inā€¦there is a lot of bouncing around when filling is happeningā€¦Nice!

Funny, I was just adding these into Grafana. How do you get to display binary sensors like this in Grafana?


Idea is to superimpose the binary sensor atop distance values. Can think of making a template sensor, but may be too lazzy to do it right now!

1 Like

@monkey-house I convert the level change (on/off) to become an analog value in my PLC and then as the level rises past the first sensor the tank has 200 litres and then the second sensor has a value of 200 more litres = 400 litres stored etc, etc.

So my binary sensor becomes a very coarse analog sensor. Works for me!

I can see how you could most likely do the same with a template sensorā€¦have a crack!

Why not get with the open source ethos and publish them on thingiverse or github?

Cheers. By the way, you could set Grafana to do a linear progression between readings. If you use automations only between readings, it should give you a good estimate of how much water you got in there at time T rather than stepsā€¦

1 Like

Am all in with the Open Sourceā€¦ Heck, am here!
Then again Thingiverse needs to die IMHO. Itā€™s a total POS of a website.
If anyone needs the file, Iā€™ll send it FOC. Should have used the word ā€œgiveā€, I guess.

1 Like

Yesā€¦since HA + grafana I have considered that but I am quite used to seeing it as steps and it is sometimes good to see the time pass as it can feed me back information about my slow sand filters flowrate state.

1 Like

@monkey-house You could then use a comparison between systems to constantly check that the level is genuine and throw a fault notification plus halt any unsafe automation from running if you wanted?

1 Like

Yup, thatā€™s the idea. Waiting to get some data on empty, low and full values. Will then use a lambda into esphome to calculate percentage and a template sensor in ha for volume.
Already realised that my full binary sensor could have been placed higher. Changed my automation to wait 15 minutes after full sensor is on before turning pump offā€¦

1 Like

Since they are quite cheap and if you have spare inputs what about adding a High High level sensor for overflow protection at the correct level? Risky running blind just on a time value I think?

So, ok, i had some requests for this holder. Here is the link to Thingiverse: https://www.thingiverse.com/thing:3862489
Happy @nickrout?

4 Likes

Good on you (I know thingiverse is a PITA).

1 Like