Home Assistant and my Garage Door
In my ongoing quest to spend more time implementing automation solutions than it would normally take me just to get up and flip a switch I inevitably found myself really wanting to implement some automation around opening my garage door.
While looking for options I really only had these hard requirements:
- Absolutely no cloud access at all
- Could also detect if the door was open and closed
- Still work normally even if my home assistant setup was not working, which given my 80% uptime stats, is often
- Prove to my wife once and for all that this was, in fact, totally worth it
Thankfully I decided that going the pre built route was going to be far too easy and I should instead opt for cobbling together my own disaster.
This isn't really going to be a tutorial so I think what I'll do is just go over how I did it.
The workhorse of this whole thing is a Raspberry Pi 4 which I setup with a really simple controllable relay.
I then proceeded to install this Pi in the absolute most horrific way ever seen.
I assure you this is an industry standard installation. Even the thumbtacks and spider webs.
Since I also wanted to be able to tell if the door was open or closed I dug around for a few options and ultimately decided on using a very simple reed sensor also wired into the poor abused Raspberry Pi.
I'm actually quite proud of this part!
I actually spent time designing and 3d printing the orange brackets holding the PVC along the chain channel then ran the reed sensor wires down the PVC.
For the door I attached it to the adjustment bolt on the chain holder that actually moves the door up and down.
You can find my models here on my Printables account.
Finally wiring this whole thing is some Golang code I wrote using gpiod to provide access to the GPIO inputs and outputs.
The code is very simple and you can check it out on my codeberg repo called gogarage.
All it really does is:
- Provide an endpoint to trigger the relay for opening and closing the garage door
- Provide an endpoint for querying the state of the reed sensor (open/closed)
I wrote the code in an hour or so, pushed it to the repo and haven't touched it since. Probably the most rock solid code I've ever written.
Tying it all Together
Pulling this whole hack together I am utilizing three components in Home Assistant:
- A custom input_button helper for physically triggering the garage door to open and close on the gogarage service
- A custom sensor for reading the reed sensor state from my gogarage service
- Node-RED for actually wiring the input_button to calling the API and integrating it into my automations.
The Node-RED flow looks like this:
I actually recently added the section of the code checking if the garage door is open or not and notifying me if it isn't because I once left a server on a table right under the garage door that I had been cleaning out and promptly forgotten about only to wake up with it full of rain water. WHOOPS!
Overall this was a fun project and of all the custom hacky crap I've done this is one of the few that 80% of the time works every time. Even that poor, poor, POOR bastard of a Raspberry Pi.
Seriously, that Raspberry Pi has endured living in my hot as hell muggy dust ass garage for over two years without a single complaint. That's a testament to these little things.