How to Automate Your Garage Door With IFTTT and Raspberry Pi

Hamish Dowell 15-10-2018

Smart home gadgets are cool but can be expensive. With a Raspberry Pi and a component or two, it’s easy and cheap to connect existing devices to the internet.


Making your garage door internet-aware is a great introduction to learning how to control the real world with a Pi. And let’s be honest, who doesn’t want to feel a bit like Batman and have their garage open by itself when they pull into their driveway?

What You’ll Need

To automate your garage door, you will need:

Once you’ve collected those components together, it’s time to get started.

How This Automated Garage Door Works

Most garage door motors can be triggered to open or close through an external input. Manufacturers include these inputs so that installers can hook up a simple push button somewhere in the home to open or close the door without using the regular remote. When a trigger button is pushed and released, it momentarily closes a circuit which tells the motor to start or stop.

You’re going use a relay in place of an external button. Closing the relay briefly will close the circuit, exactly as if a trigger button had been pressed. A Python script running on the Raspberry Pi will let you control the relay, and therefore the door, from your home network.


Step 1: Connect the Raspberry Pi to the Relay

You’ll be making at least four connections between your Raspberry Pi and the relay board. If you’re using a Pi Zero you will either need to solder the connections directly, or solder a GPIO header to the Pi and use jumper wires for the connections. The latter option is recommended because if you ever want to disconnect the relay board and use the Raspberry Pi for something else, you won’t have to de-solder your connections. The bigger model Pis already have header pins for connecting push-on jumper cables.

If you’re new to using the GPIO, be sure to read our article Everything You Need to Know About Raspberry Pi GPIO Pins Everything You Need to Know About Raspberry Pi GPIO Pins The Raspberry Pi is a fantastic little computer, but what do the GPIO (General Purpose Input/Output) pins do exactly? In short, they open up a whole world of DIY electronic tinkering and invention. Read More .

Before hooking everything up, check to see if your relay board has a jumper connecting the VCC and JD-VCC pins together. If it has, remove it, because you’ll need to power VCC and JD-VCC separately.

Relay board JD-VCC to VCC jumper


With everything powered down, connect the relay board to your Pi as follows:

  • Begin by connecting Pi Pin 2 (5V rail) to the JD-VCC on the relay board.
  • Connect Pi Pin 1 or Pin 17 (3.3V rail) to VCC on the relay board.
  • Connect Pi Pin 6 (GND) to GND on the relay board.
  • Finally, connect Pi Pin 7 (GPIO 4) to IN1 on the relay board. This is the connection that switches the relay.

If you have more than one garage door, or if you want to add control for electric gates, you should add extra connections between IN2, IN3, etc. on the relay board and other free GPIO input/output pins on the Pi.

Raspberry Pi connected to a relay board

Step 2: Install Dependencies on the Raspberry Pi

Raspbian comes with Python pre-installed, but you will need to add the GPIO library. Type the following into the terminal window on your Pi:

sudo apt-get update
sudo apt-get -y install python-rpi.gpio

Now make a new folder in your home directory, somewhere to put the Python script that’s going to control the relays:

mkdir ~/garagedoor
cd ~/garagedoor

Finally, download bottle, a lightweight framework that will create a simple web server on your Pi:


Step 3: Create the Control Script

Here’s a very simple Python script to control the relay board via HTTP:

# Python Script To Control Garage Door

# Load libraries
import RPi.GPIO as GPIO
import time
from bottle import route, run, template

# Set up the GPIO pins
GPIO.setup(7, GPIO.OUT)
GPIO.setup(11, GPIO.OUT)
GPIO.output(7, True)   
GPIO.output(11, True)

# Handle http requests to the root address
def index():
 return 'Go away.'

# Handle http requests to /garagedoor
def garagedoor(doornum=0):
 if doornum == '0':
 return 'No door number specified'

 elif doornum == '1':
 GPIO.output(7, False)
 GPIO.output(7, True)
 return 'Door number 1 cycled.'

 elif doornum == '2':
 GPIO.output(11, False)
 GPIO.output(11, True)

 return 'Door number 2 cycled'

run(host='', port=1234)

On your Raspberry Pi, create a new Python file using nano:


Copy and paste the script above into the empty document. Exit and save with CTRL+X, then Y, and Enter to confirm.

Now test the script by running it:


If everything is working, you will see a message like this:

Python script running message

If you get any error messages, check that everything got pasted into the file correctly and that you don’t have another web server like Apache running on the same port (it will interfere with the server the script creates).

Assuming there are no errors, go to a web browser on another computer on the same network, and into the address bar type the IP address of your Pi followed by a colon and 1234. For example, if the IP address of your Raspberry Pi was, you would type into your browser.

If everything works, you will see a message telling you to go away!

Now add /garagedoor/1 after the IP address and port number, like this:

Hit Enter, and you should hear the first relay on the board click twice as it closes and opens again. If you change the 1 to a 2 and reload the page, you’ll hear the second relay cycle.

Step 4: Connect the Relay to the Door Motor

Refer to your garage door motor manual to find where an external controller can be connected. Attach the two-core cable to it, and connect up the other end of the cable to the relay board’s screw terminals.

Relay board connections to door motor

There are three terminals per relay—use the normally open pair as shown in the picture.

Garage door motor connection

Test everything from the web browser again (you can just refresh the page). If all goes well, the relay will click a couple of times and your garage door should start to open.

Step 5: Set the Script to Autoload

If your Raspberry Pi reboots for any reason, such as a power outage, your Python script will stop running. To make it load on startup, add the following line to your /etc/sc.local file (if you are logged into your Pi as a different user, change Pi to your username):

