ESPHome water level sensor

hi everyone,

I also need to know how much water is in my cistern so I know when to fill it up again.
I bought an TL-136 Water Level Sensor and have an ESP8266 here.

this thread is miles long (with many different aprroaches) and I would like to know If anyone can share a step-by-step tutorial how to set everything up.

  • components used
  • how to wire everything up
  • how to setup up the software and the home assistant integration

Best regards
Tobias

hi, which component did you use for this one? looks very nice and simple.

  • LM2596
  • Water Level Sensor (TL-136?)
  • MCU 8266 (is this an esp8266?)
    -CurrentToVoltage Converter ?? which one is it?

Best regards

HIi @kimocal,

Just a few questions. I have the same setup, but looking to connect to a Wemos D1 mini

I assume that the VCC & GND of your INA219 connect to the 5V and GND of your ESP, right ?
I assume that the SDA of your INA219 connects to the A0 of your board ?
Where is the yellow one going to ? :slight_smile:

Thanks in advance !

Kr,

Bart

Hi Kimocal,

Would you mind sharing your yaml code ? I constantly receive errors in the way you wired

Thanks in advance !

Kr,

Bart

Hi,

Do you mind sharing your esphome yaml file used ? I’m having trouble using my TL sensor and the ina219

Much appreciated !

Jt,

Bart

Here’s the esphome yaml parts:

esphome:
  name: water-tank
  platform: ESP32
  board: m5stack-core-esp32

# Enable logging
logger:

# Enable Home Assistant API
api:


i2c:
  sda: 21
  scl: 22

sensor:
  - platform: ina219
    address: 0x40
    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: 32.0V
    max_current: 400mA
    update_interval: 10s
    
    

Here is the Home Assistant configuration.yaml parts:

 
 template:
  - sensor:
      - name: "Water Tank Level"
        unique_id: "water_tank_level_sensor_inches"
        unit_of_measurement: "inches"
        state: >
          {% set height = ((states('sensor.ina219_current')|float * 5.0663) - 24.86) |round(2) %} #This equation was derived in a spreadsheet based upon actual water height and ina219 current values
          {% if 0.000 <= height <= 72.000 %}
            {{ height }}
          {% else %}
            unknown
          {% endif %}

The INA219 is connected to the ESP32 via the wires in my diagram. The red is VCC and black is Ground. The yellow and green wires are the SDA and SCL pins on the M5 Stack ESP32. You’ll have to look up the Wemos D1 mini pins. On the M5 Stack the SDA and SCL pins are 21 and 22 respectively per the yaml code I shared.

Hi,

Can you help ?

Thanks @kimocal,

Unfortunately I’m receiving following errors:

