ESPHome water level sensor

Hey all - I got everything hooked up today for testing and I’m not sure I’m getting a correct reading. I have the sensor in a 3-gal jug and it reads the same voltage (0.09570v) fully out or fully submerged. Is that just not enough depth to get a proper reading? It’s evening here so I can’t go out and test at my water tank.

Also the current to voltage board that was provided gets very hot, has anyone else experienced this (@teich ?)

Also after reading the specs the sensor operates at 12-36v, so I nixed the 24v step-up and am just powering it with 12v.

Update: I dropped the sensor in my water tank and again the voltage was basically the same from top to bottom of the tank. I might have blown the current to voltage sensor when I momentarily hooked it up incorrectly so I have another one on the way.

there shouldn’t be any heat - that sounds like mixed up wiring. Double (triple?) check everything. I had the same symptoms at first - not getting variation. Turns out I had made a mistake (don’t remember anymore what).

I was afraid I had fried it, but it turns out OK.
Check where your 12V vs 5V is, make sure the wires are exactly as diagrammed, etc.

Turns out I had wired things incorrectly and in the process fried the current to voltage sensor. Thankfully that was my hunch and a new one arrived yesterday and now it’s reading correctly!

I got everything wired up and in a waterproof box. I want to post these details below for folks who want to run this off a battery. The sensor pulls current regardless if you’re taking a reading from it or not, so you can use a relay controlled by your ESPxx to give it power. I have my ESP8266 turn the relay on on_boot and it automatically turns off when I put the ESP8266 into deep_sleep I only take a reading every 2 hours but it could probably be every 6-hours, we’ll see what kind of data i get back.

Below are some photos and the code I’m running on my ESP:


ESPHome Code:

esphome:
  name: water_tank_sensor
  platform: ESP8266
  board: d1_mini_pro
# Send power to sensor by enabling relay on boot
  on_boot:
    then:
      - output.turn_on: water_sensor_power
      - delay: 5s

# Enable logging, api, ota, captive_portal
logger:
api:
ota:
captive_portal:

# wifi settings
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_pw

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "watertanksensorAP"
    password: !secret ap_pw

# Deep sleep
deep_sleep:
  run_duration: 90s
  sleep_duration: 2h

# Set relay as output component
output:
  - platform: gpio
    pin: 13
    inverted: True
    id: water_sensor_power

sensor:
  - platform: adc
    pin: A0
    update_interval: 2s
    id: "waterTankSensorVoltage"
    name: "Water Tank Sensor Voltage"
    icon: "mdi:water-percent"
    filters:
    - median:
        window_size: 10
        send_every: 10
        send_first_at: 10
5 Likes

See this interesting guide to using the vl53l1x TOF sensor with the emphasis on waterproofing the sensor.

The vl53l1x reads up to 4 metres and the sensor is supported by tasmota now, so you can easily integrate it with HA.

https://nerdiy.de/en/howto-espeasy-fuellstandssensor-mit-vl53l0x-vl53l1x/

2 Likes

@hummingbear, thank you for sharing your solution. If you cut-off the power from ESP to curent-valtage converter for power saving then I think (not sure) that this does not impact the current which flows through the sensor (4-20mA). If you read the data every 2 hours this means that for most of the time that current id not used. In order to “save” it your relay should connect/disconnect power to sensor. But then I am not sure how much time sensor need after getting power to give reliable readings. Looking forward for data you are getting… :wink:

I have installed mine and during test the current measured with multimeter was quite stable. After connecting the sensor to ESP8266 via simple 100 Ohm resistor measurements are not that stable and can vary even 10% - example below of 24 measurement:


Was initially using filter: median and yesterday changed to

    - sliding_window_moving_average:
        window_size: 10
        send_every: 1
        send_first_at: 1

Maybe it is related to the fact that noew the sensor is not in water ? Or maybe your current/voltage converter is better the simple resistor ?
Will do some more testing and we will see.

I was using very similar sensor VL53L0X and had the same challenge that water vapors from hotter liquid was condensing on the laser (which in my case is half the year always colder then the liquid) and measures were not correct. :frowning:

1 Like

