Projects / Home Automation

Coffee

Baratza Encore Coffee Grinder
The thing that started it all

My wife drinks coffee, but I do not. I get up before her and deliver a cup of coffee in the morning.

I hate grinding the beans. It’s very loud. One day I wondered if there was a way to grind the beans while I’m still in the bedroom, where it could be reduced to a dull noise.

I discovered I could leave the grinder switched on and use a smart plug to control the power. Apple’s HomeKit allows this, but only toggles switches in intervals of one minute. Running our grinder for a minute produces almost twice as much coffee grounds as we need.

That journey of home automation ended with me deep in the world of Home Assistant.

Home Assistant

The first step was to install Home Assistant and get it to control that smart plug. Easy enough to put it on a virtual machine. I paired the plug and wrote a script that would turn it on, wait 35 seconds, then turn it off.

This worked, but how to schedule it?

Home Assistant has a nice website, native app, and can integrate into every ecosystem that exists. People customize in-wall tablets to display their bespoke user interfaces. While I was sorely tempted to do that myself, I value being able to easily share these features with my family and interact with them through Siri.

Home Assistant dashboard
I haven't customized the Home Assistant dashboard since everything runs through HomeKit

Bridges

Home Assistant allows you to export its device control functionality to other ecosystems via bridges. Scan a QR code and HomeKit will think it’s talking to switches, lamps, fans, locks, or whatever else. In reality Home Assistant lets you share an item as anything.

I exported the Grind coffee script to HomeKit as a power switch. When I turn it on via the Apple Home app, it runs the script to turn on power, wait 35 seconds, turn off power. But there is a natural jankiness. The Home Assistant script doesn’t have the on/off state a true switch would have, so in the Home app it switches itself off after about five seconds. This works fine for my scenario.

I used the Automation feature of the Home app to grind coffee at 7:30 AM every morning. Then I wondered… what else could I do?

Multiple switches

While the smart plug that runs the coffee grinder remains exclusive to Home Assistant, I added more plugs and paired them directly to Apple HomeKit. This severely restricted my choice of plugs, but I found Meross indoor and outdoor plugs to work well.

That let me automate turning off devices in the nursery after the kids wake up. I could schedule the holiday lights to activate at sunset. While I would have had more flexibility in Home Assistant (e.g. turning on lights just before or after sunset), I ran all automation through HomeKit.

Nursery power strip in the Home app, showing all 5 plugs
The numerical naming scheme lets me tell which of the unlabeled sockets on the strip are which

Laundry timers

With simple on/off functionality working, I wondered if I could use it for more complicated things. Could I get a notification when the washing machine was done?

  • Vibration sensors on the appliances? Too expensive and too finicky.
  • Noise sensors in the laundry room? Not with my rowdy children running about.
  • Monitoring the power draw through a smart plug? This worked, but wasn’t as reliable as I liked.

In the end I went with a timer, but it wasn’t simple. I wanted a notification on my iPhone from the Home app.

This meant setting up an Input Boolean in Home Assistant, exporting that to HomeKit as a contact sensor, then making Washer and Dryer scripts that started a timer to toggle their respective input booleans after about an hour. The changing of the contact sensor in HomeKit would trigger a notification, though it wouldn’t be the same one every time. It would switch between e.g. “Laundry sensor open” and “Laundry sensor closed” depending on the state of the boolean.

Still, that was fine. I got a notification on my wrist roundabout when the washer was done, assuming I hit the Washer switch on my phone when I started the appliance.

A Home Assistant script that starts the washing machine timer for 70 minutes
This script is exposed as a switch to HomeKit
A Home Assistant automation that flips an input boolean when the washing machine timer finished
With clever use of input booleans, you can get notifications from Home Assistant into HomeKit

Garage door

Technological wizard I may be, but it took me several years to figure out the reason why our garage door remote rarely worked. It was because we had vacation lock on. Whoops! Once I figured that out, I wondered if I could control it remotely.

Meross to the rescue again. This one was a bit more involved, requiring actual wiring and careful placement of contact sensors on the frame and panel. But it connected to our Wi-Fi fine and hooked directly into HomeKit.