[16:48:31][I][app:102]: ESPHome version 2022.5.0 compiled on May 24 2022, 16:47:54
[16:48:31][C][wifi:491]: WiFi:
[16:48:31][C][wifi:353]: Local MAC: 4C:75:25:34:94:32
[16:48:31][C][wifi:354]: SSID: [redacted]
[16:48:31][C][wifi:355]: IP Address: 192.168.1.80
[16:48:31][C][wifi:356]: BSSID: [redacted]
[16:48:31][C][wifi:358]: Hostname: ‘watertank’
[16:48:31][C][wifi:360]: Signal strength: -64 dB ▂▄▆█
[16:48:31][C][wifi:364]: Channel: 1
[16:48:31][C][wifi:365]: Subnet: 255.255.255.0
[16:48:31][C][wifi:366]: Gateway: 192.168.1.1
[16:48:31][C][wifi:367]: DNS1: 192.168.1.1
[16:48:31][C][wifi:368]: DNS2: 0.0.0.0
[16:48:31][C][logger:274]: Logger:
[16:48:31][C][logger:275]: Level: DEBUG
[16:48:31][C][logger:276]: Log Baud Rate: 115200
[16:48:31][C][logger:277]: Hardware UART: UART0
[16:48:31][C][i2c.arduino:038]: I2C Bus:
[16:48:31][C][i2c.arduino:039]: SDA Pin: GPIO4
[16:48:31][C][i2c.arduino:040]: SCL Pin: GPIO5
[16:48:31][C][i2c.arduino:041]: Frequency: 50000 Hz
[16:48:31][C][i2c.arduino:044]: Recovery: bus successfully recovered
[16:48:31][I][i2c.arduino:054]: Results from i2c bus scan:
[16:48:31][I][i2c.arduino:056]: Found no i2c devices!
[16:48:31][C][ina219:133]: INA219:
[16:48:31][C][ina219:134]: Address: 0x40
[16:48:31][E][ina219:137]: Communication with INA219 failed!
[16:48:31][C][mdns:084]: mDNS:
[16:48:31][C][mdns:085]: Hostname: watertank
[16:48:31][C][ota:085]: Over-The-Air Updates:
[16:48:31][C][ota:086]: Address: watertank.local:8266
[16:48:31][C][ota:089]: Using Password.
[16:48:31][C][api:138]: API Server:
[16:48:31][C][api:139]: Address: watertank.local:6053
[16:48:31][C][api:141]: Using noise encryption: YES
[16:48:39][D][api:102]: Accepted 192.168.1.142
[16:48:39][D][api.connection:827]: Home Assistant 2022.5.5 (192.168.1.142): Connected successfully

Seems that my wemos is not able to communicate through the I2C. My SDA GPIO pin is connected to the SDA pin on my INA219, same goes for SCL.

Do you have any idea ?

Kr,

Bart

This is part of the issue. Without seeing which pins you have the SDA and SCL lines physically connected to on the Wemos, it’s hard to trouble shoot. If you have them connected to the actual SCL and SDA pins then change these in your esphome yaml:

i2c:
  sda: 21
  scl: 20

Also you may wait to add everything after those lines until your ESP can see the i2c devices. The ESP will scan the i2c bus and then give you the address of the INA219. That will show up in the logs. Then you can add the appropriate address in the remainder of the YAML.

sensor:
  - platform: ina219
    address: 0xZZ  <---- TO BE DETERMINED WHEN THE ESP SCANS THE I2C BUS

Hi Kimocal,

Thanks again for your swift answer. Please find below the code. The Wemos D1 mini on an ESP8266 platform doesn’t support the declaration of the 20 and 19 pins, I need to use (I think) the GPIOnumbers.
So my SDA from the INA219 is connected to the GPIO4, the SCL from my INA219 is connected to the GPIO4. The GND from my INA219 connected to GND from Wemos & the VCC of INA219 connected to the 5V pin.

I use code below:

esphome:
  name: watertank
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:
 level: VERY_VERBOSE

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

ota:
  password: "532e35be5f3621ce8a33df0d057a0bda"

wifi:
  ssid: "xxxxxxx"
  password: "xxxxxxx"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Watertank Fallback Hotspot"
    password: "xxxxxxx"

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: 32.0V
    max_current: 400mA
    update_interval: 10s

I try to scan the I2C, but no devices found. I tried to put a delay ‘on boot’, but that doesn’t work…

To be complete: I connected the pins for the INA219 to the Wemos board directly using the breadboard cables, but without using a breadboard (so from pin to pin)

Any other suggestions ?

Thanks in advance !

Kr,

Bart

Try using the pin numbers first and report back.

i2c:
  sda: 21
  scl: 20

If you are using a d1_mini you can also use the D-numbers for your pins in the yaml file.

The i2c scan doesn’t find any device, so 99 out of 100 times there is a problem with the wiring, or a defect sensor. Do you have another i2c device which can be used for testing to exclude the sensor itself.

Can you post some pictures of your setup?

That doesn’t make sense when using a esp8266, that are the actual pins on the bare esp-chip, not the GPIO numbers.

I was going by other examples in a quick google search of using the pin #s I found online for esp8266. I have only played with ESP32s so not too familiar with the 8266 / Wemos idiosyncrasies.

