Setup Motion on Raspberry Pi with Email Motion Alert

As postfix config use „Direct SMTP“ option, if necessary enable TLS:

You can test if everything works correctly with:

Now its time to get a version of motion tailored for the raspicam:

Add the freshly created motion user and yourself to the video group just for good measure:

Otherwise the motion service may fail silently with * failed to open vchiq instance

Enable and start the motion daemon with

Create a directory for motion’s videos and log files:

Make some adjustments to motion.conf, especially the paths for logs and videos:

and change
on_picture_save echo ‚Motion alert‘ | mail -a %f -s „Motion alert“

and reload the config file:

Create a directory for motion’s videos and log files:

Check if the motion process is running by

motion 7676 82.4 2.6 91488 23656 ? Sl 13:00 1:33 /usr/bin/motion

If there is no running motion process, check the service status for additional details why motion exited:

The output should look like:

● motion.service - LSB: Start Motion detection
Loaded: loaded (/etc/init.d/motion)
Active: active (running) since Sat 2016-06-11 13:00:30 CEST; 1s ago
Process: 7662 ExecStop=/etc/init.d/motion stop (code=exited, status=0/SUCCESS)
Process: 7669 ExecStart=/etc/init.d/motion start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/motion.service
└─7676 /usr/bin/motion

Jun 11 13:00:30 raspberrypi3 motion[7669]: Starting motion detection daemon: motion.
Jun 11 13:00:30 raspberrypi3 systemd[1]: Started LSB: Start Motion detection.
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] conf_load: Processing thread 0 - config file /etc/motion.conf
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] motion_startup: Motion mmaltest Started
Jun 11 13:00:30 raspberrypi3 motion[7676]: [0] [NTC] [ALL] motion_startup: Logging to file (/home/tatsch/motion/motion.log)

If motion is setup correctly, you should be able to see the web stream:


If you are unable to open the stream, check if motion is listening on the port:

Mask for motion

If you get a lot of false positives from the motion detection with your webcam or raspicam you should consider masking out the susceptible parts (busy streets, moving leaves etc.).

Simply take a false positive frame from your motion setup e.g. with VLC -> Video -> Snapshot. The mask must have exactly the same size as the image:


Select the area where the motion should be masked out, fill it with black, invert the selection and fill the rest white. Save as jpeg and convert to pgm with imagemagick

or a jpeg-to-pgm converter.


Now you can transfer the mask via scp or directly download the pgm file with:

and add the mask in your motion config file by:

and adjusting the mask_file path as follows:

# PGM file to use as a sensitivity mask.
# Full path name to. (Default: not defined)
mask_file /home/motion/mask.pgm

Finally restart the motion daemon:

and you should get a lot less false positive motion detections.