ESPHome water level sensor

Thanks @sparkydave and @A320Peter this is good to know for version 2.0.

Just FYI that was because the offset was applied before the multiplication. I’m not sure if the filters are applied in the order they are listed or by some other random method. That’s why I also listed the lambda version.

1 Like

Eg this confirmed it works with and arduino so should be fine:

pressure sensor

You should consider which type you need based on the size of the tank but for home usage usually 5-20 psi is more than enough.

1 Like

Hi folks,

I’m doing the same thing - as winter draws to a close here in Australia, focus returns to the amount of water in the tanks.

I was hoping I could get an explanation of the values supplied by @tom_l in the first reply?

If my tank is 1.8 meters in height, and the waterproof ultrasonic emitter can only read from 20cm above the surface - what would the values be? How do I read what these values (114.94 & 128.74) represent?

I’ll be working out what my total storage value is, so I’m looking to additionally calculate what 1% of the tank would be - then show how many litres used/collected in a day based on the percentage fluctuation.

Thanks folks!

Brendan

I think I may have nailed this myself:

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s
    
  - platform: ultrasonic
    trigger_pin: GPIO5
    echo_pin: GPIO4
    unit_of_measurement: "%"
    icon: "mdi:water-percent"
    accuracy_decimals: 0
    update_interval: 5000ms
    name: "Water storage"
    
    # tank height: 200cm
    # height from full to sensor: 22cm (essentially sensors minimum distance)
    # full tank: 180cm
    # current reading: x
    # ergo: used = (x - 22)
    # ergo: remaining = (180 - used)
    # ergo: percent = (remaining / 180) * 100
    
    filters:
      - lambda: return (1-((x-.22)/1.8))*100;
      - filter_out: nan

Seems right math wise. Let me know your thoughts.

6 Likes

I’ve been trying it out with one of the cheap HC-SR04 sensors. When testing it against a wall It only works up to about 1.5m (even though the spec sheet says up to 4.5m). Has anyone got one reliably working up to 2m or so?

Not sure who advertised it as 4.5m. Most sites have this sensor listed as only having 0.4m range.

The same Chinese websites who tell you 18650 cells have a capacity of 9000mAh! Lol. So I’m after a different one that has practical range of up to 2m, preferably waterproof.

The data sheets I have been able to find say 400cm, which is 4m. https://www.electroschematics.com/wp-content/uploads/2013/07/HCSR04-datasheet-version-1.pdf

EDIT: then again, this one says 5m. FIIK. https://www.electroschematics.com/wp-content/uploads/2013/07/HC-SR04-datasheet-version-2.pdf

1 Like

Well that was dumb. In my defence I… got nothing.

1 Like

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