Water level detection with ESPHome and Home Assistant

by Bradley Geldenhuys on July 20, 2021

I have been working on a smart sustainable garden project for a while now.  In my mind a smart sustainable garden will need to overcome several draw backs to a traditional garden (Watch this space for the link to the main project coming soon). 

In this blog we will be focusing on the water level in a Jojo tank that harvests rainwater. This is a pretty important aspect to the sustainability of the garden and answers a very simple question, “Do I have enough water to irrigate the garden?”

JoJo Tank which we will measure water levels

While we have plenty rain here in KwaZulu Natal there will be times when the water supply might be questionable, especially during winter.  So how do we monitor the water level?

Equipment Needed.

  • 1 x Non-contact Digital Water / Liquid Level Sensor XKC-Y25-T12V
  • 1 x D1 Mini
  • 1 x 3 Flat Ribbon Cables

Optional

  • 1 x Battery Pack

It goes without saying you need Home Assistant running but just in case you didn’t know, now you do.

Step 1

Install and configure ESPHome in Home Assistant.

This is the guide I used to install the ESPHome add-on Getting Started with ESPHome and Home Assistant — ESPHome

Step 2

Build your sensor. 

I soldered the D1 Mini and used the Flat Ribbon Cables to connect the GND, 5V, GPIO14 to the DFRobot chip.

D1 Mini and DFRobot Water Level Measure

I like to keep it challenging so I connected the yellow to GPIO14 (D5) on the board, Blue to GND and Green to 5V.

D1 Mini Pins

I then plugged this into my PC with a USB cable and made sure the power came on.

Step 3

Update the D1 Mini with the ESPHome firmware from Home Assistant.

Simply create a new configuration with a name and your SSID details.

ESPHome create new configuration with Wifi SSID

To complete the configuration, add the following to the script.

binary_sensor:

  – platform: gpio

    name: “Tank Water Level”

    pin: GPIO14

Click Save and then Install.

ESPHome serial port selection

Select the USB port that your D1 Mini is plugged into.

D1 mini ESPhome configuration installation progress
ESPHome Configuration installed successfully

Step 4

Home Assistant configuration.

Head over to Home Assistant and click Configuration –> Integrations and search for ESPHome.

ESPHome Home Assistant Integration

Add the new device you just created in the Host

ESPHome Home Assistant Config Successful

Now you should be able to see the device.

ESPHome Entities in Home Assistant

Simply add the Entity to Lovelace or start using it in Automations to make things happen.

Finally, you will need to attach your sensor to your JoJo tank, which is pretty straight forward if you have power available.  If you don’t there are some solar/battery options available, but I wont cover that now.

ESPHome with a D1 Mini connected to Home Assistant showing water level in a JoJo tank

To test this product, I have a temporary setup which I will need to enclose in a waterproof casing eventually, but here you can see the sensor installed and working.  I did have issues with it not sensing water level if placed too close to them bottom of the tank, I only started getting readings above about 20cm from the bottom.  I assume one could add additional sensors to other GPIO’s on the D1 Mini to detect multiple water levels of the tank.

BACK TO TOP