ESPHome water level sensor

ok so ive had something simular for a while on the bench and could never get the maths right.

Based on a RapidPLAS RT2200 2200L Tank
Height 165cm from the bottom of the overflow to the bottom of the BSP fitting
Radius works out to be 67.5cm

so based on the maths in this code

lambda: |-
        return id(watertank_cm).state / 1.65 * 3.14159265 * 0.675 * 0.675 * 1000.0;
      #height (meters) times pi times radius (meters) squared times 1000 gives Liters

should work out to be about 2250L on paper (small margin of error with rounding ect)
instead HA assistant is reporting back 145845.1 L


as you can see from the image, the water level usable CM and $ are about right

Anyone able to shed a bit of light on my maths issue? This is legit the only thing stopping me deploying this at home lol

Am I mistaken that your sensor variable is in centimeters and your formula is expecting meters? I think they should all be the same unit or else your formula thinks you have 100x more meters than it actually does.

Also does that divide by 1.65 need to be in there if your outcome is liters and not percent? Actually if you changed that from 1.65 to 100, youā€™ll be in better shape. That will covert your sensor value from cm to m and the rest of the formula makes sense.

1 Like

so i figured out that the formula in the original code was very much the case.

using

lambda: |-
return 3.14159265 * 0.625 * 0.625 * id(watertank_cm).state * 10;

got me to the correct volume of the tank

While waiting for my pressure sensors to arrive Iā€™ve been thinking about using the same principal in my pond. I would like to auto refill my pond if it drops below a certain level but I want to be 100% sure to stop pumping water in it once it is full so I would like to implement safe switches and not only rely on the pressure sensor for this.

My idea was to add some kind of water leakage sensor to the top of the pond but Iā€™m not sure how I should wire that to the digital input of the shelly uni. I would like to receive a signal (similar to what the shelly flood does) but wired to the digital input of the uni. Another important thing would be to make sure that this doesnā€™t harm the living creatures within the pond.

Anyone who can help me get started?

I found this sensor:
https://www.kemo-electronic.de/en/House/Garden/M158-Water-Switch-9-12-V-DC.php

Does the schematic below make sense?

Hi guys,

Can anyone confirm if this sensor will work? Iā€™d like to confirm that itā€™ll work before purchasing it.

Sensor

If so, can some kind person provide me with a basic code to read the water volume using it?

Iā€™m sure it will work but it depends on the application. That sensor reads up to 12 bar (175 psi), which is probably a bit much for accurately measuring water volume in a tank. It also wonā€™t compensate for changes in atmospheric pressure so you need an additional sensor or just go with general atmospheric pressure from a weather service.

Thanks for the feedback.
Iā€™d like to use it to measure the tank level/volume of an outdoor water tank.
Doesnā€™t need to be 100% accurate but rather an indication as to how full the tank is

Received my pressure sensor today. There is a small variance in readings.

After about 30 minutes the signal seems rock solid after applying low pass & outlier filters to it (in home assistant).

sensor:
- platform: filter
  name: "shelly_uni_waterput_1_adc_filtered"
  entity_id: sensor.shelly_uni_waterput_1_adc
  filters:
    - filter: outlier
      window_size: 4
      radius: 0.03
    - filter: lowpass
      time_constant: 10

Will let the sensor sit in my bucket for a few days now and see how it reacts.

This sensor still working well for you?

Yes, so far I am happy with the results. Iā€™ve tested them for about 2 weeks and the results were stable.
Do note that I have only tested it in a bucket indoors. Will place them in my cisterns when spring arrives.

Hi all,

Iā€™m wondering if someone can help me out hereā€¦ I feel like Iā€™ve got waaay too many tabs open (YT/HA Forum etc) with different options on how to try to get my setup to work.

Hereā€™s a diagram of what Iā€™m trying to do:

As per the diagram, Iā€™m planning on installing a DF Robot Analog Pressure Sensor on the lower outlet pipe of our 2400 L water storage tank.
The tanks dimensions are Height: 1700mm. Diameter: 1420mm

The other components that I plan to use include:

The tank is currently empty so I would like to try and calibrate it every 50 or 100L as I have a flow gauge on the garden hose which I plan to use to fill the tank. Iā€™m planning on initially using the code below to get a Voltage reading every 50 or 100L until the tank is full.

