Instructables

Raspberry Pi - SMS Garage Door Butler

Featured
Picture of Raspberry Pi - SMS Garage Door Butler

Most Raspberry Pi garage door remotes had open ports, or other features I wasn't too fond of. So I created my own that contains much more security, logging of who opens the garage, video capture, garage status and more.

Features:

  • 100% secure garage door operation, with access control lists. Only authorized family members can open.
  • Ability to monitor or control garage anywhere in the world from a controlled website, with no open router ports
  • Full video capture of who's coming into the garage, uploaded securely to your website for later perusal
  • Ability to remotely stop or kill the process in case of malfunction or abuse
  • Email notifications when a family member arrives or leaves the house
  • Cheap SMS solution (3/4 a cent per text), with no GSM card purchases or any cell contracts
  • Standard Linux code, easily setup on a new Pi, and quickly portable to other platforms like BeagleBone or whatever future Linux technology arrives. Basically, I wanted the ability to restore this system on a fresh device within 30 minutes or less
 
Remove these adsRemove these ads by Signing Up

Step 1: Requirements

Picture of Requirements

You will need:

  • A Raspberry Pi or BeagleBone Black setup with base configuration. I use Raspbian Wheezy
  • Wireless connectivity via a wireless dongle (or just plug in a network cable)
  • A camera (compatible webcam or PiCam)
  • A relay board. I use "SainSmart 5V 2-Channel Solid State Relay Board", because it defaults to LOW instead of HIGH
  • Enough wire to access your garage door opener, or just break apart a spare remote
  • A website with hosting. You can get a small amount of space on DropBox or Google Drive and use that, or you can create a random website from a cheap hosting service like 1and1.com, which will provide 100gb of space for only $11 PER YEAR. You won't need to keep these files anyhow, since they're just logs.
  • If using the PiCam, a little poster putty

Step 2: Install required libraries on your Raspberry Pi

You first need a Twilio account (free, go to Twilio.com), a Twilio phone number ($1 per month) and some money in your account.

Once setup, install necessary libraries into your Raspberry Pi:

sudo apt-get install -y python-pip mysql-server python-dev libmysqlclient-dev

sudo pip install MySQL-python twilio

And create two directories:

/home/pi/movies

/home/pi/pictures

Step 3: Create SQL databases, users, permissions

Next, login to your new MySQL localhost server, and then add a user + set privs + create the database and tables needed:


mysql -pYourSQLPassword -u root -h localhost

create database GarageDoor;

use GarageDoor;

create table Door(sSid CHAR(40));

create table Authorized(sPhone CHAR(20));

create table Log(sPhone CHAR(20), sAction CHAR(10), dDate datetime);

-- put your phone number, with a +1 before it if you're inside the USA

insert into Authorized (sPhone) values ('+12145551212');

CREATE USER 'garage'@'localhost' IDENTIFIED BY 'garagepassword';

GRANT ALL PRIVILEGES ON * . * TO 'garage'@'localhost';

FLUSH PRIVILEGES;

exit;

Step 4: Hookup a relay and garage door opener

Picture of Hookup a relay and garage door opener

For this step, we'll be hooking up your Raspberry Pi's GPIO pin 23 (physical pin 16) to a relay. I like the SainSmart 4-Channel Relay Module off Amazon for about $9. Now either break apart a spare garage door remote, or just wire the relay directly to your garage door. Consult your garage manual how to do this.

You can see my spare garage remote has an obvious button that I soldered two wires to, and jammed into my relay.

Next, connect all the proper wires from your Raspberry Pi to the relay. Pin 2 = 5v. Pin 6 = Ground, and Pin 16 controls the relay. Now ensure your relay is ACTIVE LOW, which means sending a HIGH signal opens the garage. This relay off Amazon was the proper fit for me: SainSmart 5V 2-Channel Solid State Relay Board

Step 5: Add a camera

In this example, I used the Raspberry Pi camera. You can use a webcam if you're on BeagleBone Black or some other Linux computer. Click here for a list of Raspberry Pi compatible webcams

Mount the camera using some stiff wire + poster putty. You can mount on either your Raspberry Pi case, or the shelf your device is sitting on. You alternatively CAN make a fancy 3D printed larger case to house all of this inside, but I'm cheap.

Step 6: Grab the SMS Butler code, and install

Picture of Grab the SMS Butler code, and install

Grab my code from here:

