Water Tank Level and Water Volume with ESPHome

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.

I got this working (getting Voltage readings) I used your config except I am using A0_GND as my output.
I do have a question about the config.
where and why did you choose that gain number exactly?

so I have done like youève asked and colected voltages at different quantities of water in my small tank
here they are:
10l: 0.621v
15l: 0.634v
20l: 0.649v
22l: 0.663v
32l: 0.689v
40l: 0.7v
50l: 0.715v
52l: 0.720v
65l: 0.718v
70l: 0.730v

numbers seeb to not be logical some yes some no… but maybe it needs some time in the water to adjust and be more stable (i’ve read some places that it need’s 24hr)

anyways, so from that how do I get a percentage or volume (max is 70L)

Thanks

Thanks, its the exact same formula I was using, i re-used my old one and it’s now working with the new sensor.

Yes the reading for 65l is strange indeed!

For the next steps: have you had a look at the code I shared in the other topic?

For the gain factor: have you read the ESPHOME documentation for the ADC you bought and the documentation of the manufacturer?

i got no documentation from manufacturer, none was available. And no, i didn’t read any documentation symply because i didn’t find any…
I did but i still am not so sure about what would be the code, I’m actually reaaly bad in maths. I mean that type of maths specially… I should have listened better in high school!
:wink:

It’s really easy: go to your favourite search engine ands search for ads1115 esphome
The first result should be the esphome documentation.

I thought you were talking about the pressure sensor!?
Of course i’ve read that documentation, but again I am using a 1118, and not much documentation. I was told they were the same …but they are not… i found my way though.

i think that i would get better results if I could get more info about the actual sensor, the pressure sensor!

;’)

Yes it would be good if you have the documentation of your sensor, but it is not necessary. You can instead test what voltages you get at various depths.
My reference to documentation was for your question on the gain factor :wink:

so what else would you need appart from the voltage measures that i already provided then, you lost me a little…

/fab

Well basically if I understand correctly in your case the max voltage you will be reading is 0.730v.
So based on the documentation I think you should set a gain factor of 1.024

ok cool, but from voltage how do I get to the desired volume or percentage: I know I’m that bad in maths…

This code will get you a sensor which shows the centimeters:

  - platform: template
    name: "CM"
    id: watertank_cm
    icon: 'mdi:water-well'
    unit_of_measurement: 'cm'
    lambda: |-
        return id(watertank_voltage).state;
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - calibrate_linear:
          # Measured value of X volt maps to y cm
          - 0.464 -> 0
          - 0.994 -> 55.2
          - 1.424 -> 102.0
          - 1.818 -> 144.0
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you a percentage of how full your tank is:

- platform: template
    name: "usable %"
    id: watertank_percent
    icon: 'mdi:water-well'
    unit_of_measurement: '%'
    lambda: |-
        return id(watertank_cm).state / 165.0 * 100; 
      #divide by max water level height to get a percentage
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this

This code will give you the liters:

  - platform: template
    name: "usable liters"
    id: watertank_liter
    icon: 'mdi:water-well'
    unit_of_measurement: 'l'
    lambda: |-
        return id(watertank_cm).state / 100 * 3.14159265 * 1.13751599 * 1.13751599 * 1000.0;
      #height (meters) times pi times radius (meters) squared times 1000 gives liters. This works if your water tank is a cilinder shape. Otherwise you have to use different calculations.
    update_interval: 1s #the delta filter will ensure it only sends values when something changes. 
    filters:
      - delta : 0.001 #only send the result if the difference with the last sent result is higher than this
1 Like

where did you get the documentation, i didn’t get any with my sensor