A few years ago, I had the desire to create a home security system. I at least wanted the ability to be notified when someone arrived at my house, and an image of them would be even better. I wasn’t as into Arduino and other microprocessors back then as I am now, however, I did like to tinker with Raspberry Pi’s.
So of course, I had an extra laying around. I started to see if anyone else had done something similar before. That was when I discovered MotionEyeOS. It is a lean Linux distribution designed for small computers like the Raspberry Pi. It is a very well made system, and I have been using it with few, although there have been some, errors for years.
In this project, I used all these parts:
- 2x Raspberry Pi 3 Model B
- 2x 5V 2.5A MicroUSB Power Supplies
- Raspberry Pi NoIR Camera Module V2
- Xbox 360 Webcam
- Large External HDD
- 2x 8GB SD Cards (although size shouldn’t really matter)
The reason I’m using two Raspberry Pi’s is because I wanted to store the photos long-term on my own HDD. My HDD is being used, however, to house my media on another Raspberry Pi that is running LibreELEC as a media center. I’ll have another post about that, soon. This isn’t an issue for me, however. LibreELEC supports mounting the HDD on the network as a SAMBA share, and MotionEye supports saving images to SAMBA shares. If you wanted to only use one RPi and a USB Flash Drive that would work fine, too.
Here are some photos that show system and its functionality:
The software I used to make this all happen includes:
Alright, now I’ll go ahead and explain how I set it all up. I’m not going to go into detail for every step, however if someone wants more depth on a specific part let me know.
First, I installed MotionEyeOS onto my RPi using this tutorial. After getting it set up, I plugged in each of my cameras and configured them how I wanted. Then, I set the following options as follows:
I added the SAMBA share here, using the IP from my other RPi and the appropriate folder on the HDD. The command that I run to upload the picture to my external site is here, too. The whole command is
/root/upload.sh %H-%M-%S Doors %Y-%m-%d
Now, the upload.sh script contains this code:
ssh EXTERNALDOMAIN “mkdir -p /usr/share/nginx/www/security/$CAMERA/$DATE”
echo “mkdir -p /usr/share/nginx/www/security/$CAMERA/$DATE”
scp $FILENAME user@EXTERNALDOMAIN:/usr/share/nginx/www/security/$CAMERA/$DATE/$1.jpg
This script is pretty simple. It creates the current day’s folder on the server if it doesn’t exist, then uploads it. The RPi uses certificates so that it doesn’t require a password every time it uploads a photo.
I set the RPi to save still images when it detects motion. I also set the filename to match what I have in my scripts.
I could have easily just used a web hook to interface with Pushover, however I wanted to have my own script, as I may redo this project using an ESP8266 and a camera module. The command here is
/root/motion.sh %H:%M Doors %Y-%m-%d
and the code inside motion.sh is
curl –data “token=REVOKED&user=REVOKED&message=$CAMERA&title=Motion Detected&url=https://EXTERNALDOMAIN/security/$CAMERA/$DATE/&sound=pushover” https://api.pushover.net/1/messages.json
This uses the API from Pushover, which is a paid app that lets you send yourself push notifications. I could have written my own app for this, however Pushover was quick and easy to use.
For a password protected link I used NGINX and its .htpassword support. A good tutorial on how to do that can be seen here.
The default folder browser for NGINX is ugly and doesn’t let you view the images easily. To make it look slightly prettier and easier to use I installed h5ai. Their website is a good place to start if you have never used it before.
This setup has been running well for a few years now, like I said. But I’d also like to redo it, using motion sensors and ESP8266’s. A setup like that would be cheaper and allow me to have cameras all around the house, not just the front door and driveway. If I ever get around to making a setup like that, I’ll make a new post! Thanks for reading.