:description:Water leak detector with ESPhome on an M5StickC ESP32
:image:images/leak-detector-m5stickC_dry.jpg
:keywords:Leak Detector M5StickC M5Stack M5Atom
Using the ESP32's capacitive touch GPIOs, it's relatively easy to build a water leak detector using ESPhome. M5StickC was chosen as a platform due to the integrated Grove connector for clean connections and the fact it's well housed. The built-in display is a bonus, but not strictly necessary. Notifications are performed via HomeAssistant's 'alert' and 'notify' facilities, which send via Pushover to iOS & Android.
(the M5StickC comes with the short black USB cable seen in the pictures)
------------
Probe Connection
================
Since the probe comes with an integrated 3.5mm male plug, a 3.5mm female jack has been connected to the Grove port to allow easy probe replacement in the future. Orange connects to orange, blue connects to blue. The pads on the opposite side of the probe are internally-connected identically to the front. The two middle rings on the 3.5mm jack are unused. There is no polarity -- simply connect one terminal (orange or blue) to Grove GND, and the other to Grove G33.
Even though the M5StickC has a battery inside (which might be enough to cover short power outages), you'll need to keep
the unit on USB power 24/7.
Display Font
============
You'll need to place the `OpenSans-Regular <https://fonts.google.com/specimen/Open+Sans>`__ font (or another of your choosing) alongside your ESPhome yaml file. See - :doc:`/components/display/index`.
Flashing
========
I initially had trouble flashing the M5StickC; this is the procedure that I've found to work well with these devices.
You must provide the ESP32 bootloader during the initial flash over USB. Compile your ESPhome binary, and flash it along with the required bootloader (bootloader_dio_80m.bin), `available here <https://github.com/espressif/arduino-esp32/tree/master/tools/sdk/bin>`__, from the commandline (example under macos):
I also needed this procedure to flash M5Stack ATOM Lite and ATOM Matrix modules, which you also might consider using for this project. Both are smaller and more cost-effective than the M5stickC, and a generation newer -- though they lack the TFT display.
Once everything is hooked up and flashed, enable ``esp32_touch:````setup_mode: True`` and proceed to adjust the threshold setting on the touch-sensitive binary sensor (GPIO33) to find the proper value for your particular moisture sensor and cabling situation. Grab a glass of water for testing, another for yourself, and dip away while watching the logs. Your goal is to find a threshold value that is sufficient to trigger the binary sensor in water, but not otherwise. See :ref:`ESP32 Touch Pad <esp32-touch-binary-sensor>` for more information.