Using a Raspberry Pi and MotionEyeOS To Create a Home Security Camera

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:

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:

Encased with a 3D printed case, with the Xbox WebCam cord visible on top
Raspberry Pi with NoIR Camera mounted onto it, pointed towards the driveway
The Xbox 360 WebCam mounted towards the front Door
A screenshot of a motion notification from Pushover
Password Protected image viewing
The online image viewer that uses h5ai

 

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:

File Storage settings

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:

#!/bin/bash

DATE=$3
FILENAME=/data/media/motioneye_192_168_2_77_wyatt_hdd_security_${2,,}/$3/$1.jpg
CAMERA=$2

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.

Still Images settings

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.

Motion notification settings

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

#!/bin/bash

DATE=$3
TIME=$1
CAMERA=$2

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.

One thought on “Using a Raspberry Pi and MotionEyeOS To Create a Home Security Camera”

  1. Hi. I have checked your wyattmarks.com and i see you’ve got some duplicate content
    so probably it is the reason that you don’t rank hi in google.
    But you can fix this issue fast. There is a tool that creates content like human, just search in google:
    miftolo’s tools

Leave a Reply

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