When I connect the signal cable and ground to my multi meter, I get a reading of 0.435 volts- I assume that this is what the reading should be when the tank is empty. I then filled up a 5L tank whilst measuring the voltage and confirmed that the voltage went up to 0.445 volts. I seem to be having issues integrating this into HA.

For simplicity sake, Iā€™ve been using the NodeMCU ESP32 dev board (and not the ESP8266 as shown in the diagram above), and running the following:

sensor:
  - platform: adc
    pin: GPIO33
    name: water pressure
    update_interval: 2s
    unit_of_measurement: V

I get the following readings with no water in the tank:
[21:29:29][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy
[21:29:31][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:29:33][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:29:35][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy
[21:29:37][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy
[21:29:39][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:29:41][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy

When I add 5L to the tank, I get the following readings:
[21:38:25][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy
[21:38:27][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:38:29][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:38:31][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:38:33][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.45300 V with 2 decimals of accuracy
[21:38:35][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.07500 V with 2 decimals of accuracy
[21:38:37][D][sensor:127]: ā€˜water pressureā€™: Sending state 0.88500 V with 2 decimals of accuracy
[21:38:39][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy
[21:38:41][D][sensor:127]: ā€˜water pressureā€™: Sending state 1.05100 V with 2 decimals of accuracy

So it seems like something is off.

The next planned step was to do the following but I donā€™t think Iā€™m ready for this:

  - platform: adc
    pin: A0
    name: "water volume"
    update_interval: 2s
    unit_of_measurement: "liter"
    accuracy_decimals: 5
    filters:
      - median:
          window_size: 200
          send_every: 10
          send_first_at: 4
    icon: "mdi:gauge"
    accuracy_decimals: 1
    filters:
      - calibrate_linear:
        - 0.1 -> 0
        - 0.5 -> 50
        - 0.9 -> 100

Please can someone help me - Iā€™ve reached out to numerous folks without any luck.

Thanks in advance.

Using the following hardware, iā€™ve got some data readouts, but not really sure how to visualise it in a lovelace card from current/voltage to tank volume. Ideally, id like a tank level shown as % and Litres remaining. What I have is raw data from the sensors at the moment (not in the water yet).

  • D1 mini
  • INA219
  • 4-20ma in tank pressure sensor
  • ESPhome config copy and pasted from a few sources above in the thread
  • Powered by 5.2v plug pack

image

i2c:
  sda: GPIO4
  scl: GPIO5
  scan: true
sensor:
  - platform: ina219
#    address: 0x76
    shunt_resistance: 0.1 ohm
    current:
      name: "INA219 Current"
      id: ina_current
      accuracy_decimals: 5
      filters:
      - multiply: 1000 #convert from Amps to mA
      unit_of_measurement: "mA"
    power:
      name: "INA219 Power"
      accuracy_decimals: 5
    bus_voltage:
      name: "INA219 Bus Voltage"
      accuracy_decimals: 2
    shunt_voltage:
      name: "INA219 Shunt Voltage"
      accuracy_decimals: 5
    max_voltage: 6.0V
    max_current: 400mA
    update_interval: 60s

Thanks once again for the feedback.

Iā€™ve installed the DFR 0257 sensor with a DFR 0553 16-bit ADC Module.

I have a weather app in HA which is giving me an atmospheric pressure of 1019 hPa. How would I add this into my current setup to compensate for this?

My current code looks like this:

i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

ads1115:
- address: 0x48
  i2c_id: bus_a

sensor:
- name: Jojo Tank Volume
  platform: ads1115
  multiplexer: 'A0_GND'
  update_interval: 6s
  gain: 6.144
  unit_of_measurement: "L"
  icon: "mdi:gauge"
  accuracy_decimals: 0
  
  filters:
  - calibrate_linear:
    - 0.37 -> 0.0
    - 0.426 -> 50
    - 0.430 -> 100
    - 0.431 -> 150
    - 0.432 -> 200
    - 0.434 -> 250
  - median:
     window_size: 200
     send_every: 20
     send_first_at: 4

Iā€™ve noticed that there is a difference between actual fill (using a pretty accurate flow gauge) and the sensor value as per the table below:

Fill amount (L) Voltage Meter V ESPHome Log V HA Volume (L) Difference (L)
0 0,425 0,37
50 0,426 0,426
100 0,428 0,43 79 -21
150 0,428 0,431 104 -46
200 0,429 0,432 131 -69
250 0,431 0,434 163 -87

The plan is to measure the values and add them to the calibration above at every 50L fill until the tank is full but I donā€™t want to put more water into the tank until these values look better. Iā€™m not too concerned about absolute accuracy as itā€™s 2400L tank so Iā€™d like the numbers to be relatively close but not absolute.

Thanks in advance :slight_smile:

I didnā€™t bother to compensate for atmospheric pressure ā€¦ I thought it was minimal. So 50hPa change in atmosphere is equivalent to 0.05bar. My tank level is absolutely stable at 6,697 litres for the last few weeks! It might be that my sensor allows pressure to be equalised through the cable. So I would not say I am correct!

Thanks for the feedback @JulianDH

Would you mind sharing your yaml details as I seem to be struggling a bit with the calibrations

  sda: 04
  scl: 05
  scan: true
  id: bus_a


ads1115:
  - address: 0x48

  - platform: ads1115
    multiplexer: 'A0_GND'
    gain: 4.096
    name: "Water Tank Level"
    id: wtd
    internal: true
    unit_of_measurement: 'metres'
    accuracy_decimals: 3
    icon: "mdi:water-percent"
    update_interval: 1s
    filters:
      - median:
          window_size: 30
          send_every: 30
          send_first_at: 30
      - calibrate_linear:
          - 0.028 -> 0
          - 2.275 -> 1.98
1 Like

Hi all,
I seem to be getting fairly inconsistent data from my pressure sensor and ADS- over time, the voltage seems to be going up and then randomly down so itā€™s making calibration quite difficult. The tank currently has a total of 800 litres inside so nothing has changed.

Hereā€™s my latest setup where Iā€™ve done the following to try stabalise things:

  1. Pressure Sensor and ADS Powered by same 5V power supply - no longer using the power from the ESP32
  2. grounded Pins A1, A2, A3 on the ADS as theyā€™re not in use (apparently this is good practice and causes less interference)
  3. Changed my code as follows:
i2c:
  sda: GPIO21
  scl: GPIO22
  scan: true
  id: bus_a

ads1115:
- address: 0x48
  i2c_id: bus_a

sensor:
- name: Jojo Tank Volume
  platform: ads1115
  multiplexer: 'A0_GND'
  update_interval: 10s
  gain: 2.048
  unit_of_measurement: "L"
  icon: "mdi:gauge"
  accuracy_decimals: 3
  
  filters:
  - calibrate_linear:
    #- 0.4413 -> 375
    - 0.4479 -> 450
    - 0.4488 -> 500
    - 0.4496 -> 550
    - 0.4508 -> 600
    - 0.4530 -> 700
    - 0.4680 -> 800
       
  - median:
     window_size: 250
     send_every: 15
     send_first_at: 10

You can see on the log that the output liters is going up:

[00:00:06][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.437063V
[00:00:16][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470062V
[00:00:26][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.449313V
[00:00:36][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.439813V
[00:00:46][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.440500V
[00:00:56][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.435562V
[00:01:06][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.440937V
[00:01:06][D][sensor:127]: ā€˜Jojo Tank Volumeā€™: Sending state 823.18744 L with 3 decimals of accuracy
[00:01:16][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469625V
[00:01:26][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470187V
[00:01:36][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469438V
[00:01:46][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469438V
[00:01:56][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470250V
[00:02:06][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469500V
[00:02:16][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469875V
[00:02:26][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469687V
[00:02:36][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469938V
[00:02:46][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469500V
[00:02:56][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470437V
[00:03:06][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469250V
[00:03:16][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470125V
[00:03:26][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.470187V
[00:03:36][D][ads1115:164]: ā€˜Jojo Tank Volumeā€™: Got Voltage=0.469312V
[00:03:36][D][sensor:127]: ā€˜Jojo Tank Volumeā€™: Sending state 828.91681 L with 3 decimals of accuracy

Does anyone have any suggestions for my setup or change in code to stabalise things?
Iā€™m not worried about it being a million perfect accurate - I just need it to remain stable without these random upward and downward drifts.

hello @mrmuttley

  1. ESP32, ADS115 and sensor need same GND rail. That means the reference ground is the same across the platform. This is important
  2. I have not heard of this and my set up does not have this and is super accurate
  3. I went for height of water in metres and then worked out tank volume separately in a template. It was easier to work out what was going on with the sensor. (and whether it was accurate!)
  4. I have 25 metres long Cat6 cable and getting the wiring in each twist is important. For this length, I think the 24V supply was quite helpful