Water Tank Level and Water Volume with ESPHome

Did you get the timeout issue resolved? By default the pulse time used for Ultrasonic sensors is 10usec whereas these sensors need 20usec (from the spec sheets). I changed this parameter plus the timeout parameter (default is 2.0m), but I was getting erroneous readings with the HC-SR04 above 1.80m.

Full details here ESPHome water level sensor - #190 by Britespark.

No timeout errors since I made these changes months ago. Still to resolve in code the random readings I get when it’s actually raining (so the water surface is rippled) which really mess up the charts (negative levels and percentages creep in), and temperature stabilisation (tank level inflates a few percent through the day as it gets warmer).

Thanks, I didn’t know about the pulse time though it is in the docs I didn’t think to try it. I’ll give that try. Thanks for that. My tank is way smaller that 1.8m.

Hey, that seems to be working now. Thanks a lot.

No drama - glad to help.

1 Like

would you mind sharing your code because i’m getting exactly the same problems as you, me it’s 0.25m… kinda stuck on that number almost…

thanks

Remember de JSN-SR04T has a minimum measuring range which is about 20cm

BTW, here’s my code:

sensor:
  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    name: 'Nivel cisterna'
    unit_of_measurement: 'm'
    accuracy_decimals: 2
    update_interval: 10s
    pulse_time: 20us
    timeout: 2.0m
    filters:
      - filter_out: nan

After a month of stable operations (still to resolve temperature-based variations, and stable readings when it’s raining), my level sensor started playing up two weeks ago - often reading a distance greater than the height of my tank, frequent time-outs, etc. I figured I had a moisture or corrosion problem, but after replacing the Wemos D1 mini and the sensor board and sensors…same problem!

My fix? Upgrade ESPHome and HASSOS to current versions. I was running 2021.08 versions, not on 2021.10 and everything seems good.

I’m using the JSN-SR20 (samre as HC-SR04 with 2x waterproof sensors), it has a much better range than the JSN-SR20:

Specifications and parameters :

pulse output the serial output
working voltage DC:3.0-5.5V
working current <8mA
the probe frequency 40kHz
the farthest range 500cm
recently range 2cm
long-distant accuracy ± 1cm
resolution 3mm
measurement angle 60 degree
the input trigger signal 20us

My code (assumes tank height is 200cm):

  - platform: ultrasonic
    trigger_pin: D7
    echo_pin: D6
    timeout: 4m
    pulse_time: 20us
    update_interval: 60s
    name: "Water level"
    unit_of_measurement: "cm"
    accuracy_decimals: 0
    filters:
    - filter_out: nan
    - sliding_window_moving_average:
        window_size: 10
        send_every: 5
    - lambda: return (200 - (x * 100));

I do multiple readings / calls presently, to return other calculations for litres and %full. I’d guess there’s an easier (smarter!) way to do this but I’m learning as i go!

Has anyone the solution of implenetation two ultrasonic sensors in different tanks on one esp32/8266?

Maybe you could use two different GPIOs on the same board for the trigger and echo pins on the sensor

I’m trying to do this to measure a sump pit because I want to know if my pump fails before its too late.

I’m using a d1 mini as my MCU and the same sonar sensor as everyone else.

I have the following sensor code

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO5
    echo_pin: GPIO4
    name: "Water Level"
    icon: "mdi:water"
    update_interval: 30s
    unit_of_measurement: "%"
    accuracy_decimals: 0
    timeout: 3m
    filters:
    - filter_out: nan
    - lambda: return ((((x*100)-10)-(76-10))/(76-10))*-100;

Right now in the winter my pit is almost completely empty there is a little bit of water down there. The sensor however is reporting in that the pit is at 80%. I’ve drilled 2 different holes into the lid of my pit to try and figure out if maybe the sensor was hitting off of something else in there but I don’t think thats the case. I live in the US but I converted all of my measurements over to metric for this. My pit is actually 76.2CM deep but I knocked off the decimal and I figure that the exclusion distance is about 10CM which is about the highest level I’d ever like my water to get in that pit anyways. If it ever got above 70% I’d be worried. Thank you all in advance for your help with this.

