Water Tank Level and Water Volume with ESPHome

Hi Nawafbana

Thank you for posting this. I’m a bit of a newbie and while I have a level sensor set up and measuring I have tried to compile the sketch you posted but fail.

Can you please tell me how you compiled the sketch.

Thanks in advance

Tony

Can someone help make my formula perfect?
I now have my new/“almostfinal” setup finished (sensor hooked up, tank, pumps, tubing flow sensor & flow limiter all in place.
Maybe someone can help me to make it even better.
so here are my infos:

  • EX: 8cm (sensor to max water level)
  • TD: 46 cm (empty bottom of tank)
  • TC:72 Litres (44cm deep (36cm max water level) by 40cm wide by 50cm long tank)
  • Minimum water level (so the pump is still submerged): 13 cm

I still get a 1% error and almost 1 litre error (not so bad but not perfect)
this is the empty tank snapshot:

Screen Shot 2021-04-27 at 12.39.26 AM

heres my code:

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Sensor"
    update_interval: 60s

  - platform: dht
    pin: GPIO 13
    model: dht11
    temperature:
      name: "Temperature_01"
    humidity:
      name: "Humidity_01"

  - platform: ultrasonic
    trigger_pin: GPIO 5
    echo_pin: GPIO 4
    name: 'Water tank Level'
    unit_of_measurement: '%'
    accuracy_decimals: 1
    update_interval: 1s
    icon: mdi:water-percent
    filters:
      - lambda: return ((((x*100)-8)-(46-8))/(46-8))*-100;
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.05 #only send the result if the level difference with the last sent result is higher than this
      - filter_out: nan
      
      
  - platform: ultrasonic
    trigger_pin: GPIO 5
    echo_pin: GPIO 4
    update_interval: 2s
    name: 'Water Tank Volume'
    unit_of_measurement: 'l'
    icon: mdi:cup-water
    accuracy_decimals: 2
    filters:
      - lambda: return ((((x*100)-8)-(46-8))/(46-8))*-70;
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.05 #only send the result if the level difference with the last sent result is higher than this
      - filter_out: nan

Thank you in advance for the help, also i want to give big thanks to everyone in this wonderful community for all the help and learning opportunities!

2 Likes

not a sketch (arduino) its done using esphome…

Thank you very much for nice project. Everything done like described. Everything is working, but… till power-cycle. After power cycle ESP not booting. Only reset (RST–>GND) help to boot again.

my config posted here was working and just stopped out of the blue, now the numbers are all off, and random it seems… connection times out… the whole thing just broke !

what can i do?

I need this for my installation!

So I finally got around to installing this yesterday. I installed sensors on an 800 gal and 400 gal tanks. Here are some pics of my setup.

I also did a sensor calibration at different depths and noticed that as you measure further from the sensor the delta error increases (see table below).

Does anyone know how to apply corrections to output for errors that vary (maybe in lambda function)?

Calibration

3 Likes

Just in case people in this topic haven’t seen it.
As an alternative you can use a pressure sensor. You just throw it in your water tank so that it drops to the bottom and for me it measures the water depth with a precision of about a millimeter!

3 Likes

Cool! A bit pricey but looks like it gets the job done.

Really!!! I cant seem to be able to figure out how to make it work for me!
would you mind sharing that part of your config, i’ve been pulling my on this for days now!
got this model:

using a nodemcu for this

  - platform: pulse_counter
    name: "Flow rate 1-2"
    id: water_flowrate
    pin: 13
    update_interval: 1s
    filters:
    - lambda: return (x / 96.0);
    unit_of_measurement: "L/min"

thank you in advance

I think we’re talking apples and pears.
You are looking for a solution that can measure flow rate.
What I am using is a solution that can measure pressure differences and translate that into water levels (how much water is in the tank).

i posted the wrong code, i have the pressure sensor
and i want to get the volume or at least the percentage of water in my tank…

here’s the right code… its not giving me the plausable results but its my presure sensor code:

  - platform: adc
    pin: A0
    name: "water pressure"
    update_interval: 2s
    unit_of_measurement: "psi"
    icon: "mdi:gauge"
    accuracy_decimals: 1
    filters:
      - multiply: 5.0
      - lambda: return x*43.75-21.875;

my code is wrong and it gives me only psi…

:frowning: i am sort of a newbie in esphome and i could take all the help because ,my grow is ongoing and this isnt working and its not good…

thanks!

I just got the dfrobot weatherproof ultrasonic sensor in replacement for the HC…

would you mind sharing your config, i want to re-start from someone elses config, i need to get this working asap.

thanks

Sure, here it is

esphome:
  name: tank1_water_level
  platform: ESP8266
  board: esp12e

wifi:
  ssid: "HomeWiFi"
  password: "************"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Tank1 Water Level"
    password: "*************"

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: "**********"

ota:
  password: "**********"

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO16
    echo_pin: GPIO14
    name: "400 gal Water Tank Level"
    unit_of_measurement: "%"
    accuracy_decimals: 4
    update_interval: 1min
    filters:
      - lambda: return ((((x*100)-27.5)-(150-27.5))/(150-27.5))*-100;
      - filter_out: nan

  - platform: ultrasonic
    trigger_pin: GPIO16
    echo_pin: GPIO14
    name: "400 gal sensor measurement"
    unit_of_measurement: "m"
    accuracy_decimals: 4
    update_interval: 1min

Thanks!
I got it working with my exact old code in the end, was the damn sensor

are you using pressure sensor as a second backup method?

1 Like

No, no backup. Its not mission critical so I just have this one to show the remaining water in the tank.

My code is a bit different, but I’m using a dedicated ADC (costing around $1) because it is much more precise.

Here’s the bit of code I use to get the voltage reading from the ADC:

sensor:
  - platform: ads1115
    multiplexer: 'A3_GND'
    gain: 4.096
    id: zwemvijver_voltage
    name: "zwemvijver Level Voltage"
    icon: 'mdi:swim'
    unit_of_measurement: 'V'
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - sliding_window_moving_average:
          window_size: 10 #creates a moving average of the last 10 values
          send_every: 1 #sends the moving average at every measurement (but only if it passes the delta filter below)) 
          send_first_at: 1 #after startup immediately start sending the result rather than wait for the first 10 measurements
      - delta : 0.0015 #only send the result if the voltage difference with the last sent result is higher than this

I then have a lot of code to transform that voltage into centimeters, liters, percentage etc but first step for you is to make sure you get the voltage reading from the ADC :wink:
I believe I put the rest of my code in the other topic for which I shared the link earlier.

1 Like

I just got an ADC will try this .

by the way would you mind just confirm the wiring you used for your ADS1115/1118?
it’s going to be the first time I sauder such small board.

thanks

same for me

Here’s my set-up. As you can see I have multiple pressure and temperature sensors hooked up to my ESP8266 so it looks rather complex. The ADS1115 is in the upper left corner.

On some of the components you will see some short strands of wire that lead to nowhere? That is because I changed my design many times to get to the final design and I was too lazy to try to remove the wires on these components.

1 Like

I want to have a backup because i live on the 3rd floor and if theres an overflow or anything i want to be as safe as i can be, plus im curious as how that works.