Introduction: Raspberry Pi DIY Smart Doorbell That Can Detect People, Cars, Etc.
Rather than buying a Ring Doorbell (or Nest, or one of the other competitors) I built our own smart doorbell with a Raspberry Pi. The whole project cost about $150 (USD), which is about average for a smart doorbell, but it is much more full-featured than anything else you’ll find on the market. For example, it integrates with the rest of the home security system — using machine learning to identify humans, cars, animals, and more:
Exact parts I used can be found here.
Step 1: Laying Out the Parts
I had some spare copper and brass parts lying around from prior steampunk projects (see part list). This came in handy when not all of the electronics could easily fit in the junction box.
I began by laying out the parts. Three holes were drilled in the sides of the junction box for the power cable, USB cables, and button wires. Plus, one larger hole in the cover to accommodate the camera.
Step 2: Ringing the Doorbell
The first order of business was to make the doorbell actually ring.
With the doorbell wire attached to GPIO18 (pin 12) on the Raspberry Pi, I then used the Serial Port input in Node RED to detect button-presses. To actually trigger a doorbell alert, as well as handle bi-directional (microphone/intercom) audio, see this post.
Step 3: Motion Detection
There’s also the topic of motion detection and video.
In this regard, the doorbell is just another CCTV camera. It uses the exact same setup described in the following series of posts. The motion detection and object recognition is what generates the images like the one at the top of this post.
Step 4: Smart Lock Integration
I used hot glue on the openings of the junction box to seal it, where possible.
The copper ring seen above also has a lip, protecting the camera from water. Plus, the whole thing is installed underneath a balcony, so not much water even has the chance to hit the doorbell. The final pieces was to integrate the doorbell with a smart lock. Thankfully, Home Assistant makes this easy.
It communicates with Home Assistant via Z-Wave. What I like about this lock is that it can be programmed remotely to support different user codes (useful as an Airbnb host, or when you need to let a friend in). It also can detect which user pin code was used to open the door (and when) — great peace of mind when giving cleaners a code to the house.
Step 5: Source Code: Recap
I wish I could give you copy-and-paste code for this project, but a lot of it will depend on your exact hardware, speakers, cameras, etc. Instead, I’ll recap each piece involved and link to the articles/code where I explain how to implement them:
- Node Red uses gpiod to trigger a flow when GPIO #18 (the doorbell button) fires.
- The loudspeaker alert flow plays a wav file.
- I have multiple DIY speakers that play the alert around the house.
- MotionEye drives the camera, capturing stills and videos.
- The CCTV Security Cameras handle person/object detection.
- Home Assistant’s Yale Lock integration allows us to lock/unlock. The Yale lock is a Z-Wave device. Once paired with Home Assistant, it shows up as a lock and requires no further configuration.