Infrared blasters

This house has mini splits in every room. They’re controlled by an infrared remote. I was surprised to discover that the remote is what stores the state of the mini split. When you press the temperature up button, the remote sends the entire state it expects to the mini split (e.g. heat on, 72 degrees).

Home Assistant supports learning and repeating these commands, so I bought a flight of Broadlink RM4s and went to work. I taught the system how to turn on for heat at a specific temperature, how to turn off, and how to disable the LED. Those are individual commands for each mini split.

I couldn’t use scripts and switches to integrate that with HomeKit. The mini splits would default back to off. Instead, I exported input booleans representing each mini split’s state. Then I wrote automation in Home Assistant to wait for changes to the mini split’s input boolean and run the appropriate script when it turns on or off. To handle the transition from heating to cooling, I made another input boolean that toggles a house-wise “heat mode” input boolean. The mini split’s on scripts check that variable to know whether to send heat on or cold on commands.

Home Assistant automation for the mini splits
Mini splits are input booleans whose changes are watched by automations that do the actual on/off

Window shades

In 2022 we replaced some of our nearly broken window shades with Graber’s automatic shades. These have one sophisticated remote and several mini remotes that use the Z-Wave protocol. While the mini splits would continue to respond to its own remotes after I programmed my IR blasters, the Z-Wave shades are paired to a single controller device.

I bought a Zooz 700 Series Z-Wave USB adapter for the 2014 Mac mini that I used for Home Assistant. Pairing it to Home Assistant was similar to pairing Bluetooth headphones, except for me standing on the windowsill as the shades bobbed up and down to signal they were listening. Having done so, I could control the shades from Home Assistant, but the Graber remote was useless.

Note to self: set that back up again when you sell the house.

Happily, Home Assistant exports window shades natively to HomeKit. They show up as shades and can be adjusted to any height from the Home app. One quirk I noticed is that HomeKit sends the “go to this height” command very frequently as you slide your finger up and down. That would cause the shades to hesistate and sutter as they constantly receive new commands. It’s not an issue when the shades are automated and receive just one command at a time.

Door lock

When all you have is a hammer, every problem begins to look like a nail. One day my toolbox was stolen out of the garage. Hammerless, I bought a Wyze lock for the door and a Zigbee dongle to use the hammer of Home Assistant to protect my replacement hammer.

Like Z-Wave, Zigbee devices must be paired to a controller, in this case a white circle you plug into an electrical socket. I installed the door lock and used the app to pair it to the circle. While it’s paired to the app, don’t forget to change the lock’s settings so it doesn’t try and lock itself whenever the door closes. Then you can turn on discovery mode on the lock and pair it to Home Assistant.

The lock exports to HomeKit with only a few complications. It must be exported on an individual bridge, and when it’s told to open it stays in a state of “Opening…” that never resolves.

Home app for Mac, showing the Living Room, Garage, and Nursery devices
Part of my sprawling automated house

More fun

Nonsense and useful things I get up to with home automation:

  • My wife has a “party lamp” she likes. I created an automation to have it turn off when she leaves the house and turn on when she returns. That way it always appears on to her. And I get a bit of a warning when she’s nearly home.
  • Downstairs lights in our house are controlled by smart plugs. An automation turns them off at midnight, so we never have to worry about doing it ourselves when we go to bed.
  • On Saturdays my wife sleeps in while I get the kids up in the morning. I prepare the coffee and then press a shortcut on my phone that turns off the plug that controls the brewer. Then I switch on the brewer, but nothing happens. My wife has a matching shortcut on her phone that turns on the brewer’s plug. That way she can control the timing of the brewing from bed without us having to buy a specific automation-enabled coffee machine.
  • We have a HomePod play ocean sounds at bedtime. Originally this was a playlist through Apple Music. Then it started failing for some reason. I flailed around for a bit, finally discovering that the correct workaround to buy the album on Apple Music, use ffmpeg to merge them into one MP3, then store it on Apple Music and play that one track on loop.
  • When we go on vacation I disable all our normal automations and enable a couple vacation automations to make the house look lived in. Not quite Kevin McAllister’s house, but it’s something.