Rough estimate, check with your seller: prices vary by shop and period.
Project goal
You will lay a probe on the floor under a washing machine, a water heater or a sink, and get an alert in Home Assistant, the software that gathers your connected devices, as soon as water bridges the probe’s tracks. An ESP32, a small electronic board with Wi-Fi, checks it only every 30 seconds and powers it only during the reading, which delays the corrosion of the metal tracks.
Why build it
A slow leak under an appliance often goes unnoticed for days, long enough to ruin the cabinet or the floor. This build warns you before serious damage is done, and an automation can even switch off a smart plug, for example the washing machine’s, as soon as the alert fires.
Useful terms for this project: ESP32 (small Wi-Fi board) · ESPHome (prepares the board’s program) · GPIO (the board’s pins) · OTA (update without a USB cable)
Prerequisites
- Home Assistant with ESPHome and a power outlet near the install spot (5 V USB supply).
- A three-pin analog water sensor module (S, + and −), the “water sensor” type sold for microcontrollers.
- A glass of water and a multimeter or the ESPHome log to calibrate the threshold.
Diagrams
Parts list
This ESP32 board is the base for every project in the series. ESPHome also works with other ESP32 boards: the board-choice guide helps you compare them. Which ESP32 board to choose?
Suggested board
ESP32-C6-DevKitC-1
- Wi-Fi 6, Bluetooth 5, Zigbee and Thread (at hardware level)
- Supported by ESPHome (ESP-IDF framework)
- USB-C for flashing and power
Watch-outs
- 2.4 GHz Wi-Fi only
- Use a USB cable that carries data
Main components
| Item | Quantity | Role and precautions |
|---|---|---|
| ESP32-C6-DevKitC-1 | 1 | Control board (see the box above). |
| Analog water probe module (bare traces) | 1 | Analog AO output: the value changes when water bridges the traces. Bare traces eventually oxidise: plan to replace the probe. Main component: search for « water level sensor module analog Arduino » at your seller (affiliate link, check price and availability). |
| 3-core extension wire | 1 to 3 m | Lets you put the probe on the floor and the board higher, away from splashes. |
Small parts
| Item | Quantity | Role and precautions |
|---|---|---|
| USB-C data cable | 1 | For flashing and power. Charge-only cables do not carry data. |
| USB 5 V power supply (CE/UKCA-marked charger) | 1 | At least 1 A for the board alone; more if peripherals draw power from it. |
| Dupont jumper wires (male-female and female-female) | 1 | One mixed pack covers every prototype. |
| Breadboard | 1 | To test without soldering; replace with a soldered build if you need it permanent. |
| Heat-shrink tubing | 1 | Insulates solder joints and splices; avoid tape in a permanent build. |
| Vented plastic or 3D-printed enclosure | 1 | Protects the board; leave a cable gland and vents if the sensor measures air. |
Amazon links are affiliate links: the site may earn a commission at no extra cost to you.
Step-by-step build
Step 1. Prepare ESPHome and create the device
- In Home Assistant, open the ESPHome Device Builder add-on (see the tutorial “Install ESPHome in Home Assistant (Device Builder)”). ESPHome is the software that turns a simple settings file into the program for your ESP32 board, without you having to write any code.
- Open “Secrets” (top right): this file keeps your passwords apart, so you can share your configurations without revealing them. Check that wifi_ssid (the name of your Wi-Fi network), wifi_password, api_encryption_key (the key that encrypts the link with Home Assistant), ota_password (for updates without a cable) and ap_password (for the board’s fallback Wi-Fi network) exist, and add any missing line. A valid API key is a long 32-byte string encoded in base64, which you can generate with “openssl rand -base64 32”.
- Click “New device”, name it “detecteur-fuite”, pick ESP32-C6, skip the flash for now, then replace the file content with the YAML from this page (“Edit”). YAML is a configuration file written in plain text: it describes, line by line, what the board must do.
What you should see: The file opens in the editor with syntax highlighting and no red underline.
Check: The “Validate” action (⋮ menu) answers “Configuration is valid”.
Step 2. Wire the probe
- With the USB power unplugged, connect the probe’s + pin to GPIO18, one of the metal pins lined up along the edge of the board (GPIO means “general purpose input output”). The probe is therefore not powered all the time: the board gives it current only during the reading, which slows the corrosion of its tracks.
- Then connect the − pin to a GND pin, the ground, and the probe’s output, marked S or AO (analogue output, which gives a varying voltage), to GPIO2.
- Extend the probe wire if the board must stay high.
What you should see: The probe is unpowered between measurements: any LED on it does not stay lit.
Check: The signal wire is on GPIO2, an analog input pin of the board.
Step 3. Flash the board and add it to Home Assistant
- Connect the board to your computer with the USB-C data cable: “flashing” means writing the program into the board’s memory, and this first write must be done over a cable. The board can already be wired or sitting on the breadboard, but any external peripheral with its own power supply must stay switched off.
- In ESPHome click “Install”, then “Plug into this computer” (Chrome or Edge over HTTPS) or “Manual download” and upload the file with ESPHome Web (web.esphome.io). If the port is missing, follow the flashing tutorial.
- After the reboot open Settings → Devices & services: the ESPHome device is discovered; click “Configure” and paste the API encryption key.
What you should see: The “Logs” show the Wi-Fi connection and then “Successfully connected to Home Assistant”.
Check: The device appears under Devices & services → ESPHome with its entities; later updates need no cable and go over Wi-Fi (this is OTA, “Over The Air”).
Step 4. Calibrate dry and wet values
- Calibrating means teaching the board to tell “dry” from “wet”. In Home Assistant, open “Leak probe level”, the voltage read on the probe, and note the value with the probe dry (for example 0.0 V).
- Dip the probe tip in a little water and note the wet value (for example 1.8 V).
- Set the “upper” threshold halfway and the “lower” one a bit below in the YAML, then reinstall over OTA.
What you should see: “Water leak” turns to “Wet” with a little water and back to “Dry” once the probe is dried.
Check: Test three times: the changes are clean, without flicker.
Step 5. Install and test in real conditions
- Lay the probe flat at the lowest point under the appliance you want to watch, tracks facing up, because water always runs to the lowest spot, then fix the wire so it does not move the probe.
- Pour a little water next to it: the alert must arrive in under a minute.
- Wipe, dry the probe and check the return to normal.
What you should see: A phone notification arrives after the detection.
Check: Repeat this test every three months: it also reveals an oxidised probe.
ESPHome code (YAML)
YAML is a configuration file written in plain text: it tells ESPHome what the board must do. Paste this one into ESPHome after creating the device. It targets an ESP32-C6 board; values to personalise are marked with “CHANGE” comments.
esphome:
name: detecteur-fuite
friendly_name: Water leak detector
esp32:
board: esp32-c6-devkitc-1 # XIAO ESP32C6: use board: seeed_xiao_esp32c6
framework:
type: esp-idf # required for ESP32-C6
logger: # serial logs, also visible over Wi-Fi
api:
encryption:
key: !secret api_encryption_key
ota:
- platform: esphome
password: !secret ota_password
wifi:
ssid: !secret wifi_ssid # 2.4 GHz network only
password: !secret wifi_password
ap: # fallback hotspot if the Wi-Fi is unreachable
ssid: "detecteur-fuite fallback"
password: !secret ap_password
captive_portal:
switch:
- platform: gpio
id: probe_power
pin: GPIO18 # powers the probe only while measuring (limits corrosion)
restore_mode: ALWAYS_OFF
internal: true
sensor:
- platform: adc
id: leak_level
pin: GPIO2 # ADC1 channel on the ESP32-C6
name: "Leak probe level"
update_interval: never # read on demand by the interval below
attenuation: 12db # full 0-3.3 V range
accuracy_decimals: 2
entity_category: diagnostic
- platform: wifi_signal
name: "WiFi signal"
update_interval: 120s
entity_category: diagnostic
interval:
- interval: 30s
then:
- switch.turn_on: probe_power
- delay: 300ms # let the probe settle before reading
- component.update: leak_level
- switch.turn_off: probe_power
binary_sensor:
- platform: analog_threshold
name: "Water leak"
device_class: moisture
sensor_id: leak_level
threshold:
upper: 1.2 # CHANGE after measuring your probe dry and wet
lower: 0.8 # hysteresis: back to dry below this value
YAML comments are in English, as in the ESPHome documentation. This code has not been run on your hardware: use “Validate” before flashing and adjust pins and names.
Home Assistant integration
- The “Water leak” entity (moisture class) behaves like a leak detector: it triggers standard alerts and turns red on the dashboard card.
- Typical automation: on detection, send a priority phone notification and cut the smart plug of the washing machine or dishwasher.
- Add “Leak probe level” to a dashboard to follow probe drift and spot oxidation.
Common problems and troubleshooting
| Symptom | Fix |
|---|---|
| Permanent false alarm | The threshold is too low or the traces are damp or oxidised. Dry and clean the probe, re-measure the dry value and raise “upper”. |
| The value never changes | The S/AO pin is not on GPIO2, or the probe is not powered while measuring. Check GPIO18 on the + and raise the delay to 500 ms. |
| Late alert | Reduce the 30 s interval to 10 s; the probe stays lightly stressed thanks to the pulsed supply. |
| The probe corrodes after a few weeks | This is normal for bare traces: replace it or move to a stainless-contact sensor or a sealed Zigbee leak detector. |
FAQ
Why power the probe from a GPIO?
A continuous current in water electrolyses the traces. Powering it only 300 ms every 30 s greatly cuts the time under voltage and slows oxidation. The module’s current must stay below the pin’s limit.
Can it run on a battery?
Not with this build: Wi-Fi stays on. For a battery a commercial Zigbee leak sensor is a better fit.
Can I fit several?
Yes: an ESP32 handles several analog inputs (GPIO0 to GPIO6); repeat the sensor block and power each probe from its own GPIO.
Related tutorials
These step-by-step guides explain the gestures common to every project in the series.
- Install ESPHome in Home Assistant (Device Builder)Install the add-on, prepare your passwords (secrets) and create the first device
- Flash an ESP32 with ESPHome (USB, drivers, boot mode)First upload over USB, CP210x and CH340 drivers, boot mode
- ESP32 wiring basics: GPIO, 3.3 V and pull-upsWhich pins to avoid, 3.3 V versus 5 V, pull-up resistors and common ground
- ESPHome OTA updates: flash without a cableUpdate the board without a cable, OTA password and recovery if something goes wrong
