contact us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right.​

Auto Office through HomeKit

Projects

Various electronics, programming, welding, mods and other non-automotive projects.

Auto Office through HomeKit

Joe Angell

I’m too lazy to turn on a bunch of monitors and lights, so I set up an automation to do it, which I call Auto-Office. My original implementation used SmartThings and some custom software, but more recently I’ve migrated it to HomeKit and some custom software.

System Components

My setup requires a few interlocking components to work:

  • A custom daemon running on my Macs to both control their wake/sleep state and report that state to HomeKit.

  • A much more crude custom daemon running on my Windows machine to control its wake/sleep state and report that state to HomeKit.

  • An update to my AutoOfficeIR project to report status changes. This module turns on the two large TVs I use as monitors for the Mac mini and Windows machine. The other monitors wake and sleep directly via DPMS, which TVs don’t support.

  • Homebridge with homebridge-httpwebhoooks running. This is the glue between my daemons and HomeKit.

  • A couple of HomeKit compatible light switches, in this case Leviton Smart Dimmers.

All of the computers and AutoOfficeIR have static IPs assigned at the router, which greatly simplifies the Homebridge setup.

The button from the old setup is still in my desk, but my new office layout means that I haven’t bothered to hook it up since I moved, but I always have the option of reenabling it if I need to. I also don’t use a motion sensor anymore, since it was too easy to accidentally trigger that when I didn’t meant to and was just walking around the room.

macOS Daemon

The macOS daemon is the most interesting one, and the most polished. I used SwiftUI to put together a simple interface, and set it up to live in my menu bar. The UI lets you set up the accessory ID for homebridge-httpwebhooks, as well as if it should wait after sleep before reporting its state, and if it should respond to wake or sleep events. The Homebridge server IP and port are also set here, as is the listening port for incoming wake/sleep control requests.

I have this running on three machines: my Mac mini, my iMac, and my work MacBook Pro. It is set to run as a Login Item on each machine.

The source for the daemon can be found on GitHub.

 

The simple AutoOfficeDaemon UI,a s configured for my iMac.

 

Windows Daemon

The Windows daemon is a bit hacky. I’m using the same one I used for SmartThings. It only responds to wake/sleep events and doesn’t report them. I won’t go over it in detail here, since I covered it in my other post about Auto Office.

This command line utility runs on startup on my one Windows machine.

AutoOfficeIR

This ESP32-based project only required a minor change to report state changes to Homebridge. It only took a few minutes, since I mostly copied the code from my heating registers. It took me longer to realize I needed to update the Silicon Labs driver for Big Sur and flash the new program to the ESP32.

Homebridge and homebridge-httpwebhooks

I previously covered setting up Homebridge and homebridge-httpwebhooks for my smart heating registers, so I won’t go over that again here. I created a new instance of Homebridge for this, and added all of the devices to its config. The devices still use the wake and sleep URLs from the old SmartThings-based setup, but homebridge-httpwebhooks lets you enter any on/off URL you like, so that was fine. The devices are configured as switches, and show as on or off in HomeKit.

HomeKit Automations

The last piece of the puzzle is actually automating things. This was pretty trivial once everyone was talking to HomeKit.

  • When the iMac goes to sleep, all other devices go to sleep.

  • When the iMac wakes up, all other devices wake up and the lights turn on.

  • When the lights are turned on, all devices wake up.

  • When the lights are turned off, all devices sleep.

Here, the iMac is considered my “master” machine, and when it wakes or sleeps, so do the other devices. The iMac will also cause the lights to go on, but it will not turn them off itself. This avoids the lights going off on me if I’m in the room but not near the computer. If I turn the lights on or off directly, the devices all wake or sleep as well.

And that’s it. Everything works quite well so far, and is generally snappy and reliable to boot.