Garage Door, meet Pebble Watch

2015-03-17 19.13.14

I love remote-controlling things.  Last week I made my Pebble Watch control our garage door.  Here’s how:


The Garage Door

To open and close the garage door I used a Raspberry Pi A+ computer connected to a 5 volt relay.  I found a great tutorial on and followed it to the letter.  It takes about an hour to set up.

Screenshot 2015-04-08 22.29.26

The tutorial leads you through configuring your Raspberry Pi as a web server on your local network.  The author provides his code for a hosted web page with a single button.  When you click on the button it tells the Raspberry Pi to briefly complete the relay circuit (like pushing your garage door’s button).

Voila!  You can control your garage door from a website in your house.  Now let’s get that control on your wrist ;-)


Adjusting the Website

Let’s take a closer look at the code in the instructable.  In the index.php file (the main page for the website) we can see the PHP code that fires the relay on button click:


The code is saying “when the ‘trigger’ (website button) is pushed, change the GPIO pin 7 (output pin on the Raspberry Pi that we have the relay plugged into) to on for 1,000,000 microseconds (1 second)”

Well this is great for controlling the door from a website, but how do we do it from our watch?

I started playing with the Pebble Watch SDK and found that with Pebble.js you can make AJAX calls super easily.  Huzzah!

Side-note: Pebble’s new web-based SDK CloudPebble is awesome.  You can write and deploy apps from within a browser and they install over the web to your smartphone, and then via bluetooth to your watch.  Welcome to 2015.

If we can make AJAX calls from our watch with Pebble.js, that means we can make a watch app that loads our Raspberry Pi’s website.  We’ll be in business if we create a special webpage on the Raspberry Pi that auto-opens the garage door when the page is loaded!

I copied the index.php page and renamed it to ‘auto.php’, then removed the IF statement in the PHP so the GPIO pin is set on page-load instead of button-click.


Now when you load the page, the garage opens.  Whoop!


Pebble Watch Control

I signed up with CloudPebble and turned Developer Mode ON in my Pebble App on my iPhone.  Then I wrote a very simple Pebble.js app that makes an AJAX GET request to the auto.php page when it’s opened.


Once you install the app on your Pebble, you should be able to open your garage door from your watch.  Boom!


‘Better’ Security 

I’m still pretty new to web development, but I know that having a page with this much physical world power, even if it’s only available on our local network, is not a good idea.  To make my system a teeny bit more secure, I added a URL Parameter password to the auto.php page:


Now, if a user visits our Raspberry Pi’s auto.php page, they’ll see “You’ve entered the wrong password”.  But if they add “?pw=ooglyboogly” to the end of the URL, the door will open!

Adjusting this on the Pebble App is as simple as changing the URL that the AJAX request uses.

Thanks for reading!