https://github.com/AkiraFist/GarageSMSButler

and copy it to your Raspberry Pi, any directory is fine. Change the variables up top to your own Twilio account's phone number, and your personal cell number. Plus the Twilio authentication codes you can obtain from your account's main screen on https://www.twilio.com

And run:

sudo chmod 755 garage_sms_butler.py

python garage_sms_butler.py

Then text your Twilio phone number the word "status" (without quotation marks), and you should receive a status message back, with the last person who opened your garage door.

Step 7: Open garage, and see the results on your website

Picture of Open garage, and see the results on your website
Screenshot_2014-08-22-14-31-35.png

Command reference for the SMS Garage Butler:

OPEN - sends a HIGH signal to the relay for 0.5 seconds, thus activating the spare remote (or the door operner, if you chose direct connection) and opening the garage door. This will also upload a movie of who opened the door, to your website.

STATUS - see who last opened the garage door, and if the service is ENABLED or DISABLED. This will also upload a picture of your garage door status (YourWebSite.com/uploads/garagepic.jpg)

DISABLE - stops listening for garage opening commands

ENABLE - re-enables the service, if disabled

KILL - completely exits the application. No further commands will be processed

Now go and add your own commands!

Step 8: Questions and Answers

Picture of Questions and Answers

Why not use Motion for video capture?

Motion captures MOTION, which means it'll grab movies of me cleaning my garage, or changing the oil in my lawn mower. I only want to know who's entering my garage when it opens, not have a video blog of my garage activities. Plus this limits the video to only 60 seconds, which is enough time to see who's coming in, and who they are with.

In addition, I don't want to setup that huge file and configure all sorts of little options, including a live stream. Does anybody really want to stare at a live stream of their garage? No.

Why use a website for video uploads?

Most website providers offer a $11 per year plan for the first year of a new site. AND they'll give you about 100gb of free space. So I just created a site called blahblahblah15.com or whatever, and upload my videos there. Now I can view them online from anywhere.

If you're married to DropBox, Google drive, or Amazon hosting then replace my code with the freely available Python sources for using those services.

Why not use WebGPIO, host a Pi website and all that?

I dislike open ports to my home network. Sorry, it's a security issue. I've seen people do it (plus have a live stream to their garage - really? You want to stare into your garage all day?), but not for me.

Can't you just use Adafruit's FONA or some other SMS device?

Sure, if you want. Scanning Twilio for new texts for 3/4 a cent per text is much cheaper than doing FONA, and enrolling yourself in a cell contract.

Step 9: Credits

Picture of Credits

THANK YOU ADAFRUIT for selling me all these goodies. I haunt that store for new products daily.

This guy's garage idea got me started:

http://www.raspberrypi.org/forums/viewtopic.php?f=...

However I disliked his open port for doing the WebGPIO, and a live webcam of my boring garage seemed useless. I also didn't use a ULN2003APG chip, since I'm only connected to a CR2032 battery with the relay.

Greg's magic tricks alerted me to Twilio, and all the possibilities there:

http://www.rostamimagic.com


mrwilder6 days ago

Got it wired up over the weekend but it only stays running for 5-10 minutes before it errors out. Works fine otherwise...

Any idea where the twilio setting is to make it not respond with a confirmation that it received a message?

JessicaB322 days ago

Believe you have a typo on Step 2.

It should be

mysql-server, not

mysql-serversudo

AkiraFist (author)  JessicaB322 days ago

Good catch, Jessica, thank you! I just fixed the typo.

AkiraFist (author) 25 days ago

Jliberman, yes! You can use Amazon Simple Notification services:

http://aws.amazon.com/sns, or any other method you choose. Your Pi has an internet connection, so whatever API you can find, or internet JSON call you can use would work great.

Adafruit has a great example page here using SNS:

https://learn.adafruit.com/sms-texting-pet-food-dish/amazon-sns-setup

jliberman26 days ago
Could You use a different Texting provider? Such as WhatsApp or another compatible with the Pi?
AkiraFist (author) 26 days ago

Hi Scumm7, yes you need wireless or wired connectivity from the Raspberry Pi to communicate with Twilio.

Scumm726 days ago

So is it still using ethernet or Wifi to send the SMS message? I assume it must be, but I thought maybe I missed something.

wilgubeast27 days ago

This is awesome. Wish it had a garage livestream. What's happening in there all day? Is it like Toy Story, but for tools?