ESPHome water level sensor

Liflitz
I am wondering - you have sent your voltage to the A1 pin. You are referencing vdd then? Any reason why you do this and not to ground on AO?
Do you know your power usage at work and deep sleep?
Pat

1 Like

Hi Pat,

You are right, A0 not A1, I corrected the diagram.
I do not know the power usage, sorry.

Liflitz

Liflitz,
glad I wasnā€™t seeing things.
I have just been doing some reading about using proper grounding of components so that there is no fluctuation of signal due to electromagnetic interference. This youtube video posted in an arduino forum though really in depth made me think that my rats nest of wires and cables might be causing some fluctuations to occur. (US) Designing the Signal Return Path Through the PC Board - Susy Webb - Expert Live Training - YouTube
Might see how a good ground base may assist.
Pat

Thank you so much, I will study it

Advice welcome
I have my bits connected and thought I would put it through itā€™s paces to see how consistent the readings are.
Everything is powered by a bench top supply delivering 14v. I then step this down to 13.3 for the sensor. I have a separate step down to 5v. This power goes to the esp32, the 5v relay (switching power to sensor on upon wake), the current to voltage converter and then to the ADS1115.
All grounds are connected.
Looking at the logs I see that there is fluctuation on readings - is this normal in your setup? see piccy
water level sensor
This is my yaml.

esphome:
  name: "maintankv2"
  platform: esp32
  board: nodemcu-32s
# Send power to sensor by enabling relay on boot
  on_boot:
    then:
      - output.turn_on: water_sensor_power
      - delay: 10s

# Deep sleep
deep_sleep:
  run_duration: 4min
  sleep_duration: 4min
  
# Enable logging
logger:

output:
  - platform: gpio
    pin: 19
    id: water_sensor_power
    inverted: false
# Enable Home Assistant API
api:

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

ads1115:
- address: 0x48
  i2c_id: bus_a

sensor:
- name: maintank
  platform: ads1115
  multiplexer: 'A0_GND'
  update_interval: 6s
  gain: 4.096
  unit_of_measurement: "V"
  icon: "mdi:gauge"
  accuracy_decimals: 3
  
  filters:
  - median:
      window_size: 23
      send_every: 21
      send_first_at: 7
        
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Esphome-Web-178238"
    password: "R4e6qBGLoo7Z"

captive_portal:

Patrick

1 Like

I have the exact same setup. But unfortunately I always get 9,7V from the current to voltage converter, no matter what the water level sensor sends.
Could you share a wiring diagram? Maybe I missed somethingā€¦
Thanks!

Philipp
Here is my just made schematic. You can see that this is my first time using draw.io - maybe Iā€™ll work on it amongst the other 327 jobs.
I get readings that are within +/- .03


Let me know if I have wires missing or in the wrong place.
Pat

1 Like

Hi All,

Thought people here may be interested in a solar ESPhome based water level sensor I recently completed work on. I have a water tank/bladder under the house which I wanted to track for garden watering purposes.

Basically itā€™s a PCB + battery + sonar sensor + solar panel. Iā€™ve got 3D printed cases/enclosures to go with each of these items too.

The ESP reports back the sonar distance (which I convert to water level in HA) as well as battery voltage and wifi signal strength.

Several iterations were needed to improve/reduce battery usage. The first version had the sonar wired directly to the battery which constantly drained it. The HD-SR04P version it can be powered as/when required from a ESP8266 pin.

The battery is a small 240mAh one I had left over from another hobby. On this it will last roughly a week without sun from a full charge with my deepsleep settings. Iā€™d recommend going with a better battery with proper low power cutoff as I destroyed more than one battery during testing.

This was my first attempt at PCB design so I wouldnā€™t recommend going out and make clones of this but I can say it works well for me.

Was thinking that it would be cool if this community could put together libraries of known working (and expert reviewed) designs and recommended parts for things like this.

The voltage regulator is a BL9 110-330BPFB which worked better than expected as did the solar/voltage management IC - CN3163.

Iā€™m happy to upload schematic/BOM files for anyone interested.

