I’ve been meaning to add my garage door to HomeKit for quite some time. And not just for fun. There are some good reasons why this would improve my quality of life:
- My wife has already lost two garage door remotes. Her iPhone, however, fortunately never gets lost.
- If you’re like me you’ll never remember if you actually pressed the button to close the garage on the way out. And this doubt will only pop up when you’re already at the end of the street.
- Since I’m frequently using my bike nowadays, it’s one less remote I have in my pocket.
I finally completed this project yesterday!
Behind the scenes
Making this happen isn’t terribly difficult but there are a few hoops to go through.
Controlling the garage door
First I needed a way to remotely control the garage door. Most garage doors come prepared to be controlled with a push button, mine was no exception.
To simulate the push button I’m using an old Raspberry Pi and a simple relay switch. I also bought a reed switch to know when the garage door is closed. Using the wiringpi gpio
command you can test all this stuff rather quickly.
Remotely accessing the Raspberry Pi
Next I needed some way for my Pi to connect to the internet. Fortunately my garage is connected to my apartment’s electrical circuit, so I simply added a power line adapter to connect my garage to the internet. Added bonus I can now check my e-mail inside the garage where GSM reception was poor.
Supporting HomeKit
To add HomeKit support I’m using Homebridge with this garage door plugin. Homebridge runs fine on the Pi and even has specific instruction for it.
The plugin simply runs commands to open, close and get the status of the garage door and parses the output. You could write these commands in Bash or Python but I wanted to try doing this with Swift.
Adding Swift to the mix
You can’t sudo apt install swift
on the Raspberry Pi yet, but installing is almost just as easy thanks to the buildSwiftOnARM project. Just download and unzip.
To be able to control the GPIO pins on the Pi you’ll need SwiftyGPIO.
You can check my project that puts all this together.