Hi @kimocal , hi @jsuanet ,

Thanks both for your replies and your advice !
Indeed, when I try to enter the physical pin number (21/20), the yaml file tells me that these pin numbers are not supported for the 8266 platform. However, I tried both GPIO4 & GPIO5 / D1 & D2, but unfortunately without any luck.
Unfortunately, I don’t have another I2C device to test with :-/

Please find enclosed the requested pictures. The pictures with the usb cable attached is the Wemos D1 mini, the little one is the INA219
Connections on INA219:

  • yellow = VCC
  • orange = GND
  • red = SCL
  • blue = SDA

And… please don’t look at the mess of my desk :wink:

Kr,

Bart




If I look at the picture of the INA sensor I would suggest to resolder the SCL and SDA pins. The soldering of these pins looks not so good, try to cover the whole puch hole with solder.

1 Like

Hi @jsuanet, hi @kimocal ,

Resoldering the pins did the trick !!! you are hero’s !

[18:30:15][VV][scheduler:195]: Running interval 'update' with interval=10000 last_execution=17664 (now=27670)
[18:30:15][VV][i2c.arduino:126]: 0x40 TX 02
[18:30:15][VV][i2c.arduino:102]: 0x40 RX 07AA
[18:30:15][V][sensor:074]: 'INA219 Bus Voltage': Received new state 0.980000
[18:30:15][D][sensor:124]: 'INA219 Bus Voltage': Sending state 0.98000 V with 2 decimals of accuracy
[18:30:15][VV][i2c.arduino:126]: 0x40 TX 01
[18:30:15][VV][i2c.arduino:102]: 0x40 RX 0000
[18:30:15][V][sensor:074]: 'INA219 Shunt Voltage': Received new state 0.000000
[18:30:15][D][sensor:124]: 'INA219 Shunt Voltage': Sending state 0.00000 V with 5 decimals of accuracy
[18:30:15][VV][i2c.arduino:126]: 0x40 TX 04
[18:30:15][VV][i2c.arduino:102]: 0x40 RX 0000
[18:30:15][V][sensor:074]: 'INA219 Current': Received new state 0.000000
[18:30:15][VV][sensor.filter:014]: Filter(0x3fff1ecc)::input(0.000000)
[18:30:15][VV][sensor.filter:021]: Filter(0x3fff1ecc)::output(0.000000) -> SENSOR
[18:30:15][D][sensor:124]: 'INA219 Current': Sending state 0.00000 mA with 5 decimals of accuracy
[18:30:15][VV][i2c.arduino:126]: 0x40 TX 03
[18:30:15][VV][i2c.arduino:102]: 0x40 RX 0000
[18:30:15][V][sensor:074]: 'INA219 Power': Received new state 0.000000
[18:30:15][D][sensor:124]: 'INA219 Power': Sending state 0.00000 W with 5 decimals of accuracy
[18:30:15][V][component:199]: Component ina219.sensor took a long time for an operation (0.11 s).
[18:30:15][V][component:200]: Components should block for at most 20-30ms.

The only thing is, I wired my sensor using the scheme in this thread by @kimocal , but my voltages (see this log & Watts) are very low. I drowned it in a bucket of water and there is no movement of the values.

My sensor is powerd by 12V only, is this enough or should be 24V ?

Could this be the reason ? Or is the bucket no reference ?

Thanks in advance !

Kr,

Bart

It depends on which sensor you bought. The supplied spec sheet for your sensor should tell you. Mine requires 24V and the depth range is 0 - 2 meters.

That’s the point, it varies apparantly :slight_smile:

Longzhuo TL-136 Vloeistofniveau-meetomvormer, waterniveau-sensor detector 12-32 VDC 4-20 mA signaaluitgang voor precisiemeting (1/2/3/4/5 m) (0-2M)

So also 0-2M but with a 12-32 VDC :slight_smile:

So I presume that 12V should work, no :slight_smile: