Water Depth Sensor With ESP32


We live in a house with a water tank in the loft which uses gravity to feed water to any of the water sources upstairs in the house like the hot water tank to bathroom taps.

Now and again, the ball cock valve would stick and either stay open (which we can hear / see the overflow pipe when water flows outside) or sticks shut and does not refill the tank. The real solution is to fix the valve but it happened so infrequently (like twice a year) that I thought I could make try out a liquid depth sensor.


The sensor is a Milone eTape 30cm sensor. I got the one with a casing and pre-wired. A cheaper version exists which requires soldering and no protective case.

It is paired with a ESP32 running ESPHome that will read the sensor and relay the data to Home Assistant via WiFi .

I decided to add an environment sensor but that is out of scope of this post.


If the eTape doesn’t have the wiring soldered then it is assumed that is done before the rest.

The ESP32 is flashed with ESPHome, connected to the WiFi and (optionally) setup in Home Assistant. For more details see here.


The wiring is the same as other analogue sensors. You apply a voltage and measure the difference. The higher the water level is, the more resistance there is from the output.

Pin 36 is the analogue to digital pin so make sure it is connected to the right pin on ESP32.


Add the following top level directive:
# Analogue
- platform: adc
pin: 36
name: "Water Tank Level"
update_interval: 60s

Install and check values are coming back in the logs or in Home Assistant.


I left the sensor running with no water to get the highest voltage reading because the lower the level is, the less resistance there will be.

Then I dipped it in water to check the voltage drops.


I taped the sensor to the side of the water tank.

Used a 20 amp USB battery pack to power ESP32 and temporarily put it to the side.

Home Assistant

I created a template sensor that would take the min and max voltage based on the bucket test to get a water level as a percentage. Take the below and put it in a package replacing 0.37 as your lowest voltage (most amount of water) and 0.54 as the highest voltage (least / no water) measurement.
- sensor:
- name: Attic Water Tank Percent
unit_of_measurement: "%"
state: >-
{% if states('sensor.water_tank_level') == 'unavailable' %}unavailable
{% else %}{{ (0.54/(1+((states('sensor.water_tank_level') | float - 0.37) / (0.54 - 0.37)))/0.54)*100 }}
{% endif %}
icon: "{% if (0.54/(1+((states('sensor.water_tank_level') | float - 0.37) / (0.54 - 0.37)))/0.54)*100 | int > 50 %}
mdi:water-percent {% elif (0.54/(1+((states('sensor.water_tank_level') | float - 0.37) / (0.54 - 0.37)))/0.54)*100 | int > 25 %}
mdi:water-percent-alert{% else %}
mdi:water-remove{% endif %}"


The eTape sensor is pretty cool and easy to use with ESP32 chip. The case it comes with feels sturdy enough for home applications and the hard part was getting power to the ESP32.

I can see future uses in things like a water butt so I know how much rain water was captured or weather weight sensor would be more reliable.

About Danny

I.T software professional always studying and applying the knowledge gained and one way of doing this is to blog. Danny also has participates in a part time project called Energy@Home [http://code.google.com/p/energyathome/] for monitoring energy usage on a premise. Dedicated to I.T since studying pure Information Technology since the age of 16, Danny Tsang working in the field that he has aimed for since leaving school. View all posts by Danny → This entry was posted in Home Automation, IOT and tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *.

All comments must go through an approval and anti-spam process before appearing on the website. Please be patience and do not re-submit your comment if it does not appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.