julienfouilhe / automate-gate-opening

Automate gate/garage door opening via 433.92MHz emitter with Raspberry Pi, Home Assistant and Homekit.
59 stars 4 forks source link
433mhz domotic homeassistant homekit ook raspberry-pi

Automate opening your garage door / gate

Summary

This project sums up how I automated opening my garage door using a Raspberry PI, a 433Mhz emitter, Home Assistant, and Homekit.

Introduction

I have a car and I use Apple Carplay. I wanted to automate my garage door so that I could have the "Garage door" button on the screen in my car. 😍

Carplay with garage door open button

Obviously I couldn't mess with the garage electronics or change the hardware, I'm just a tenant, but the door could already be opened remotely, so I figured I could just copy the signal it was sending, and send it back.

⚠️ If you are the owner of the garage door or you're allowed to mess with it, there are cheap and easy to install modules such as the Meross Smart Wi-Fi Garage Opener

Note that my garage door uses a very simple system, and that my process may not work for your garage.

It took me some time to understand how to do just that, but hopefully this document will help people trying to achieve the same thing.

Here's a graph of my setup, you can have something simpler, but I already had a home server (NUC) so I setup some things on that instead of on the Raspberry Pi.
My setup requires the Raspberry Pi to be connected to your local network (not necessarily to the internet though).
You can use an Arduino but you'll need to adapt the Python script that sends the signal.

Graph

⚠️ I don't know how legal/illegal this is. I think it's ok if you're doing this for your own garage though but this is not legal advice. 😅

Requirements

You'll need:

Procedure

Step 1: Sniff the signal

My garage opens then closes automatically. If you have another button to close it you will need to do this step twice.

Detected OOK package  2021-10-24 05:01:08
Analyzing pulses...
Total count:   13,  width: 13.85 ms    ( 3463 S)
Pulse width distribution:
 [ 0] count:    8,  width:  368 us [360;424]  (  92 S)
 [ 1] count:    5,  width:  740 us [740;748]  ( 185 S)
Gap width distribution:
 [ 0] count:    5,  width:  372 us [368;380]  (  93 S)
 [ 1] count:    7,  width:  756 us [756;764]  ( 189 S)
Pulse period distribution:
 [ 0] count:    3,  width:  756 us [740;792]  ( 189 S)
 [ 1] count:    3,  width: 1500 us [1496;1504]  ( 375 S)
 [ 2] count:    6,  width: 1116 us [1116;1124]  ( 279 S)
Pulse timing distribution:
 [ 0] count:   13,  width:  372 us [360;424]  (  93 S)
 [ 1] count:   12,  width:  748 us [740;764]  ( 187 S)
 [ 2] count:    1,  width: 10004 us [10004;10004]  (2501 S)
Level estimates [high, low]:  15599,    544
RSSI: -0.2 dB SNR: 14.6 dB Noise: -14.8 dB
Frequency offsets [F1, F2]:  -28455,      0  (-108.6 kHz, +0.0 kHz)
Guessing modulation: Manchester coding
view at https://triq.org/pdv/#AAB103017402EC27148091818091818090909181818255
Attempting demodulation... short_width: 368, long_width: 0, reset_limit: 768, sync_width: 0
Use a flex decoder with -X 'n=name,m=OOK_MC_ZEROBIT,s=368,l=0,r=768'
pulse_demod_manchester_zerobit(): Analyzer Device
bitbuffer:: Number of rows: 1
[00] {16} 22 38     : 00100010 00111000

Graph with values

Step 2: Send the values

The script as is does not send the code when it's run. It waits for messages ordering it to open the garage door. At this point you can try to run the script and it should open your garage if you add this before the start_loop:

  for _ in range(0, 40):
    sendCode()

The signal needs to be repeated a certain amount of times because your gate's receiver can be a little deaf sometimes. 40 is an arbitrary number that works without fail for me.

If your gate doesn't open at this point... I'm sorry but it worked on the first try for me 😎 Just kidding I didn't have this guide so it took me a whole night to figure it out. You can try sniffing the code signal your Raspberry pi sends using your RTL-SDR and compare it to your remote's. I even exported the signal to Audacity to be able to see if the waves matched... If your RTL-SDR doesn't catch any signal, then that can mean several things: either the emitter is not correctly plugged in the Raspberry Pi, you didn't use the right GPIO (the script uses the pin 11 / GPIO 17 by default), or the emitter is broken.

Step 3: Installing home assistant

Home assistant dashboard

At this point you should see the Garage door device appear on the Home app.

Home app screenshot

Step 4: Connect the Raspberry Pi script to Home assistant

It's time to make sure your Pi can receive OPEN orders from Homeassistant.

🎉 You should be able to open your garage using the Home app!

Step 5: Keep everything running all the time

That's great everything works, but we need to make sure that if the devices are restarted, everything is restarted correctly.

Wait a few seconds for the Pi to restart, and try to open your garage again! It should work!