Worried about someone breaking into your house in your absence? Or just need to keep a tab on who enters your room while you are away? Well, all you need is a webcam, a linux PC/laptop and a twitter account. And you are set for real time updates through twitter about all that goes on at your abode behind your back (can even receive a text message/sms on your phone). Keep reading for the very simple setup you need.
1.) Download and install “motion” on your computer. For ubuntu users, this is as simple as running
sudo apt-get install motion
2.) Setup your motion configuration file. (Usually at /etc/motion/motion.conf). There are quite a lot of options available. You might want to tweak it a lot according to ur needs later on but the most important ones that you can begin with are (leave the rest untouched for now):
2a.) Add/edit the option “target_dir” to point to the directory where you want to save the images of the event when motion is detected.
2b.) Add/edit the option “locate” and set it to “on” so that you get a nice square box around the detected moving object/person.
2c.) Add/edit the option “webcam_port” and set it to, say, “8000″. Motion includes a mini http server so now, you can use it to view the actual images of the happening when you get the update and check for false alarms.
3.) Now, comes the most important part, about getting the update.
motion has an option called “on_motion_detected” and here you can specify any command or program that you want to run when motion is detected. To get the update on your twitter account, use one of the following three methods with this option.
3a.) Using curl. If you have curl installed in your system, then you can use the following value for the on_motion_detected option:
curl -u yourusername:yourpassword -d status=”Motion Detected! Check Immediately” https://twitter.com/statuses/update.xml
3b.) Using wget. If you don’t have curl, you can even use wget for this. Use the following value:
wget -O - --user=YOURUSERNAME --password=YOURPASSWORD --post-data=”status=Motion Detected! Check Immediately” https://twitter.com/statuses/update.xml
3c.) Using my perl script. If you don’t have curl as well as wget, you can even use my perl script (attached below) for this. The value will now be:
/path/to/script/twitter.pl "Motion Detected! Check Immediately"
4) Now connect your webcam and start motion (Just type “motion” on command line and press enter). Wait for someone to break in, or just roam around in front of the camera yourself and have fun as you receive a message on your phone about the “motion”.
PS: For receiving a text message on your phone, you’ll need to turn on the “Device Updates” option in your twitter account, otherwise you need to open the twitter web page to check the status.
The script: Twitter Updating Perl Script
Let me know if you put this to some other exciting uses or have any questions about the method described above.



