Emailing or Tweeting when motion is detected on your web cam

twitter.pngHi again everyone.

In the previous 2 posts we’ve setup an Xbox LIVE Vision Cam in Ubuntu then we Set it up to trigger on Motion. Now in this post we’re going to build on this and have it send us a notification via email or via a tweet on twitter.

What we’ll need

  1. The Ubuntu/Webcam setup from the previous 2 posts
  2. An internet connection
  3. A twitter.com account or an email address

First things first open up a terminal window

type

sudo vi /etc/motion/motion.conf

(or sudo gedit /etc/motion/motion.conf if you’re using a gui)
to open up the Motion config file.

we’re looking for the “locate” item and we want to change this from “off” to “on”

This will draw a border around the motion in the image.

Next we need to find the “on_motion_detected” line. This is where the magic happens
This line will allow us to define a command to run when motion is detected.

Now like I stated in the beginning we have 2 options we can send the message via email or we can send it via twitter. I’ll begin by showing you how to send the message via twitter.

We need to replace the entire line

; on_motion_detected value

with

on_motion_detected wget -O - --user=TWITTERUSERNAME --password=TWITTERPASSWORD \\
--post-data=”status=Your Message” https://twitter.com/statuses/update.xml

Save your file and restart motion (as covered in the previous article)
Now when motion is triggered you’ll post a tweet with the message you set in the command above.

Now to have it send you an email message there’s an extra step.
We have to install “mailutils”

So run the command

sudo apt-get install mailutils

Once that’s done installing we now have access to the “mail” command

So we need to edit the “on_motion_detected” item in the motion.conf file like for the twitter command above.

type

sudo vi /etc/motion/motion.conf

(or sudo gedit /etc/motion/motion.conf if you’re using a gui)
to open up the Motion config file.

And edit the

; on_motion_detected value

line to read

on_motion_detected echo "Your Message" |mail -s"Email Subject" your@email.addr

Save your file and restart motion (as covered in the previous article)

Now just as with the twitter command when your webcam sees motion an email will be sent off to the email address you set in the command above.

Make sure to check out the previous posts in this series Setup an Xbox LIVE Vision Cam in Ubuntu and Web Cam Motion Detection with Xbox LIVE cam and
As always post any questions, comments or other input in the comment section.
Cheers!

If you enjoyed this post, make sure you subscribe to my RSS feed!

Published by

LiamM

I'm a self labeled Nerd who enjoys Playing Video Games, restoring classic muscle cars (i have a 65' Mustang in the works) , Running Big Data Clusters, Tattoos, Working on System Automation, Riding and customizing Motorcycles, and writing python Code. I'm an SRE with DemonWare/Activision Specializing in Big Data/Hadoop operations but all opinions and views expressed on this site are solely my own.