Skip to content

Build Your Own Smart Contactless Liquid Sensor with Home Assistant and XKC Y25 – Easy DIY Tutorial!

DIY LIQUID DETECTOR $5 and Kiril Peyanski holding the sensor

What contactless liquid sensor is? Can you make such sensor smart by your own? Proudly present you another DIY smart sensor named XKC Y25 that is working with Home Assistant. This time I will show you how to easily create an Intelligent non-contact level sensor that can detect whether a liquid is present in a plastic, glass or ceramics container up to 20mm thick. 

What is the main idea?

The idea is the following the sensor have to be glued to a tank wall or a pipe and when there is liquid inside that tank at the level of the sensor or above it, the sensor will have state ON. Respectively, when the liquid inside the tank drops below the sensor level – the state of the sensor will become OFF.

That is called a binary sensor in Home Assistant terms as you will see later. 

Contactless Liquid Sensor Schema
Contactless Liquid Sensor Schema

And because there is no contact with the liquid, the sensor is suitable for hazardous applications such as detecting toxic substances and all kinds of liquids in containers under high pressure. 

One great use case of this sensor is measuring the level of clean, grey and brown water in Campers or Caravans. My idea is to use this smart non-contact liquid level sensor for exactly that purpose.

XKC Y25 Contactless Liquid Sensor Cost & Specs

I got my sensor from AliExpress where there are 3 different modifications. Mine is the PNP model.

XKC Y25 PNP contactless liquid sensor
XKC Y25 PNP contactless liquid sensor

This version cost me around $5 US dollars with the shipping , it is waterproof with an IP67 rating, can work in a humidity range from 5% to 100%, and has an operating temperature range from 0 to 100 Celsius, which makes it quite versatile.

Adjusting the Sensitivity of the XKC Y25 sensor

By removing the cover, you can adjust the sensor sensitivity. Counterclockwise rotation of the knob will increase the sensitivity and respectively, clockwise rotation will decrease it.

Sensitivity adjustment knob of the non-contact liquid level sensor
Sensitivity adjustment knob of the non-contact liquid level sensor

What is needed to make the Liquid Sensor Smart?

Apart from the XKC Y25 sensor, several other things are needed and I’m going to list them all in the next few sections.

D1 Mini

Next thing that is needed for todays DIY project is an ESP board. I will use a D1 mini for that purpose and I will connect the liquid sensor to that D1 Mini and then I will upload the ESPHome firmware on it, so I can read the sensor data wirelessly.

D1 Mini (ESP8266) that will be connected to the sensor and wirelessly to Home Assistant
D1 Mini (ESP8266) that will be connected to the sensor and wirelessly to Home Assistant

Do not worry I will show you the wiring and firmware uploading procedure in just a moment. It is peace of cake.

Working Home Assistant

Third thing that is required is a working Home Assistant. If you don’t have such yet go and register for my Home Assistant Webinar where I’ll talk about the all 4 official methods of Home Assistant installation + 1 secret and stupid easy way to get started on a PC in under 5 minutes. 

Link to the free webinar registration page -> https://automatelike.pro/webinar

Micro USB cable and optional adapter

Final things that are needed, are a Micro USB cable and optionally an USB power adapter that will be used to power up the D1 Mini as well as the contactless liquid sensor.

The needed parts for the contactless liquid sensor apart from the XKC Y25 sensor.
The needed parts for the contactless liquid sensor apart from the XKC Y25 sensor.

Where to buy the needed parts?

I bought all of the things above from the AliExpress website. The parts are also available in Amazon, but they are slightly more expensive there. Both AliExpress and Amazon links for all of the needed parts for this project can be found below:

How to wire the XKC Y25 PNP and D1 Mini?

Now it is time to wire the future smart contactless liquid detector to the D1 mini board and then to upload the ESPHome. Here is how I did it.

First, I cut the plastic connector at the end of the XKC Y25 PNP cable and I connected the wires directly to the D1 mini board as follows:

XKC Y25 SensorD1 Mini
Blue wire (Ground)GND
Brown Wire (VCC)3v3
Yellow Wire (Signal Output)D0 (GPIO16)
Black WireNot connected
Wiring the XKC Y25 with D1 Mini

I solder the wires and below is the end result. Have in mind that the black wire is not connected anywhere and can be insulated somewhere, so it doesn’t get in the way.

Final result of wiring the XKC Y25 and D1 Mini
Final result of wiring the XKC Y25 and D1 Mini

Connecting several sensors to one D1 Mini Board

It is possible to add several XKC Y25 contactless liquid sensors to one ESP board. Using this approach you can mount several contactless sensor to one water tank for more precise monitoring. I didn’t made that yet, but I plan to do it in the future.

As general guideline, an external power supply should be used and different Data Pin for every contactless sensor have to be chosen.

UPDATE: Robert, shared in the comments below that he managed to connect second sensor using the following:

He connected the blue and brown wires from both sensors together, and the yellow wire from the second sensor I connected to D8 (GPIO15). Below is the code for both sensors:

binary_sensor:
– platform: gpio
pin:
number: GPIO16
mode:
input: true
pulldown: true
device_class: moisture
name: “Liquid sensor – upper ”

– platform: gpio
pin:
number: GPIO15
mode: INPUT_PULLUP
device_class: moisture
name: “Liquid sensor – lower”

If you have some other experience with connecting multiple sensors to one ESP board – please, share it in the comments bellow.

Question for You

I’m planing to use this contactless liquid detector in my Camper, so that I will know when the water tank is running out of water.

My winter clean water tank in my Camper
My winter clean water tank in my Camper

But I’m wondering what is your use case for this DIY project? Can you share what is your idea in the comments below?

Installing ESPHome on the D1 Mini

ESPHome Dashboard installed as Home Assistant add-on is probably the easiest way to manage ESPHome devices. This method + several other are well described in this article of mine – Complete ESPHome Installation Guide: 4 different ways to install ESPHome. If there is such need go read it and then come back right here.

ESPHome add-on is available in Home Assistant Add-on store (Home Assistant OS or Supervised is needed)
ESPHome add-on is available in Home Assistant Add-on store (Home Assistant OS or Supervised is needed)

This is how I will upload ESPHome firmware on the D1 Mini:

  • While I’m Inside Home Assistant I pressed the “c” button to invoke the search command bar and I typed – ESPHome
  • Then I selected Navigate ESPHome, to open the ESPHome Dashboard
  • Inside the ESPHome Dashboard I clicked on the New Device button then on Continue
  • Then I enter a device name (ex. Liquid Sensor) and I typed my WiFi name and Password.
Creating ESPHome initial configuration
Creating ESPHome initial configuration
  • Then I choose Pick a specific board option and I selected the D1 Mini from the dropdown list
Selecting WEMos D1 R2 and mini option from the board list
Selecting WEMos D1 R2 and mini option from the board list
  • I leaved the auto generated Encryption Key and I pressed on the Skip button, as I want to add few more lines to the ESPHome Configuration.
  • To edit the configuration I pressed the Edit button under the newly created Liquid Sensor.
Edit the liquid sensor ESPHome configuration
Edit the liquid sensor ESPHome configuration
  • I added the following lines at the bottom of the existing ESPHome configuration:
# Example configuration entry
web_server:
  port: 80

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO16
      mode:
        input: true
        pulldown: true 
    device_class: moisture
    name: "Liquid Sensor"
  • The web_server line will open a Web Server on the default port 80, so you will be able to see the status of the sensor from any web browser. This web_server part is optional and you can remove/comment it if you don’t need it.
  • In binary_sensor section I suggest to not change anything unless you know what you are doing. Just for information – GPIO16 is equal to D0 pin on the D1 mini according to the D1 Mini board pinout.
  • Finally I saved the changes.
  • I connected the D1 Mini with the Micro USB cable to the device where Home Assistant/ESPHome dashboard are running and I clicked on the Install button.
Build Your Own Smart Contactless Liquid Sensor with Home Assistant and XKC Y25 - Easy DIY Tutorial! 1
  • I selected the Plug into the computer running ESPHome Dashboard option.
  • After several minutes (3-5min) the Smart Contacless Liquid Sensor should be ready for use.
The assigned IP address of the Smart Contactless Liquid Sensor can be seen in the log. If you open that IP in a new browser/tab you will see the current sensor status.
The assigned IP address of the Smart Contactless Liquid Sensor can be seen in the log. If you open that IP in a new browser/tab you will see the current sensor status.

Testing the Liquid Sensor using the Web Interface

After the installation of ESPHome is ready I wanted to quickly test if the sensor is working as expected. Here is what I did:

  • I opened the ESPHome Dashboard and I saw that the Liquid Sensor is online.
  • I pressed on the Visit button and the Web Page of the device was opened for me.
Pressing the Visit button will work only if you enabled the web_server option as described in the previous section.
Pressing the Visit button will work only if you enabled the web_server option as described in the previous section.
  • I used a glass of water and when I glued the sensor to the glass it state immediately goes to ON.
Build Your Own Smart Contactless Liquid Sensor with Home Assistant and XKC Y25 - Easy DIY Tutorial! 2
  • If I moved the sensor up to the empty part of the glass – the sensor state becomes OFF immediately.

This quick test described above showed me that the sensor is working perfectly and I can freely continue forward to the more interesting part.

Smart Home Glossary?

Before I continue to the actual adding of the DIY smart liquid sensor in Home Assistant I want to give you my free Smart Home Glossary that will help you find the meaning of the 60+ of the most popular Smart Home words and abbreviations.

Download that Smart Home Glossary right now free of charge from my other website https://automatelike.pro/glossary

With glossary or not here is how I added the sensor in Home Assistant 

Adding the XKC Y25 in Home Assistant

Adding the ready to be used Contactless Liquid Sensor that is running ESPHome in Home Assistant is extremely easy. Let me explain how I added mine:

  • While I was inside Home Assistant I pressed the “c” button to invoke the search command bar.
  • I typed Integrations and I selected Navigate Integrations.
  • Inside the Home Assistant Integrations list I found the Liquid Sensor auto discovered and I pressed Configure button under it.
Auto Discovered Liquid Sensor by Home Assistant
Auto Discovered Liquid Sensor by Home Assistant

Quick Tip: If the sensor is not auto discovered it should be manually added. By adding a new ESPHome integration and providing the IP of the sensor during the configuration process.

  • After I successfully added the Contactless Liquid Sensor in Home Assistant I can see a new device under the ESPHome Integrations. And now, I can start using this Device/Sensor in Home Assistant automations & scripts.
Adding the Contactless Liquid Sensor in Home Assistant and testing it
Adding the Contactless Liquid Sensor in Home Assistant and testing it

How to create a Home Assistant demo automation?

One of the biggest flex of Home Assistant are the automations. You can easily create an automation that will notify you when the liquid in the tank that you are monitoring is below certain level.

Here is one quick example that will send a persistent notification when Liquid Sensor becomes Dry (Not moist)

alias: Dry Liquid Sensor
description: ""
trigger:
  - type: not_moist
    platform: device
    device_id: 421168f108dc14423f7f34dc7c6d499d
    entity_id: binary_sensor.liquid_sensor
    domain: binary_sensor
condition: []
action:
  - service: persistent_notification.create
    data:
      message: liquid sensor is dry
mode: single

To use the above automation in your Home Assistant setup, you have to change the device_id & entity_id with yours.

Challenge for You

I’m pretty happy with the end result of this DIY smart contactless liquid sensor. If you manage to create such sensor for yourself, share that in the comments below, by typing #LiquidSensorOwned

If you want to see more DIY Smart Sensors that are working with Home Assistant check this category of mine – https://peyanski.com/category/smart-home/smart-sensors/

I promise to congratulate you personally for the efforts.

Thanks for reading. I’m Kiril, see you next week. Bye!

2 thoughts on “Build Your Own Smart Contactless Liquid Sensor with Home Assistant and XKC Y25 – Easy DIY Tutorial!”

  1. Hi,
    I was able to connect the second sensor. I connected the blue and brown wires from both sensors together, and the yellow wire from the second sensor I connected to D8 (GPIO15). Below is the code for both sensors:

    binary_sensor:
    – platform: gpio
    pin:
    number: GPIO16
    mode:
    input: true
    pulldown: true
    device_class: moisture
    name: “Liquid sensor – upper ”

    – platform: gpio
    pin:
    number: GPIO15
    mode: INPUT_PULLUP
    device_class: moisture
    name: “Liquid sensor – lower”

    1. Great work Robert, and many, many thanks that you are sharing your solution. I will put it in the article 😉

Leave a Reply

Your email address will not be published. Required fields are marked *