Micropython leak detector with Adafruit and Home-assistant

Introduction

After experiencing both a new boiler AND a washing machine leak in the same weekend I searched online for a network connected water leak detector. I wanted a device I could integrate into my home automaton system so I could both continually monitor the status of the detector (battery level etc.) and receive notifications. Unfortunately nothing quite fit the bill, so I set about making my own.micropython leak detector with adafruit and home assistant

I am passionate about the python language, and chose to develop this sensor in micropython due to both my familiarity with the language and since I can interactively prototype the code from the REPL (command line). This avoids the faff of compiling and uploading code as required by some other approaches, resulting in very rapid development.

There are many home-automation platforms available, perhaps the most popular open source ones are openHAB and Home-assistant. I use Home-assistant as I found this much easier to setup than openHAB and it is written in python 3. As a very brief introduction to Home-assistant, hardware or software ‘components’ are added to the system by making the appropriate entries in a .yaml file. This is described in detail later. I personally host Home-assistant on a dedicated rasberry pi, and my devices (lights, cameras etc.) send data to Home-assistant over my network using a number of number of protocols. The approach I use in this project is to send data from my Wipy board to Home-assistant via the Adafruit MQTT broker, illustrated in the schematic below.schematic micropython leak detector with adafruit and home assistant

Hardware

The hardware is shown in Figure 2, and the wiring is illustrated in Figure 3 on an annotated version of the board diagram available at https://www.pycom.io/resources/ I will add a Fritzing diagram when pycom to make one available. Note that the expansion board is ONLY REQUIRED for updating the Wipy firmware. For the final version of this project I will not need the expansion board and will just need to add a 5V power source.

Temperature readings are made using the DS18B20 sensor, here powered by the 3.3 V output of the Wipy and connected via the 1-wire protocol.

Water/moisture readings are made using a cheap sensor I found on Amazon, again powered by the 3.3 V output. This sensor has both analogue and digital outputs, but I chose the analogue since the docs advise that this is more accurate, and seemed the simplest approach. The readings are a bit noisy, so I take an average of 100 readings.

Details of how to setup Wifi connection on the Wipy are provided on https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/wlan.html but in summary I place my wifi credentials in the boot.py file on the Wipy. Actual code to take sensor readings and send them to my home-automation system is in the main.py file.

For more detail: Micropython leak detector with Adafruit and Home-assistant

Scroll to Top
Read previous post:
Next-generation smartphone battery inspired by the gut
Next-generation smartphone battery inspired by the gut

A new prototype of a lithium-sulphur battery – which could have five times the energy density of a typical lithium-ion...

Close