Water Tank Level and Water Volume with ESPHome

Do you know which of these type sensors are compatible with ESP Home? I’ve searched for “pressure” but that gives me information about temperature and air-pressure sensors.

Not sure how, I’m not using ESP, but surely it can be done. Those are standard 0-10V or 4-20mA sensors, ESP surely can work with it. But I can’t tell you, how to set up the software.

This must be searchable with Google :wink:

The pressure type sensors typically have an analogue output so don’t require a special integration in ESPHome (at least I’m not using one). It’s just a case of connecting the lead from the analogue output to one of your ESP device ADC pins, then translating the voltage to a useful measure (litres/gallons, %full, liquid height, etc).

If using a bare ESP board you might need a couple of resistors set up as a dividor to ensure you don’t go above the maximum input voltage; I’m using a Wemos D1 mini which supports 3.3VDC on the analogue input so I don’t have to worry about this.

1 Like

As with all things electronics there is no standard. I have successfully completed today my test lab with a pressure sensor (throw in type) with a signal between 4-20mA.
This is powered with a 24v power source (currently finalising my 18650 battery setup). The 24v is stepped to 5v (5.3v actually) that sends power to the nodemcu esp8266 and the ‘gravity’ current to voltage converter.
I also followed the great instructions from humming bear in relation to putting a 5v relay in line so the esp8266 can enter deep sleep - wake up and then power on the sensor and send data over a space of about 2 minutes then go back to sleep.
My 24v power supply shows that I consume .05 amps in sleep mode and .1 amps in signalling mode.
I will be looking to place it in the water tank soon - i still need to mount everything and avoid those dodgy plug in jumper wires. (couple of times these dodgy things made me scratch my head why I wasn’t getting results i thought i should)
I intend to try and write it up to help those who might want something similar.
On a side note - this was the project that got me into playing with electronics and eventually into home assistant. I haven’t regretted the choice I made between HA and the other automation software that was on offer about 4 years ago. In making this project I was very impressed how easy the whole write to esp through esphome was. Congrats HA people for bringin this software into the fold.
Pat

2 Likes

Well done - look forward to the rightwrite-up, and seeing your results over time.

Thanks. That seems an option worth exploring.

Would be very interested to see that. Thanks.

Would also love to see a more detailed implementation using a pressure sensor.

PS: For the persons that already have a working set up. Is it sufficient to put the EPSHome node in a waterproof box (above ground)? Doesn’t condensation harm the electronics in such a box? Is there a way to have better protection against condensation?

If your box is IP68 rated and the cables going in it are installed properly, nothing will happen to your ESP :wink:

https://www.google.com/search?q=ip68+junction+box&client=firefox-b-d&sxsrf=ALiCzsaQGlmMv6ImvVl9_2-QFAJQx8CvjQ%3A1665435568832&ei=sIdEY5y1MtKckgWfyI7gCQ&ved=0ahUKEwiczef7xtb6AhVSjqQKHR-kA5wQ4dUDCA0&uact=5&oq=ip68+junction+box&gs_lp=Egdnd3Mtd2l6uAED-AEBMggQABiABBjLATIIEAAYgAQYywEyCBAAGIAEGMsBMggQABiABBjLATIIEAAYgAQYywEyCBAAGIAEGMsBMgQQABgeMgQQABgeMgQQABgeMgQQABgewgIKEAAYRxjWBBiwA8ICBhAAGAcYHsICCBAAGAcYHhgKwgIIEAAYBxgeGBOQBgJI9SJQuAdY4xdwAXgByAEAkAEAmAFzoAGWBaoBAzYuMuIDBCBBGADiAwQgRhgAiAYB&sclient=gws-wiz

My tank monitoring config has lived happily on top of my water tank through a couple of very humid and wet summers & winters, with no sign of any condensation or corrosion on the electronics.

My housing is a 20cm long section of 90mm PVC pipe with an end cap glued on top and a press-fitted adaptor cap on the base. All cables enter through holes drilled into the bottom end cap, and the holes double as drain points for any moisture that gets in via the press fitting. I used some fibrous insulation (similar to insulation batts, used around heating duct) to keep the electronics off the bottom AND to keep the bugs out. All up maybe AU$12 to build it but a fair bit of mucking around, and keeping everything tidy while the cover is fitted is a challenge.

I bought one of these to upgrade it on the weekend…
https://www.bunnings.com.au/arlec-4-outlet-weatherproof-electrical-enclosure-box_p0065728

Similar items will be common in a lot of countries with outdoor festive decorations being popular now.

At AU$17 this was only slightly more expensive than a junction box, but the cable entry points are already there (with seals) and at 340mm x 230mm x 140mm I can run the mains extension cable right into the box and house the plugpack and all the electronics with plenty of room to spare. Real plug and play!

Hi, I’m just doing a test in a glass. The capacity is 250ml (0.25L), the full water level is 10cm, and the gap between sensor and water is 1cm.
I tried like that:

sensor:
  - platform: ultrasonic
    trigger_pin: GPIO13
    echo_pin: GPIO14
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 30s
    name: "Serbatoio Acqua Irrigazione"
    filters:
      - filter_out: nan
      - lambda: return ((((x*0,25)-1)-(11-1))/(11-1))*-100;
Compiling /data/esp-irrigazione/.pioenvs/esp-irrigazione/src/main.cpp.o
/config/esphome/esp-irrigazione.yaml: In lambda function:
/config/esphome/esp-irrigazione.yaml:236:19: warning: left operand of comma operator has no effect [-Wunused-value]
       - lambda: return ((((x*0,25)-1)-(11-1))/(11-1))*-100;

The result is always -100%, and the sensor doesn’t update every 30 seconds … It is the first time that I use this sensor, could you explain to me what I did wrong?
Thanks

