Making a dumb electric garage door work with HomeKit

 
8.jpg
 
 

Its been a while since I updated this, but I have been playing around and troubleshooting this project for a while and its finally ready for sharing. The goal of this project is to make my dumb electric garage door work with HomeKit so that I can automate the opening and open it using my phone instead of the RF fob.

Parts Required

Raspberry pi 3A+

1.5.jpg

The reason I chose this was that it had integrated wifi and its cheap.

Gravity: Relay Module V3.1

Link to shop

2.jpg

I brought this from the Pi Hut in the UK, This was after much trial and error buying relay boards on amazon and getting 12v relays that the shop page said would work with 5v. I eventually gave up and went to the Pi Hut and got this relay that worked 1st time.

Setting up your pi

Follow the basic setup documented on the Raspberry Pi page here. However there are 2 additional steps required before you put your micro SD card in your pi.

Enable SSH

This one is nice and simple on your raspberry pi’s Micro SD in the root folder add a blank file with a name of ssh no extension just ssh . That’s it you have enabled SSH without having to connect anything to your pi.

Connect to wireless

This Will make your pi connect to wireless without having to connect a keyboard mouse and monitor. Create a file called wpa_supplicant.conf, Open this file with a text editor and add the below and replace the country code, ssid and psk with the ones required for your network.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

update_config=1

country=<Insert 2 letter ISO 3166-1 country code here>

network={

 ssid="<Name of your wireless LAN>"

 psk="<Password for your wireless LAN>"

}

Connecting to your pi

3.jpg

Insert your SD into your pi and power it up. After a while, it will connect to your wifi. You will need to retrieve the IP address of your pi from your networks DHCP controller. Once you have the IP open up your SSH terminal of choice and connect to that IP.

By default the username is raspberry and the password is pi.

Installing software

Now that you have connected run the below commands to get the software required installed and software and packages updated.

sudo apt-get update

sudo apt-get upgrade

sudo rpi-update

sudo apt-get install python-flask

Now we are ready to configure your pi to respond to an API request.

Configuring API

Now its time to get your pi to translate an API request into a GPIO output.

In your SSH client type the below commands to create the python file that will be our API

cd ~

mkdir /door

nano door.py

Now in the nano interface add the below code

#!/usr/bin/python

from flask import Flask

from flask import request

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BOARD)

GPIO.setup(8, GPIO.OUT)

app = Flask(__name__)

@app.route('/', methods=["GET"])

def api_root():

return "not in use"

  @app.route('/door/push', methods=["POST"])

def Api_Door_Control():

if request.method == "POST":

GPIO.output(8, 1)

time.sleep(.5)

GPIO.output(8, 0)

return "Pushed"

if __name__ == "__main__":

    app.run(host='0.0.0.0', port='80')

This code will wait for a post request to <IpOfPi>/door/push, It will then raise the voltage of pin 8 on the GPIO for ½ a second and then return it to normal and return pushed to the requestor. This will have the same effect of pushing the push to make button on my garage door and should be the same for most dumb garage door’s.

Next thing we need to do is create a service for this code so that it runs automatically at startup. Enter the below commands into your SSH client.

cd /lib/systemd/system/

sudo nano door.service

In the nano window paste the following.

[Unit]

Description=Door Service

After=multi-user.target

 [Service]

Type=simple

ExecStart=/usr/bin/python /door/door.py

Restart=on-abort

 [Install]

WantedBy=multi-user.target

The last thing we need to do is configure the permissions on the files this is done by entering the below commands

sudo chmod 644 /lib/systemd/system/door.service

chmod +x /door/door.py

systemctl daemon-reload

systemctl enable door.service

systemctl start door.service

Wiring up your Pi

8.jpg

There is a wiring diagram for the pi 3 A+ available here. You will need to run 3 wires from this, Pin 4 5v (for powering the relay), Pin 6 (Ground for relay) and Pin 8 (signal for relay).

You can see from the pic I have used Cat5e cable a joining box and some jumper cables to connect to my pi.

9.jpg

This second pic shows how I mounted the relay. I have spare space in the switch box so I hot glued the relay to the back of the box and have the relay connected in series with the push button so that either switch closing completes the circuit. I have joined the Cat5e cable to the control and power cables for the relay using jellies.

Configuring HomeBridge

6.PNG

I have already gone over the creation of a HomeBridge server here. You will need to add the package homebridge-http-switch to your HomeBridge setup. Then add the below to your config under accessories.

       {

            "accessory": "HTTP-SWITCH",

            "name": "Garage Door",

            "switchType": "stateless",

            "onUrl": {

                "url": "http://<ipofpi>/door/push",

                "method": "POST"

            }

        }

Save and reload your configuration, and you will have the ability to have the button pushed by asking Siri to “turn on garage door” or just pushing the button in the Home app.

I will be adding a state sense to this later however the part I want for this a digital hall effect sensor is not currently available