Code is probably what took me the longest to get working correctly. Hopefully this will help others. Just set your deep sleep settings and the battery voltage settings in the bits below.

esphome:
  name: tanksensor
  on_boot:
    - wait_until:  
        condition:      #  any condition here
          api.connected: 
        timeout: 20s
    - script.execute: read_then_sleep


esp8266:
  board: esp12e

# Enable logging
logger:
  level: DEBUG

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: .mynet.lan
  fast_connect: true

# Enable Home Assistant API
api:
  encryption:
    key: "yeahnah"

ota:
  password: "yeahnah"

output:
  - platform: gpio
    pin: GPIO4
    id: sonar_power

status_led:
  pin: GPIO2


sensor:
  - platform: ultrasonic
    trigger_pin: GPIO14
    echo_pin: GPIO12
    name: "Ultrasonic sensor"
    id: tanklevel_sonar_sensor
    timeout: 4m 
    pulse_time: 15us
    update_interval: never
    unit_of_measurement: "cm"
    accuracy_decimals: 3
    icon: "mdi:water-percent"
    filters:
    - multiply: 100
    - sliding_window_moving_average:
        window_size: 5
        send_every: 5
        send_first_at: 5
    - filter_out: nan
    - filter_out: 0.0
  - platform: adc
    pin: A0
    name: "Battery sensor"
    id: tanklevel_battery_sensor
    update_interval: never
    accuracy_decimals: 3
    icon: "mdi:power"
    filters:
      - calibrate_polynomial:
         degree: 3
         datapoints:
          # Map 0.0 (from sensor) to 0.0 (true value)
          - 0.68945 -> 3.18
          - 0.73047 -> 3.34
          - 0.79785 -> 3.66
          - 0.82715 -> 3.83
          - 0.87402 -> 4.01
          - 0.90332 -> 4.14
          - 0.91797 -> 4.21
  - platform: wifi_signal
    id: tanklevel_wifi_signal
    name: "Wifi Signal sensor"
    icon: "mdi:wifi"
    update_interval: never


script:
  - id: read_then_sleep
    then:
      - output.turn_on: sonar_power
      - delay: 2s
      - component.update: tanklevel_sonar_sensor
      - delay: 1s
      - component.update: tanklevel_sonar_sensor
      - delay: 1s
      - component.update: tanklevel_sonar_sensor
      - delay: 1s
      - component.update: tanklevel_sonar_sensor
      - delay: 1s
      - component.update: tanklevel_sonar_sensor
      - component.update: tanklevel_battery_sensor
      - component.update: tanklevel_wifi_signal
      - delay: 4s
      - script.execute: consider_deep_sleep

  - id: consider_deep_sleep
    then:
      - if:
          condition:
            lambda: 'return id(tanklevel_battery_sensor).state > 3.4;'
          then:
            - logger.log:
                format: "Battery state high"
            - lambda: |-
                id(enter_deep_sleep).set_sleep_duration(XXXXXX);
          else:
            - logger.log:
                format: "Battery state low"
            - lambda: |-
                id(enter_deep_sleep).set_sleep_duration(YYYYYY);
      - deep_sleep.enter:
          id: enter_deep_sleep


deep_sleep:
  id: enter_deep_sleep
  sleep_duration: 2min
    

I have 4 boards left that I probably will not end up using as you have to order with a minimum of 5. If you are in Australia and are interested in something like this feel free to PM me.

Cheers,
Bob

6 Likes

Hi @bobderbuilder thank you for sharing it and sounds a fantastic job
Iā€™m not from Australia, but if you share your schematic, I will be happy to learn from you

regards

Hi Bremby, PMā€™ed
Cheers,
Bob

Hi Guys,

I am a novice in electronics and trying to wrap my head around this.
I have two underground water tanks (Ā±2 meters high) that I want to measure with pressure sensors. Preferably with only one ESP device.

Close to the 2 tanks I have 24VDC (altough I could change the wiring to receive 230AC).

As far as I understand I would need:

Alternatively as the distance between meet ESP device and the tanks is small I could probably just use a pressure sensor that returns 0-10V so I donā€™t need the current to voltage converters right? Is this 0-10V signal as reliable as the 4-20ma output?

