Another tutorial for building a garage door opener with a raspberry pi. I've left the garage door opened too many times. Source: https://github.com/skittleson/garage-pi This tutorial assumes you have a raspberry pi with wifi and the ability to ssh in.

Goals

  • Use Docker so it can easily be shared/restored/etc!
  • A simple web API for control
    • Use nodejs as much as possible for the build.
  • Toggle garage door
  • Status of garage door
  • Toggle light switch on the garage door
  • (optional) cheap camera to see what's going on.

What you will need

Research & Discover

There are a ton of these garage door projects. I was inspired by many of them. The LiftMaster garage door system has anti-tamper hardware measures which almost ended the project before it started. I decided to take a gamble and buy another garage door opener circuit that directly connects to the garage door unit. Bingo! Two circuits can be connected at the same time. Docker permissions and finding a base image for the raspberry pi took a few hours. Lesson learned, hardware interaction with docker can take a few extra steps.

Wiring

The relay module is stacked on top of the LiftMaster module then taped onto the Raspberry Pi. Note the relay connections are wired for normally opened. (click image to see larger version) Sealed up in a glad container (kinda hacky but it's cheap). This is the LiftMaster circuit. The narrower end has the button for opening the garage. The larger end has the button for the garage door light. The middle points are for the circuit to connect to main garage door unit. GPIO pin layout for the relays & reed switch not including power leads. Reed switch is connected to the part of the garage door (pin 18 and a ground). Once it moves away, then the reed switch is disconnected.

The entire setup. Messy but it's good enough. Cut some holes with a knife for wires and to hold it in place. The camera has been added with duck tape. Using a standard install of motion (no dockerfile tho).

Install

Install docker on the raspberry pi. https://www.raspberrypi.org/blog/docker-comes-to-raspberry-pi/

curl -sSL https://get.docker.com | sh

Clone the repo

git clone https://github.com/skittleson/garage-pi
cd garage-pi/

Run docker build for the image

docker build -t garage-pi .

Start the docker image in privileged mode. This will expose port 8090 for web access.

docker run -d --privileged -p 8090:8090 --name gpi garage-pi

Test it

curl http://localhost:8090/api

Other api commands

  • Status: /api/garage/status
  • Garage Door Toggle: /api/garage/toggle
  • Light Toggle: /api/light/toggle
  • Exit: /api/exit

That's it!

Code

Simulating the button press for the garage door opener circuit. Relay turns on for 500ms, then off. An interesting issue with the relay. As soon the gpio utility exports, it triggers it on. This code exports then unexports a pin that the relay is on.

let relayButtonPressAction = (pin) => {
    gpioExport(pin, 'out');
    gpioWrite(pin, 1);
    setTimeout(() => {
        gpioWrite(pin, 0);
        gpioUnexport(pin);
    }, 500);
}

There is one python file that checks the status of the garage door. The configuration was different enough where it needed to be done there. The reed switch should always be true until the door has been opened.

import sys
import RPi.GPIO as gpio

pin = int(sys.argv[1])

gpio.setmode(gpio.BCM)
gpio.setup(pin, gpio.IN, pull_up_down=gpio.PUD_UP)

status = gpio.input(pin)
sys.stdout.write(str(status))

gpio.cleanup()

Open for pull requests! I'm considering on moving all the gpio logic to python then using nodejs as the api router.

Summary

Hardware side is built and working. The api has enough information to check and toggle the garage door. Going to create a script to watch the door status with Node-red due to ease of configuration. This project took about 2 days with testing and debugging. Here is a screenshot of the node-red template. Still a work in progress! The flow file is in the repo code.