Typically, the HC-SR04 has a range from 2cm to 400cm.

I’m not sure if you’re using that sensor, but if the gap between the sensor and water is 1cm, I will consider adjusting that first.

Ok I try to put 2 cm, but the other parameters are correct? What does that -100 at the end of the formula indicate?

    filters:
      - filter_out: nan
      - lambda: return ((((x*0,25)-2)-(11-2))/(11-2))*-100;

The result is always -100%

This is my code so you can compare:

  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    name: 'Distancia al agua' # Distance to water
    unit_of_measurement: 'm'
    accuracy_decimals: 1
    update_interval: 10s
    pulse_time: 20us
    timeout: 2.0m
    filters:
      - filter_out: nan

- platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    name: "Nivel cisterna"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 10s
    filters:
        ## Tank Depth = all the way from the cover where the sensor is mounted to the bottom = 75
        ## Sensor Value = x this is will stay the same as this is the reading from the sensor
        ## Excluded Distance = EX which is the distance I have on top from the sensor which is mounted to the cover to the highest level the water can reach = 21
        ## return ((((x*100)-EX)-(TD-EX))/(TD-EX))*-100
      - lambda: return ((((x*100)-21)-(75-21))/(75-21))*-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

What values are you getting for X?

1 Like

The tank I use for the test is 11.0 cm high, the maximum water level is 9.0 cm (+ 2.0 cm of space between sensor and max level = 11 cm tot)

With max water level (9 cm), in the esphome log it indicates 0.02 m (2 cm).

With min water level (0 cm), in the esphome log it indicates 0.09 m (9 cm).

This is my sensor code, now the level is at max but on homeassistant it returns -0.9

here my configuration with only one sensor reading.

sensor:
  - platform: ultrasonic
    trigger_pin: D6
    echo_pin: D5
    name: $ha_prefix Meter
    id: ultrasonic_meter
    state_class: measurement
    unit_of_measurement: 'm'
    accuracy_decimals: 2
    update_interval: 30min
    pulse_time: 20us
    timeout: 2.5m
    filters:
      - filter_out: nan
  
  - platform: copy
    name: $ha_prefix Percent
    source_id: ultrasonic_meter
    state_class: measurement
    unit_of_measurement: '%'
    accuracy_decimals: 1
    filters:
      # height from sensor to empty tank MAX: 228cm
      # height from sensor to full tank OFFSET: 38cm
      # sensor reading: x
      # used = x - OFFSET
      # remaining = MAX - used 
      # Full = (MAX - OFFSET ) = 190 cm
      # percent = 1 - (remaining / Full) * 100
      - lambda: return (1-((x-.38)/1.9))*100;

Bonjour peux tu partager ton code yaml sous esp home svp ?

Guys I need your help!
I’m trying to complete a similar project with temperature and ultrasonic senors.

A. Temp sensors (3x) will be attached to the storage tank of hot water for observing

  1. the temp of stored heated water
  2. the temp of water circulating in the diesel boiler system (common with house heating)
  3. the temp of water circulating in the solar panel system (there is an autonomous system with differential switch and a motor attached to it for the circulation).
    No any automation will be connected to this system, it will be exclusively for keeping me informed what is going on.

B. ultrasonic sensor to measure the level of the underground potable water tank, 6,000 ltrs, almost cube in shape, with well known dimensions. Filling of the tank, the submerged pump and Hi/Lo limits are operated from an autonomous system. I want to follow up the level, remaining quantity in it and consequently the overall consumption bu this is not the main object.

for the purpose of this, Im using:
Waterproof Ultrasonic Module JSN-SR04T
DS18B20 Temperature Sensor Module Kit Waterproof
ESP32 Development Board ESP32-WROOM-32U

So far the temp part is working but the level not.

[17:52:00][D][ultrasonic.sensor:036]: 'Water Tank Volume' - Distance measurement timed out!

this is the permanent error and presented on pre-defined interval of configuration
This is how is connected
5v----->5v of ESP32
RX---->GPIO1 of ESP32
TX----->GPIO3 of ESP32
GND—>GND of ESP32

My yaml file is

 - platform: ultrasonic
    trigger_pin: GPIO1
    echo_pin: GPIO3
    name: "Water Tank Level"
    unit_of_measurement: "%"
    accuracy_decimals: 0
    update_interval: 5s
    filters:
      - lambda: return ((((x*100)-20)-(123-20))/(123-20))*-100;
      - filter_out: nan
      
  - platform: ultrasonic
    trigger_pin: GPIO1
    echo_pin: GPIO3
    update_interval: 5s
    name: "Water Tank Volume"
    unit_of_measurement: "l"
    accuracy_decimals: 0
    filters:
      - lambda: return ((((x*100)-20)-(123-20))/(123-20))*-1000;
      - filter_out: nan

**dont bother with lambda, its not adjusted yet for my tank !

Any idea what else to try? other GPIO? what?
It is convenient for me to have only one ESP board in that place for simplicity reasons and the external antenna that I’m using with this board.

Thanks

Only use the same pins one time in your config - that would be for the ultrasonic platform. If you want to calculate other values (Volume etc.) make use of copy or template sensors instead :bulb:

Yes, both GPIO 1 and 3 have limitations and should be avoided. ESP32 got plenty of GPIO’s that are good for Input/Output use, check here for more info:

1 Like

since the day that posted here, I found another thread for my specific sensor suggesting the use of uart setup and the low power serial mode.
AJ_SR04M is the exact model and here is my adventure on this.
At the end of the day I have a sensor that is working until the reboot of the ESP board! Then I have to disconnect either pin Tx/Rx of the sensor before commence working again!
It’s insane for me that I have no any coding background.