Introduction
I got burned buying into the Google security ecosystem a while back and promised myself to never do it again. Plus now I know exactly what all the pieces of our home monitoring system are doing and where they're communicating. Easy upgrading too!
All other sensors will use the same code base and construction.
Design
The sensor is coded in CircuitPython
The current case is the snap fit case provided by team Adafruit. There will be a smaller case for the sensors mounted on doors and windows.
You will need an MQTT broker for all of this to work together. You can use Adafruit IO.
In my implementation I set up a Mosquitto MQTT broker on a RaspberryPi 4 Model B running Debian Bookworm and Mosquitto v2.022.
The first sensor built and put into use is for the garage door
Our house has a detached garage. The opening for the garage is perpendicular to the house which is good for esthetics and access, bad for knowing if the door is open.
Parts
Code
Sensor
The code for this project can be found on Github.
It is one part of the larger home monitoring project.
The following libraries are required:
- os
- time
- board
- digitalio
- wifi
- adafruit debouncer
- adafruit minimqtt
- adafruit minimqtt
- adafruit connection_manager
- adafruit logging
Feature Highlights
- When the door is open the sensor publishes a 1 to monitoring.garage-sensor
Node-Red subscribes and will
- Change the indicator on the sensor page; red - open, green - closed
- Change the indicator on the home page; red - open, green - closed. Since we often reference if the door is open or closed, having an indicator on the home page saves having to switch tabs every time we want to know the state of the door
Node-Red
I have a flow dedicated to handling sensor data.
Configuration
Add an MQTT in node and configure it to subscribe to the topic for the sensor. For me it's monitoring.garage-sensor.
After that you'll need to connect it to a UI LED node that will take action based on the message payload.
I have three functions in my flow, two are disabled and will be used when traveling. The active function will generate an email when it's past a certain hour and the garage door is still open.
To build the function nodes, you will need some familiarity with Javascript. Word of caution, there are some differences between Javascript and Javascript within Node-Red. I had to narrow a few searches to get some of the answers I initially needed.
The code in the function for sending a notification looks like this:
context.data = context.data || {};
switch (msg.topic) {
case "monitoring.garage-sensor":
context.data.garage = msg.payload;
msg = null;
break;
case "home.hour":
context.data.hour = msg.payload;
msg = null;
break;
default:
msg = null;
break;
}
if (context.data.garage != null && context.data.hour != null) {
if (context.data.hour >= 20 && context.data.garage == 1)
{
var newMsg = {
"topic": "Your Attention Needed"
,"payload": "Garage door is open"
}
}
}
return newMsg
To receive email, you'll need to have an MTA. I have a secondary Gmail account that I'm using to send mail.
Project Construction
Circuit Board
- Solder breadboard jumper wires to the earth and data pins.
- Connect one side of contact switch to the jumper wires
- Using the snap fit case, secure the QT PY, ensure the jumper wires are hanging outside the case, and close the case
Installation in the Garage
I used Uglu Dashes to secure the magnets to the side of the garage door and to the frame. It's been there now for over 6 months without issue. I did clean both areas with rubbing alcohol before applying the Uglu.
This is part of the larger Home Hub Project with Node-Red
This page (Home Hub - Door and Window Sensors) was last updated on January 28, 2026.