January 17, 2023
gome-assistant lets you write home assistant automations in Go. If you just want to see how it works, skip the article and check it out on github. Below is a short recap of why I wrote it.
tl;dr I wanted to learn go and wanted strongly typed automations.
My automation journey
I put a lot of thought into my smart home. My automations are complex so the UX can be simple. It’s taken me 3 years to get to this point, and with my new library it’s easier than ever to quickly write and iterate on a new automation.
When I started using Home Assistant in 2019, the built-in automations were pretty rough so I decided to use Node-RED.
Note: Home Assistant's built-in automations have changed signfiicantly since that time. I haven't used them, but people say they're much better now.
Node-RED was great at first, and for simple automations I had no complaints. As my automations grew more complex, I found that I was spending an hour or two just to figure out which nodes I should be using. Reusing logic was a pain compared to writing a simple function.
Then I found the function node! It was an upgrade, and I used it for all my new automations. But then I stumbled on Appdaemon. It let me set up some python classes and write my automations entirely in code.
Appdaemon renewed my excitement for creating useful automations. I was dreaming up new ideas, filtering ones that added more burden than value, and adding them to my home as fast as I could type. Writing complex logic in code was much faster since I already knew how to code.
However, there were a couple pain points with Appdaemon that wore on me over time. Since python is an interpreted language, all the source files had to be on my home server. So I had to decide between copying the files over — a pain when iterating on an automation — or remotely writing the automations, either via vim in a terminal or by running a code-server instance. I went with the latter, so I could write the automations from a tab inside Home Assistant itself. This worked okay, but I never invested time in getting VS Code properly set up since I only used it when making changes to my automations, which wasn’t very often.
Unfortunately, the lack of editor set up and python’s dynamic typing led to poor autocompletion. Combine that with infrequent edits and I was pulling up the Appdaemon docs any time I wrote an automation to remember exactly what arguments a function took. All of that friction led to me not tweaking things very often, even when I thought of a way to improve an automation.
I recently got an itch to learn Go. I learn best by doing, so I figured I’d wait until I had an idea of something to build, and I’d build it in Go. That idea eventually came to me in the form of gome-assistant!
Go, and therefore gome-assistant, lets me write my automations on my Macbook using my usual VS code setup, then cross compile the binary for linux and
scp it over to my home-server. Quick iterations are easy, autocomplete is perfect thanks to Go’s strong typing, and I can structure my code however I want to because gome-assistant is just a library.
If you’re a Home Assistant user who’s familiar with Go, check it out and see what you think!