Could the guys (@rusty_away, @quizzical and others) that have a working setup (without drift) review the material list above so I can be sure I am not overlooking anything?

Yes that seems right. I agree that you could simplify your setup by using a 0-10V pressure sensor as you are close to the water tank.
Concerning the ā€˜driftā€™: I have 2 sensors, one in a pond that gives highly accurate readings. One in a rain water tank that used to give highly accurate readings but now goes up and down.

FYI readings from pond:
image
Accuracy of about 0.1-0.2cm

Readings from water tank:
image
Here I do rounding to compensate a bit for the drift. It obviously moves more as troughout the day I use the water from that tank for various applications.

Hmm wonā€™t the 0-10V damage the ADS1115? If I understand correctly it can only take 0.3V on the analog inputs?

Hi brechtvhb

I donā€™t know what your budget is but, for what it is worth, you can buy a better quality throw-in sensor with current to voltage converter included, right here in Australia from Core Electronics, for under $100. It has the advantage of being 316 stainless steel, not 304 grade like the one in the link. To me, this is an important factor for something that will spend its whole life in water.

I donā€™t know where you are, but Iā€™m sure similar products are on offer.

Your comments about ā€œdriftā€ deserve analysis now that Iā€™ve had these things in service for a good while. Mine do drift. I see a diurnal variation of up to 3% which I have not narrowed down to an individual component yet but the timing suggests that it is temperature related. The main thing is that it is consistent so I can correct for it and I end up with reliable readings. The ultrasonic sensor I started with was all over the place and I could never make sense of the variations.

So, to answer some of your other questions, 24VDC will be fine. I used a voltage regulator to siphon off a 5V supply for the nmcu, I to V converter and ADS1115. One thing I have established is that the voltage regulator is rock solid and is not the cause of the drift.

I have one nmcu/ADS1115 pairing that is set up to sense the levels in two adjacent tanks. I can copy the ESPHome code into a separate reply when I get home from work. You can then just change the relevant bits to suit your installation.

Cheers

Hi @rusty_away ,

Could you give me a link to the sensor youā€™re mentoining? I am located in Belgium. My main concern is durable devices which I donā€™t have to replace all the time. Is it outdoor temperature that is causing the drift or the water temperature? In case of water temperature I think it should not be a big issue in my case as tanks are underground.

Hi

This is the sensor. It is almost the same as the one you linked to but it definitely says itā€™s 316 grade stainless steel and it includes the I to V converter.

As far as whether it is the air or water temperature causing the drift, it could be either but my strong suspicion is air. Water heats and cools slowly and yet this drift is tracking air temperature very closely.

Cheers

Rusty
Iā€™m about to place all of my gear in a box and put it near the tank. It is all setup as you along with others have provided. The use of a relay to control power to the sensor only when the esp wakes from deep sleep is great.
Anyway - what you say about drift is curious to me. it seems as though you have identified soem realtional drift between outside temprature and the measurement. I would be curious then if there was some way of adding that in as a factor when computing results?
I reckon there are boffins watching this thread that could surely provide some kind of mysterious equation that correlates this and provides more accurate results.
Anyway as soon as I setup my unit in a box and start testing I plan to post in relation to long _ 3 year path - to get here. (That electronics rabbit hole thingy)
Pat

Hi @Patraff

I do use a template sensor to roughly correct the result now, but I feel that I can improve on it. I have some temperature sensors and it wouldnā€™t be hard to correlate the correction to the actual temperature as seen by the sensor.

Itā€™s one of those jobs that is taking a back seat to heaps of other projects at the moment.

Cheers

I contacted the manufacturer of these throw in probes. They claim to be OEM for many resellers.
They do also produce probes with 316 stainless steel and did put up a link on ali express.

I will try to connect the 0-10V version with a shelly uni as that seems to be the easiest method for novices (no need for converters and such then). Iā€™ll try to attach a temperature sensor to it too.

I could keep you posted in this thread for those that are interested in the results.

Yes very much, I also have a Uni lying around and would like to evaluate my water level in the deep well if it runs too dry. Thanks a lot