Water level IBC with Home assistant

Measure level water in IBC tank 1000L using ultra sound and ESP Device

· 4 min read
Water level IBC with Home assistant


The goal is to be able to measure the level of water left in my IBC tank with ESPHome

This allow to connect electronic components to Home Assistant.

I will use ESPHome tool which has a very large community. ESPHome is an open source project created by Nabu Casa (https://www.nabucasa.com/).


The component I will use to measure the water level is HC-SR04:

HC-SR04 front and rear sides

This is an ultra sound sensor which will evaluate the distance to a target device or surface sending and getting back ultra sound (like bats) and then the reflected sound is converted in an electrical signal.

1. Wiring

The wiring is fairly simple :

2. Using ESPHome in Home Assistant

There are several possibilities to generate code to upload it on a ESP(wemos). I chose to use ESPHome in Home Assistant which is simple :

Go to the ESPHome add-on in Home Assistant and create your Secrets if it has not been done yet

3. Secret Creation

Now it's time to define the secrets in ESPHome by clickinbg on secrets in the upper right corner

Fill with you personnal wifi information :

4. Code

Now the code to send the this new device needs to be written to be able to measure the level of water left in the IBC water tank

Let's click on the bottom right corner on + New Device :

Give it a name

Chose the device type

Then click on Install

As I plugged this ESP on my Home Assistant I chose the following

Chose the correct port to intiate the communication

and when it's done, we can proceed to the upload of the code by clicking on Edit of this new ESP device

You can paste the following code as it is :

  name: water_tank_level_sensor
  platform: ESP8266
  board: d1_mini

# WiFi connection, replace these with values for your WiFi.
  ssid: !secret wifi_ssid
  password: !secret wifi_password

# Enable logging

# Enable Home Assistant API

# Enable over-the-air updates.

# Enable Web server.
  port: 80
# Sync time with Home Assistant.
  - platform: homeassistant
    id: homeassistant_time

# Text sensors with general information.
  # Expose ESPHome version as sensor.
  - platform: version
    name: water_level_sensor ESPHome Version
  # Expose WiFi information as sensors.
  - platform: wifi_info
      name: water_level_sensor IP
      name: water_level_sensor SSID
      name: water_level_sensor BSSID

# Exposed switches.
# Switch to restart the water_level_sensor.
  - platform: restart
    name: "water_level_sensor Restart"

  # Uptime sensor.
  - platform: uptime
    name: water_level_sensor Uptime

  # WiFi Signal sensor.
  - platform: wifi_signal
    name: water_level_sensor WiFi Signal
    update_interval: 60s

  - platform: ultrasonic
    trigger_pin: D1
    echo_pin: D2
    name: "Water level en litre"
    update_interval: 3s
    - lambda: return (100-(x*100))*10 ;
    unit_of_measurement: "L"

Then click on Install the I chose to do the install wirelessly since it's not plug to Home Assistant anymore

Waiting a bit and when it's done, distance begin to be measured (last lines)

5. Home Assistant integration

Once the ESP flashed we can add stuff in Home Assistant

6. Photos

Here are some pics for ideas