How to Build a Smart Door Sensor with Notifications

Enhance your home security with a DIY smart door sensor that sends notifications.

Posted by Nina Alvarez on April 17, 2025 · 6 mins read

How to Build a Smart Door Sensor with Notifications

In this age of smart technology, enhancing your home with DIY projects can be both thrilling and practical. If you want to feel more secure and aware of what’s happening around your home, creating a smart door sensor is a fantastic DIY smart home project. This sensor can notify you whenever your door is opened, giving you peace of mind whether you’re inside or away. Plus, integrating it with Alexa can elevate your experience even more!

In this blog post, I’ll walk you through a simple step-by-step guide to building your own smart door sensor using Node-RED and some basic hardware. Let’s dive in!

Step-by-Step Setup Guide

Materials Needed

  1. Hardware:
    • A magnetic door sensor (usually comes with a sensor and a magnet).
    • A Raspberry Pi or any computer running Node-RED.
    • Jumper wires (if necessary).
    • An internet connection.
  2. Software:
    • Node-RED installed on your Raspberry Pi. If you haven’t set this up yet, check out some Node-RED tutorials for step-by-step instructions.
    • Node-RED Contrib Modules, specifically the node red contrib alexa home skill to handle notifications through Alexa.

Connecting the Door Sensor

  1. Install the Magnetic Door Sensor:
    • Follow the manufacturer’s instructions to install the magnetic door sensor on your door. Place the sensor on the door frame and attach the magnet to the door itself, ensuring they align properly when the door is closed.
  2. Connect the Sensor to the Raspberry Pi:
    • If your sensor is wired, connect it to one of the GPIO pins on the Raspberry Pi. Make sure you know which pin you are connecting to, as you’ll need to configure this later in Node-RED.

Setting Up Node-RED

  1. Open Node-RED:
    • Access your Node-RED interface through a web browser by going to http://<your-pi-ip-address>:1880.
  2. Create a New Flow:
    • You’ll need to create a new flow in Node-RED that will read the state of the door sensor. Use an “inject” node to simulate the door state and connect a “GPIO” input node to read the door sensor.
  3. Add Condition Logic:
    • Use a “function” node to process the input. This node will check if the door sensor is triggered (open) or not (closed). You can use the following example code: if (msg.payload === 1) { msg.payload = "Door Opened"; } else { msg.payload = "Door Closed"; } return msg;
  4. Integrating into Alexa:
    • Next, you’ll want to set up a notification system. Add the node red contrib alexa home skill node that you installed earlier. You can configure it to send a message to your Amazon Echo or any Alexa device when the function node outputs “Door Opened”.
  5. Deploy the Flow:
    • After connecting these nodes properly, hit the “Deploy” button on the top right corner of Node-RED.

Test Your Setup

  1. Open your door and see if you receive a notification through Alexa.
  2. Close the door and check if it notifies you of the door being closed.

Helpful Tip Block

Consider Adding Visual Notifications: If you have a Node-RED dashboard set up, you could also add a visual notification on your dashboard. For example, you could create a simple dashboard button that represents the door state visually, letting you see at a glance whether your door is open or closed.

Common Issues & Troubleshooting

1. No Notifications:

  • Check Connections: Ensure your door sensor is properly connected to the Raspberry Pi. You might also want to check the GPIO pin configuration in Node-RED to make sure it matches the pin you used.
  • Node Configuration: Double-check the configuration for the Alexa node to ensure it’s set up correctly and has the right permissions.

2. False Alerts:

  • Sensitivity Adjustment: Some door sensors can be overly sensitive. If you are getting false alerts, try to adjust the placement of the sensor or check its settings if it’s a smart sensor.

3. Network Issues:

  • Make sure your Raspberry Pi and Alexa device are on the same WiFi network. If you’re having connectivity issues, restarting your router might help.

Final Thoughts

Building a smart door sensor with notifications is not only an excellent project for beginners but also adds an extra layer of security to your home. By following the steps outlined above, you can easily craft a simple yet effective system that alerts you every time your door opens or closes.

Remember, this is just the beginning. Once you are comfortable with Node-RED and Alexa this way, the possibilities are endless! Experiment with different sensors or add more features, such as logging door activity over time or integrating it with other smart devices.

Happy DIYing, and enjoy your new smart home setup!