And, have you confirmed that the distance measurement is working in prinicple? For example tried the sensor outside of your pit just against a wall? And if installed in the top of the pit, is the distance measured correctly in metres (i.e. without that lambda conversion)?

Please note that the sensor is still returning the actual distance, it just can’t measure correctly if the distance is outside its operating range, so in your case you would expect values up to ~0.76 metres.
You could then simplify the lambda:

   - lambda: return (0.76 - x) / 0.76 * 100;

Yeah I sit here at my desk with it and point it at various things in my office :smiley:
So I took your code and its now returning that its 70% full which is still not right so I’m still poking around at it trying to determine what its issue is. Thank you for your help this.

ok so I think I figured out my issue. The minimum reading for the sensor is 23cm and with my tank being 76cm deep I think that I’ll either need to change over to the other ultrasonic sensors or see if there is some tweaks I can make to my formula to get a better reading.

EDIT: This is what happens when I work until some odd hour in the morning and my mind isn’t firing on all cylinders. The min reading has nothing to do with my tank depth ugh.
So still attempting to tinker with settings for this thing but its still reporting in that the measurement is 0.23m regardless of where I put the sensor inside of the pit. I’ve tried to lower it down to see if it would change, I’ve held it above the pit and that changes the value but there is something that is causing it to report 0.23m once its placed inside the tank regardless of where its at.

I haven’t tried this myself, but some people try to overcome the minimum measuring distance by adding a cone like this: Waterproof ultrasonic sensor (JSN SR-04T) holder for water tank by Monkeyhouse - Thingiverse

However, this may still not help with your immediate issue…

yeah I’ll have to get my direct drive on my printer fixed (having issues not feeding the filament) and print one of these and give it a whirl

Hi all… Can you helm me somebody? I’m using ultrasonic sensor HY-SRF05 with ESP8266 i see only this Ultrasonic Sensor’ - Distance measurement timed out! I red this topic, but no clear answer. This is my config:

# Example configuration entry
sensor:
  - platform: ultrasonic
    trigger_pin: GPIO01
    echo_pin: GPIO02
    name: "Ultrasonic Sensor"
    pulse_time: 10us
    update_interval: 5s
    accuracy_decimals: 2
    timeout: 4.0m
    filters:
      - filter_out: nan

I tried different timeout, pulse time, but nothing work… Any idea?

got a question more on the display side…

whats everyone doing, would be great to have a image of tank outline shown and then fill it based on % value passed in.

I’ve gone the RPi route with a HC SR04 sensor, with Python, pushing my values to mqtt (to be consumed by HA) and then also into a InfluxDB, which I can display with Grafana if I want to.

G

Hi Guys ,

i need help with the setup referred above … i did the exact similar setup but the voltage value vary huge at different time of the day these below are the values i set the ESP home and before deciding to map each voltage to level i took the average value from 100 voltage levels at each stage as mapped below in the yaml
How can i make this sensor value report more accurate i feel that 50% of the time its not accurate even when the water level is stable or when water flushes inside the tank .

- calibrate_linear:
          # Measured value of X volt maps to y cm
#          - 0.0 -> 0
          - 0.963 -> 0
          - 1.36 -> 7
          - 1.455 -> 10
          - 1.633 -> 15
          - 1.711 -> 20
          - 1.779 -> 25
          - 1.831 -> 30
          - 1.882 -> 35
          - 1.938 -> 40
          - 2.049 -> 45
          - 2.129 -> 50
          - 2.206 -> 55
          - 2.268 -> 60
          - 2.367 -> 63.5

I am currently trying to figure out how to use this sensor. It does not work for me it seems to work for other people. Seem too many unknowns. I have a 2meter tank and when the water is VERY low it gives me a max reading of 1.1 instead off 1.87. So it seems reflection, tank diameter, and construction all play a role. Have to find another way to monitor levels.

1 Like

try relative pressure. That does not have so much problems with those limiting factors.

1 Like