@Maco65 hmmmm, I’m not quite sure I follow you. The relay most definitely does cut off the power going to the sensor. The sensor is wired up directly to the battery through the current to voltage convertor, but the positive goes through my relay. The only wire going to my ESP from the sensor is the analog wire which is not drawing power when the ESP is in deep sleep.

I’m glad to draw up a schematic if that’s helpful.

I run my ESP to take readings for 90 seconds - I take the median of every 10 readings. I’ve been getting very stable and consistent results.

@hummingbear

Apologies - for some reason, looking at your picture, I have mixed sides of relay board… :frowning: Yes, your connection looks as intended and cuts the power off the sensor.

I do not have issue with power so I am measuring every 2 minutes and averaging over 10 measurements. Still for last 24 hours it does not look super stable:


Will consider current-voltage converter instead of simple resistor. It might be this or my sensor is not as stable as yours…

That setup looks great. I’m curious what size (AH) battery you have connected? With your relay controlling power to only come on intermittently I’m assuming it would last a very long time regardless. I am thinking about doing something like this but connecting a solar panel to keep the battery charged. Do you know or are you able to measure how much power your system uses if it were operating constantly? I figure if it was being charged by the solar panel there wouldn’t be much need for the relay switch. I am just trying to figure out what size battery/panel combination I might need.

I had a sealed lead acid battery a friend gave me for free, so I’m using that. It’s 6Ah@12v. The staff on DFRobot said the sensor consumes 30mA, so that + the ESP is how much you want to account for.

I think if you have an appropriately sized panel you’d be just fine. My water tank is in the shade so sadly it’s not an option for me.

A few things I’ve learned about power saving with the ESPs is that the versions with a USB Micro plug take up a lot of power even in deep sleep. So if you want one that’s going to last, get one without the USB plug and use your own serial adapter to flash it. Secondly that if you hookup any sensors so the VIN or 3V pins, it will still power them in Deep Sleep, so it’s best to use a GPIO pin as the lead for a sensor and program the ESP to turn it on when it wakes.

Hey Dave, saw your comment, maybe you have some ideas about how to make this work? Cheers. Use Xiaomi temperature/pressure sensor as water tank level sensor

I did see that thread a while back. Using that Xiaomi unit under water doesn’t really seem like a viable solution to be honest

Yeah apparently not :slight_smile: Oh well, cheers.

@teich I would like to have the ESP8266, the “Analog Current to Voltage Converter” and the power supplies indoors, to protect them from the elements and also to ensure WIFI signal. So basically only the pressure sensor would be outside (in the water tank that is).
I see the provided cable is only 5 meters long. Do you know whether it’s possible to extend that and how?

There might be some voltage drop depending how long you want to extend it, but I’m guessing the readings would all still be relative for the most part.

Why not just put it in some kind of waterproof box? That’s what I did, seems easier than extending but idk you’re setup.

Thanks for the tip! Well my outdoor wifi signal isn’t great, so by placing it inside I would not only protect it from the weather, but also ensure connectivity.
Alternatively I could buy one of those POE-capable ESP32 boards so that I can use an ethernet cable rather than wifi, but that seems a bit complex.

Or use bigger gauge wiring so the voltage drop is less.

Or get an outdoor AP.

The poe esp32 is not too complex.

1 Like

I used an ESP8266 that let me attached an external antenna. My ESP is about 800ft away from my Wifi through trees, with the antenna it works great. You can see it in my post here

You have to move a resistor on the chip to enable the external wifi which is annoying.

1 Like

I believe there should be no problem with extending (or shortening) the cable. The readings are related to current (not voltage) so the voltage drop in the cable should not matter. To be 200% sure I would do the test before mounting in the final destination: With some tank or barrel without extension and with extension (on the same water level).

1 Like

@nickrout, @Maco65, @hummingbear thanks for the helpfull advice! I think I’ll try with a sufficiently thick wire. I have a tube running from my garage to my water citern, but the thicker the wire the lower the chance I will be able to pull it through the tube. Unfortunately there thickness of the 5m cable attached to the sensor isn’t specified. Any clue about what geige those strands of wire are?