Door Monitor with Python & Raspberry Pi

Door Monitor with Python & Raspberry Pi
April 15, 2018 Reece

Door Monitor with Python

We have a closet in our house that we do not want our young boys in for safety reasons. So a while back when I was just getting my feet wet with Python, I wrote a simple script to monitor the door using a Raspberry Pi and a cheap magnetic switch. When the door is opened, it is logged and an email is sent to my wife and I immediately. There are multiple layers of safety for what is inside, and this is the first layer. I am not very creative with naming either, I call it Doorman.

The Hardware

Raspberry Pi 3 in Acrylic Case

I used a Raspberry Pi Model 3 for this project. They are cheap ($35) little single board Linux computers that you can do a lot with.

As for the sensor, I used a cheap magnetic reed switch from Amazon and CAT 5 Network cable for the wiring. I ran the wire up from the closet into the attic and dropped it down into my office closet. There is a network jack at both ends making it look innocuous.

I took an electronics prototyping board and soldered on a female ribbon connector. This allows it to easily connect it to the Pi board. The board also has a female RJ45 jack. A short network cable is used to plug into the wall for the sensor. Lastly, I added a RGB status LED (this is optional).

Doorman hardware  Pi with doorman hardware

I made sure to stay consistent on the wiring for the sensor, always using the orange wires. With there being 8 wires in network cable, connecting the wrong ones will lead to nothing happening and a lot of frustration. It is worth noting, that if you are not comfortable soldering you might not want to dive into this endeavor. However, if you are wanting to learn, this is a small enough project to get your feet wet.

I did not put together a schematic for the wiring. It is pretty basic. Just look at a pin-out diagram and wire it how you see fit.

The Software

My Raspberry Pi just has the standard Raspbian version of Linux on it. The only change is to make sure it is using Python 3 as the default version, not 2.7. Check this guide out on how.

Doorman Project on GitLab

Follow the link above to see the code project on Gitlab.

Modify the settings.yaml to match your needs. If you want to setup the notifications, you will have to go to IFTTT and setup the maker web-hooks and actions.

Future Modifications

At some point I would like to build a better enclosure to house it all. The ribbon cable folded up on top to hold the protoboard is (hopefully) temporary. I also wrote the code when I was new to Python. Seeing as how I use it daily for work, I could probably do a lot to clean up the code. With time being a valuable resource these days, this might not happen for a while, if at all. If it’s not broke, don’t fix it.

Materials List

  • Raspberry Pi 3 Amazon
  • Acrylic Case for RPi 3 Amazon
  • Protoboard Amazon
  • RJ45 Breakout Board Amazon
  • Ribbon Cable and Connectors Amazon
  • RJ45 Male Crimp Ends Amazon
  • RJ45 Female Keystone Jacks Amazon
  • 100 ft Network Patch Cable Amazon (Good if you don’t want to mess with crimping on connectors)
  • Keystone Wall Jack Amazon
  • Magnetic Reed Switch Amazon
  • RJ45 Crimping Kit Amazon — This is not the one I have but it includes a couple of extras and is good to have around and its hard to beat the price.



Leave a reply

Your email address will not be published. Required fields are marked *