I haven’t written anything in a while, but a creative hack like this is a great catalyst. Keep up the good work. This is an excellent tutorial.
For some users, I think this technique might be more accurate if the notification message was “Cat Detected! Check immediately!”
Keep Tab On Home Security With A Webcam And Twitter | nerdd.net…
\r\nWorried about someone breaking into your house in your absence? Or just need to keep a tab on wh…
Hey …. second post on Lifehacker …
Cheers!
@Amy: Thanks…
@John: Didn’t get you…Do u mean, context based messages?
@Coolant: Thanks man..
@Shantanu: I think John means that motion isn’t the best criteria for an alert if you have pets moving around all day.
@Chris: yeah, thats true..Basically how I am using it is with the inbuilt webserver capability of motion. If/when I get a message, I simply connect to my webcam images at myipaddress:someport through my phone or office PC’s browser and check whats the cause of the motion. But apart from that I’d say it’s very difficult to formulate the message acc to the object causing the motion.
Note: I have a dynamic ip address, so the script that I use gets my ip from the web and sends that to me as well in the message
[...] command line work, but it’s spelled out and explained pretty thoroughly. Photo by MShades. Keep Tab On Home Security With A Webcam And Twitter [My Technophilic [...]
I’ve done everything in this guide, yet it won’t send the updates to my phone. It updates on the site (I’ve added the device and everything, set up updates etc) but I can’t follow myself and it doesn’t send the updates to my phone…
@blu: Oops, there is a small thing I forgot. What you need to do is create another account, and follow it, and send the tweets to that new account. Otherwise you can post direct messages to yourself (d yourusername message), that should also work.
Motion is working, I set up two twitter accounts, one following the other, however motion is not posting the alerts to my 1st twitter account.I tried all 3 methods, any idea on what I’m doing wrong?
@steven: Can you check if any of the commands are being run. I mean replace the twitter command by something like “touch ~/abc.txt” and see if on detecting motion the file is created in ur home directory or not.
abc.txt was createdhere’s the response when I run motion with curlscr@scr-desktop:~$ motion[0] Processing thread 0 – config file /etc/motion/motion.conf[0] Motion 3.2.9 Started[0] ffmpeg LIBAVCODEC_BUILD 3352064 LIBAVFORMAT_BUILD 3344896[0] Thread 1 is from /etc/motion/motion.conf[1] Thread 1 started[0] motion-httpd/3.2.9 running, accepting connections[0] motion-httpd: waiting for data on port TCP 8080[1] Not a V4L2 device?[1] Using VIDEO_PALETTE_YUV420P palette[1] Using V4L1[1] Started stream webcam server in port 8000[1] File of type 8 saved to: /home/scr/Webcam_Pictures/01-20080520091845.swf[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091845-01.jpgcurl: (6) Couldn’t resolve host ‘Detected!’curl: (6) Couldn’t resolve host ‘Check’curl: (6) Couldn’t resolve host ‘Immediatelyâ��’[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091846-00.jpg[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091846-01.jpg[1] File of type 1 saved to: /home/scr/Webcam_Pictures/01-20080520091847-00.jpg Tue May 20 12:51:58 +0000 2008 815714179 ”Motion web false false 14834776 sredd1701 sredd1701 false 1
Steve: I found the issue. It seems that for many users this is causing a problem if they have spaces inside their “message” even if it is surrounded by quotes. A simple solution would be to use smthing like “MotionDetected” instead of “Motion Detected! Check Immediately”, otherwise u can just hardcode the command and message into a shell script and just call that script instead.
Thanks for the response. I figured that out about an hour ago myself, just didn’t get around to telling you until now. Also, it may just be my phone service, but if I don’t delete the text message when I get it, another message with the same text will not be received.
BTW, I’m using a cheap Logitech Quickcam Chat webcam, less than $20 and it worked ootb with Ubuntu Hardy!
The picture quality isn’t great, But you get what you pay for.
Thanks again for all your help.
Sorry to bother you again, and yes, I’m a real noob on linux, but I’m still having 2 problems. First when motion updates my twitter account, I don’t always get a text on the update. This sounds like a twitter problem, so I’ll pursue it there. Second, it seems that twitter doesn’t update if the current message is the same as the previous one. Is there a way to rotate messages or send a message plus a random number to insure that twitter updates?
Also, if someone breaks in and steals my computer, I’ve lost all pics of him. Is there a way to have motion email the pics to my Gmail account?
Steve: As u mentioned the first 2 are twitter problems. But we can work around the second problem. For that, instead of having the command itself in motion.conf, you can create a shell script (a simple text file with #!/bin/bash in the beginning and then ur command). And in the command you can append `date` to your “message”. So everytime the current time will be added to msg making it unique. Call this script in ur motion.conf. Let me know if u need more help with this.
About the third issue. You can mail them easily using a command line mail client (like mutt) but you’ll have to set it up. U can google for how to set it up to be able to send mail and then just add the proper command line for it in motion.conf (or in ur shell script so u get twitter update as well as mail.). Again, lemme know if u need more clarification.
As I said before, I’m new to Linux so I’ve never written any kind of script before. But now seems like a good time to learn something new! Well, I’m off to Google how to write shell scripts!
Thanks for all the great advice.
[...] A Ubuntu user wrote a tutorial that details how to use a webcam tool to notify you via Twitter when there is any suspicious movement in your home. The notifications can also be sent to you as text messages to your mobile phone. Filed under Linux | var disqus_url = ‘http://www.twitterholics.com/?p=569 ‘; var disqus_title = ‘Home Security via Twitter (Linux Only)’; var disqus_message = ‘A Ubuntu user wrote a tutorial that details how to use a webcam tool to notify you via Twitter when there is any suspicious movement in your home. The notifications can also be sent to you as text messages to your mobile phone.%0A’; View the entire comment thread. [...]
That’s pretty nifty.
Nice piece of integration. For those with pets, it might be fun to set up the camera with a field of view that allows some inference about what the pet is up to (scratching at door, poking at food bowl, ..) – then the pet could have its own twitter account updating with its status.
[...] other news, my Twitter-Webcam integration post has bypassed my earlier lifehacked post about Remote File Access Through E-mail by more than a few [...]
[...] WikiViz is a Java program that renders graphical representations of graphs containing nodes and edges. In this case, the nodes are Wikipedia category pages and the edges are links between pages. The algorithm works by first placing each node, and then iteratively moving strongly linked nodes closer together and springing weakly linked nodes farther apart. Overlapping nodes are nudged away from each other by a different proccess. WikiViz can be used on other datasets such as related books in Amazon. Home Security Via Twitter and a Webcam [...]
[...] command line work, but it’s spelled out and explained pretty thoroughly. Photo by MShades. Keep Tab On Home Security With A Webcam And Twitter [My Technophilic [...]
How do you know if your computer is linux or not?
If you combine the motion program with the following script http://lifehacker.com/software/hack-attack/automatically-upload-a-folders-photos-to-flickr-262311.php , it can also post pictures to a flickr account, so you can automatically see the cause of the twitter update.
PJ: was that a joke?
USP: That’s a cool tip. Thanks. I’ll see if I can collect some of the tips/discussions done here in comments and update the post with them. Some of the things included would be tips about different things that can be done and also how to use this in windows..
[...] avez envie de faire pareil ? Alors rien de plus simple, toutes les explications se trouvent ici… Moi j’aurais bien envie de l’améliorer son script [...]
Yeah, I had a brain lapse for a minute. Sorry
I know some things but I am still new to all of this.
[...] Keep Tab On Home Security With A Webcam And Twitter | My Technophilic Musings (tags: security twitter webcam linux surveillance hacks diy electronics) [...]
The problem in the twitter command (“Motion Detected”) isn’t the spaces, it has to do with the direct copy and paste of the command into Motion. When you copy and pase the command, delete the quotation marks that are in the command, and then manually type them back in with your keyboard.
[...] room while you are away? Well, all you need is a webcam, a linux PC/laptop and a twitter account.read more | digg story Click Here – Tell the World These icons link to social bookmarking sites where [...]
[...] Tech.shantanugoel.com writes about how to create a do-it-yourself security system using nothing more than a Linux PC, Webcam, and a Twitter account. [...]
Awesome stuff !! I just configured motion at my house sitting in the office. I hope someone breaks in just so that I get to see this work
Great tips! Hopefully this can be a cheap and easy way to improve home security.
[...] Goel has an interesting post on how to turn your Linux PC/Laptop into a surveillance system using a webcam and Twitter. No [...]
[...] you want to keep taps on who sneaks in and borrows your lipstick while you’re gone, check out this site on how to set up your webcam to work as a security cam and take pictures and better yet sends them [...]
Mersi boku. Good idea. I’ll become your regular visitor and RSS subscriber.
We put together a Google Mashup with FBI crime data, Craigslist defense and safety classes and the Google map. Check out the application in action:
http://www.homesecurity8.com/map/Washington/Seattle.html
P.S. We would really like to know if their is other data that we can feed into this mashup or if anyone has any suggestions on how to improve it.
[...] Linux Motion App + Twitter (or Identi.ca) = real-time remote home security monitoring. [...]
Great work and great tutorial ! Do you have any ideas, also, if you can get voice/sound using your script ?
Can you explain a little more how to send the pictures through mail?
Hi, everybody
This has to be the best use for twitter I’ve seen yet.
Thanks, Jay
[...] plantado alguna vez que con una webcam, Twitter y un software para Ubuntu se pueda montar un sistema de vigilancia para tu casa? Pues por descabellado que parezca, hay quien lo hace y además te explica cómo llevarlo a la [...]
Hello i will be glad if you can take me step by step on how to set the security web cam up i am new to linux i just dont understand the procedure also i just cant use my webcam i am using toshiba satellite 300d i really need your help i have been using this laptop for some time now and i cant get my webcam to work also i am running ubuntume 8.10 i will be glad if you can take me through this u can send me the detail to my email as well
[...] Keep Tab On Home Security With A Webcam And Twitter Worried about someone breaking into your house in your absence? Or just need to keep a tab on who enters your room while you are away? Well, all you need is a webcam, a linux PC/laptop and a twitter account. [...]
Hello, Im from Brazil.
Using Lynx :
echo ’status=Motion Detected! Check Immediately’ | lynx –auth=USER:PASSWORD –dump -post_data http://twitter.com/statuses/update.xml
Very useful resource! Thank you Shant – I’ve added your blog post to one of my newer blog entries.
P.S. Would motion cameras work equally well?
I like the idea but i cant get it to work with the perl script. Do I need to edit the perl script? Where do I paste the perl script command? After track_type?
I’m really confused on the last step. I’m a total ubuntu 8.04 noob. Help me please! thanks.
@Richard: You need to paste the script command after “on_motion_detected” and not “track_type”. Also sending you an email. Check that.
Thats really cool, I’m going to try that out, thanks for sharing that.
[...] Linux hacker Shantanu Goel set up a video camera and some motion-sensing software on a PC connected to the internet. If anyone breaks into his house or goes snooping through his room, the software detects the movement and sends out a tweet. [...]
[...] Linux hacker Shantanu Goel set up a video camera and some motion-sensing software on a PC connected to the internet. If anyone breaks into his house or goes snooping through his room, the software detects the movement and sends out a tweet. [...]
I’ve just finished a similar project, this time with a bit of hardware connected to a burglar alarm:
http://www.kelvinsthunderstorm.com/2009/02/twitter-burglar-alarm/
@Kelvin: That’s awesome..Keep it up..I’d be watching out your blog for more of your hacks with twitter and/or Arduino..
[...] Linux hacker Shantanu Goel set up a video camera and some motion-sensing software on a PC connected to the internet. If anyone breaks into his house or goes snooping through his room, the software detects the movement and sends out a tweet. [...]
Very nice twitter hack!
http://www.brackhole.com
[...] Linux hacker Shantanu Goel set up a video camera and some motion-sensing software on a PC connected to the internet. If anyone breaks into his house or goes snooping through his room, the software detects the movement and sends out a tweet. [...]
Here is a list of applications that do similar motion capture on PC, you should add your application there. http://www.ugolog.com/pages/25-applications-to-turn-your-webcam-into-home-security-system
[...] need is your computer, a webcam and a twitter account to get real time tweets from your home. Click here for the simple set up. Comments [...]
set up a secondary twitter account just for this purpose, then follow it.
[...] Linux hacker Shantanu Goel set up a video camera and some motion-sensing software on a PC connected to the internet. If anyone breaks into his house or goes snooping through his room, the software detects the movement and sends out a tweet. [...]
Can Twitter really Be Saved?
[...] você pode baixar do Download INFO , o script em Perl criado pelo programador Shantanu Goel. O script identifica que o motion capturou uma imagem e envia uma mensagem personalizada para o [...]
home security is an important issue to protect your home and its assets.The best home security can be as little as a simple alarm system or it can be as intricate as highly advanced infrared motion detectors. Regardless of housing cost, reliability is the most important aspect of the best home security system.
Hi,
Wonder if you can advise, have added ‘curl’ command ‘on motion detect’ in config file, but it seems to only work once. Files still get saved on subsequent motion detect but the curl command is not execute after the first motion detect.
Your advice will be appreciated.
Cheers,
Ken
[...] It also provides triggers for when motion is captured (for example, if you’d like to update Twitter you can do this with [...]
I made a little Curl script to publish images to TwitPic too – it uses on_picture_save which is a little clumsy, since it uploads 100s of images to Twitter – oops!!!
If someone can think of a way of posting one image from a series of a few in one motion event please let me know..
#!/bin/bash
IMG=$1
USERNAME=
PASSWORD=
curl -F”username=$USERNAME” -F”password=$PASSWORD” -F”message=Motion Detected!” -Fmedia=@”$IMG” http://twitpic.com/api/uploadAndPost
You then need to call this from on_picture_save with %f as the argument.
I came across an article in The Times of India, Mumbai edition about “Keep Tab On Home Security With A Webcam And Twitter”. I want shantanugoel to show me a project that talks about being able to receive messages through internet and through mobile when an intruder walks into the house and I am at a distant place. I want something that is compatible with Windows XP. I am good in creating electronic hardware projects which involves soldering and fault finding jobs. However, I am not so well versed with software projects. Can Shantanu or anyone help me to acquire a security monitoring project, as explained above.
[...] WikiViz is a Java program that renders graphical representations of graphs containing nodes and edges. In this case, the nodes are Wikipedia category pages and the edges are links between pages. The algorithm works by first placing each node, and then iteratively moving strongly linked nodes closer together and springing weakly linked nodes farther apart. Overlapping nodes are nudged away from each other by a different process. WikiViz can be used on other datasets such as related books in Amazon. Home Security Via Twitter and a Webcam [...]
(Sorry I think there must be a character limit on these posts…)
Heyy just wondering before I venture into this project, is it possible to be using multiple webcams? I have about 12 webcams (got them from china for a pretty sweet price)
I’d like to be able to combine the images in somewhat of a matrix using the 12 snapshots so that when browsing through the pictures I can have it shown something like this:
(Part 2)
Okay maybe it just doesn’t like my ASCII matrix I made to illustrate;
I want it to show camera images like this:
1234
5678
9012 (last row 0 meaning 10, 11, 12)
That way when you move through browsing the pictures you see all the cameras at one specific time stamp then you can move to the next photo and so on so that instead of looking though separate folders say “front door”, “back window” on the http server you just have to look at one folder of pictures.
I’d also want to time stamp the script.
And one last thing, just wondering if I’d be able to set it to automatically upload to an ftp server somewhere when it detects motion so that if the main computer gets stolen somehow I can just look at the ftp server images. (Just uploading the motion detected images so as not to kill my bandwidth)
I’m pretty good with ubuntu just not so much the scripting side of it.
Shantanu Goel this is an awesome post and if you’d like a challenge you should give my ideas a try
Annnnnnd one last thought;
Does this script you made compare the original image with future ones or does it compare each image to the next one. ’cause say if I had a leaning tower of pizza boxes (typical me) and it fell over, I don’t want to be receiving a twitter message every second (timestamps make for different messages) because pizza boxes fell over and it thinks theres an intruder. I’d like to have some way of remotely resetting its reference image so that once the pizza boxes have fallen I can tell it “heyy capture this images with the fallen boxes and stop looking at the original where the boxes are still on the table”
Do you sorta get what I mean?
@Alvinator:
1. Yes, it is possible to use multiple webcams but you’d need to modify the script to handle them (probably pass parameters for each camera to the script to identify them)
2. Styling it how you want (9 different feeds on one page) should be possible too but your would need to probably run your own web server and throw together a custom page. Because as far as I know, “motion” (the software used to do actual motion detection here) gives each feed it’s own url otherwise.
3. The images are compared to the immediately previous images only. So, for a pizza box falling, you will get the notification only when the pizza box actually fell and not after that. Please note that this part is again handled by the “motion” software and not by the script itself.
Alrighty, cool thanks
Check out Webcam Zone Trigger.
http://www.zonetrigger.com
With this software you can setup hot spots to detect motion, each hot spot can perform a different task when it detects motion. So you can had it run a command line with different parameters (or run a different .bat file).
wget -O – –user=USERNAME –password=PASSWORD –post-data=”status=Motion” https://twitter.com/statuses/update.xml
–2011-04-22 09:43:59– https://twitter.com/statuses/update.xml
Resolving twitter.com… 199.59.148.82, 199.59.148.10, 199.59.148.83
Connecting to twitter.com|199.59.148.82|:443… connected.
HTTP request sent, awaiting response… 401 Unauthorized
Unknown authentication scheme.
Authorization failed.
why ?
[...] Keep Tab On Home Security With A Webcam And Twitter Motion [...]
[...] command line work, but it’s spelled out and explained pretty thoroughly. Photo by MShades. Keep Tab On Home Security With A Webcam And Twitter [My Technophilic [...]