nohup python /home/pi/garagedoor/ &

Do this using your usual text editor, saving the file when you’re done.

Security Considerations to Keep in Mind

There is no kind of security on this sample Python script—anyone who can access your Raspberry Pi via its IP address will be able to open and close your garage door. It’s tempting to think that just because nobody knows your script is there, nobody will find it, but security through obscurity has been shown time and again to be a bad idea.

A full authentication system is beyond the scope of this tutorial, but a simple solution to security is to not make your Pi accessible outside of your home network.

Here are some more tips for securing your Raspberry Pi Securing Your Raspberry Pi: From Passwords to Firewalls Anyone can use Google to find the default username and password of your Raspberry Pi. Don’t give intruders that chance! Read More .

Controlling Your Garage Door With IFTTT or Siri

If you do choose to make your Pi accessible from the open internet, you can control your garage door from services like If This Then That (IFTTT). For example, you can combine the Alexa and Webhooks IFTTT services to open your garage door when you say a trigger phrase to an Amazon Echo.

IFTTT Alexa and webhook applet

If you drive a car with an IFTTT connected service, you could create an applet How to Use IFTTT Applets With Advanced Filters to Superpower Your Tasks IFTTT applets can automate almost anything. But did you know you can also create sophisticated applets with special IFTTT filters? Read More to open the door as your car approaches your property, Batman-style.

Want to know more? See our downloadable guide to using IFTTT like a pro The Ultimate IFTTT Guide: Use the Web's Most Powerful Tool Like a Pro If This Then That, also known as IFTTT is a free web-based service to get your apps and devices working together. Not sure how to build your applet? Follow along with this guide. Read More .

Another way to trigger your newly internet-aware garage door is with a Siri shortcut. Putting a really simple shortcut into your widgets means you can forget about carrying annoying keys and instead open your garage with a swipe and tap on your iPhone.

Siri shortcut to call garage door script

Beyond the Garage: More DIY Smart Home Projects

Relay boards can switch mains voltage and so can control most household appliances. This project can serve as the basis for adding smarts to almost anything with a power supply. Coffee machines, lighting, air conditioners—all are ripe for automating with a Raspberry Pi and some relays.

Interested in ways to automate your ceiling fan 7 Simple Ways to Automate Your Ceiling Fan During hot summer months, keep yourself cool with these smart ceiling fans and remote controls for maximum comfort. Read More too? And be sure to check out these other smart home automation projects 9 DIY Smart Home Automation Projects for a Shoestring Budget DIY smart home devices can cheap with the right projects and instructions. These nine examples show you how. Read More for more ideas.

Related topics: DIY Project Tutorials, Home Automation, IFTTT, Raspberry Pi.

Affiliate Disclosure: By buying the products we recommend, you help keep the site alive. Read more.

Whatsapp Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Arthur
    July 20, 2019 at 7:00 pm

    I run python to test, get this response:

    File "", line 24
    return 'No door number specified'
    IndentationError: expected an indented block

    I cut and pasted directly

  2. Bryan
    June 2, 2019 at 9:43 pm

    My comment didn't show up and I need help

  3. Jesus
    March 31, 2019 at 12:28 am

    when I execute "python" then shows

    File "", line 24
    return 'No door number specified'
    IndentationError: expected an indented block

    What can I do?

    • Hugh
      April 28, 2019 at 2:55 pm

      Same - did you get a workaround Jesus?

      • Vincent
        May 1, 2019 at 7:51 pm

        Please i've got the same issue.
        Thank you

    • Peter
      May 11, 2019 at 5:47 pm

      I had the same issue. From my research, I think it's just caused by running an older version of python. I could be wrong, I'm no pro, but I did manage to fix it.

      After if and elif lines, you need to indent. A single place will do.

      • Matt
        May 20, 2019 at 1:59 pm

        Champion - adding the space to indent lines after each elif and if (including the return line) fixed this issue!

  4. Bob
    February 19, 2019 at 7:38 pm

    This opens my garage door maybe 1-2 times before the browser fails to connect. The python script then shows "socket:error (errno 98) address already in use". A reboot of the pi clears it up for another few door cycles.

  5. Eugene
    January 6, 2019 at 1:36 am

    This works outside your network provided the port is open on your router. For security I'd suggest a random external port to trigger the local 8080. I've got it setup through my google assistant and IFTTT so I can say "hey google open the garage door" and it opens while i'm driving up my driveway before I've even gotten into range of my wifi network.

    I'd like to figure out where to inject a simple buzzer in the script so everytime I run the http request it first starts my function which I have defined. The buzzer is a simple piezo that I've created an off on script for. I've yet to figure out where I can put it for it to work consistently and not break the bottle script.

    • Guillermo Mora Mora
      February 20, 2019 at 7:23 pm

      I am having error on the IFTTT Error: ETIMEDOUT. Any body knows how to solve it?
      I am kind of new in IFTT.

      • Peter
        May 11, 2019 at 5:56 pm

        My first assumption is that you haven't set up your pi for outside access. You'll need to set up some port forwarding, etc. Just be aware of the security implications.

        Before I set up my IFTTT, I made sure I could access the address using my cell phone network. IFTTT has to access from outside your network, so just be aware of that.

        I hadn't set up anything with IFTTT (well, custom anyways) before this. the THIS part is the Google Assistant (or Alexa if you roll that way) and the THAT part is the webhooks part.

        Hopefully, this helps!

  6. Michael
    November 24, 2018 at 9:32 pm

    Will this work outside of your local wifi network? I'm looking to do exactly this but from a cellular/non-local wifi network.