Opinions are mine

Useless Idea

Back in 2014, I moved from Ukraine to the US and made a few friends at my new job. I spent days on the campus of National Institutes of Health and lived nearby in the town of Bethesda - about 10 minutes walking distance from my cubicle. There were many people like myself, and we were pointing at our apartments from the office windows while chatting over coffee.

One of my colleagues did exactly that and said “voilà” - the lights in his apartment window turned on. “Isn’t that cool?” - asked he. And indeed, I was impressed. He showed me the Phillips Hue app on his smartphone and explained how it connects to cloud services, which are in touch with a hub in his apartment. This way, he can blink his lights in any color regardless of where he is.

View from the NIH campus towards Bethesda

I felt like I had transferred into the distant future. To that day, the only use of “smart home” I saw was just in advertising prospects to raise the price of the apartments in luxury buildings. Funny enough, even in that case, it usually meant something like a video doorbell. But the next very moment, my dreams crashed hard. I asked how much it costs and heard a number that was something like my monthly grocery budget at the time.

“It is cool, but with such a price tag, it’s an impractical and expensive toy for rich people,” thought I, and scratched the idea of a smart home off my mind.

First Try

According to my Amazon order history, I purchased a Phillips Hue starter kit about two years later. I don’t recall how I got back to thinking about it again, but I can only guess it was a passing inspiration. At the time, I had just returned from a trip to California, where I visited numerous museums and hipster restaurants and probably was looking to fancy up my daily life.

We were living in a tiny studio apartment, and I struggle to remember where I put those bulbs. The apartment didn’t have ceiling lights, so it had to be a floor lamp or two, but I definitely didn’t have enough bulbs to fill all our lamps. I’m sure I enjoyed syncing lights with musing, but that probably was about it.

Fast forward a few months, we moved to a bigger loft-style apartment, and I splurged on more Hue bulbs so that all of the lights would be “smart.” That definitely worked impressively for creating a special mood, and I remember thinking that it was totally worth it for such an experience (ha-ha, I guess my grocery budget went up).

Syncing lights to music looks especially impressive in a loft setting

Since our apartment now had a hallway, and the bathroom wasn’t like the minimum amount of space required to fit a toilet and a tub, I bought a few Hue motion sensors and set up automations for lights. It wouldn’t have worked at the previous one, as it was too tiny, and they’d just trigger all the time.

That probably was my first endeavor into home automation of any kind. Even though it was as trivial as just clicking several buttons in the Hue app. Kudos to Phillips for making it that simple!

Welcome HomeKit

Our new loft-style studio apartment got large walls painted white, so we bought a projector for movie nights. Being loyal Apple buyers, an Apple TV for streaming to the projector via AirPlay was a no-brainer. Who wants to bother with cables these days, huh?

Among other things, Apple TV serves as an Apple HomeKit hub. That is, it can control compatible devices in your home, even when you’re not around. So you can always turn off lights you forgot about, check the temperature, etc. I immediately connected my Hue hub to the Apple TV and now could use the integrated controls that HomeKit provides to tweak my beloved colored bulbs. Hue motion sensors also showed up there, along with their temperature readings.

HomeKit interface for creating automations

I also migrated all my automations from Hue to HomeKit. Unfortunately, both provided only a visual interface for configuring automations, so it wasn’t the best user experience either way. Imagine dozens of if-then-else rules you have to enter via a graphic interface. That being said, HomeKit offered more flexibility and allowed me to make my light automations much more advanced compared to what they were before. Also, the promise of having a single place to control automations for other devices besides lights - once I have them - was quite compelling.

Let me stop here for a moment - I want to highlight one thing, to which I will come back later. Light automations are amazing, even though it sounds as trivial as “meh, just some light turning on and off.” Not that you cannot flip the switch whenever you need the light, but it’s an entirely different thing when you tweak automations to match your habits and routines. Gradually lighting up the bedroom after sunrise so that you always wake up to a bright morning. Or never touching a switch in the bathroom or hallway - even when you briefly walk in to just quickly grab something. Or making the kitchen counter light up whenever you approach it to fix a snack. Or have the lights turn on as the sun sets so that you can continue reading a book without squinting your eyes to see characters in low light. It takes some effort to get it right, but when you get it right, it becomes a passive feature - something you don’t need to even think about, and it just works. And gosh, that’s easy to get hooked up to.

Typical HomeKit dashboard

Now, back to HomeKit. Luckily for me, soon after my base setup was in shape, Apple released HomePod, and I quickly snagged one. I needed a proper sound output for the projector - and did I mention I don’t like wires? Now, I could’ve used tons of alternatives, but HomePod also allowed me to stream music easily from my iPhone, which paired exceptionally well with the light-to-music syncing I mentioned above. On top of that, I could speak to Siri from anywhere in our 1-bedroom loft apartment, and it would hear me. What does that give? I don’t even need to pull up my phone anymore to control the bulbs that are not automated, or I can just wish Siri a good night, and it will shut off all the lights. I must admit, I felt extremely awkward talking to Siri for something like the first six months, but now I don’t even think about it. I feel like my wife used to roll her eyes each time I’d ask Siri to do something, and it won’t get what I’m saying, but these days she often asks it for things on her own instead of reaching for her phone.

One of the features of HomeKit that I liked a lot was that it was designed with offline operation in mind - contrary to Alexa or Google Home. Yes, I cannot use voice commands if the internet connection is down, but as long as I’m on the same network as the HomeKit hub, I can still control all of the devices without an issue.

Adding HomeBrdige

One thing I’m not fond of is remotes. It’s always too many of them, and they always get lost. Apple TV comes with a remote, and the projector came with one as well. That was already too much for me. Being a software engineer by trade, I set on a quest to solve this problem and quickly came across Homebridge.

Homebridge as seen in HomeKit

At the time, there were not that many devices on the market compatible with HomeKit. At some point, Apple even required compatible devices to ship with a special chip for authentication. While I understand their good intentions, it also was severely restricting choice for customers like myself. Homeridge was solving that issue - as long as you were comfortable with the disclaimer of using an uncertified integration - it allowed you to connect any device with HomeKit. You just need to set up a Homebridge instance on your local network and write some JavaScript to integrate your device (unless somebody already did so and shared their work).

I used Apple TV remote a lot, but I only used the projector remote to turn it on and off, and maybe control brightness sometimes. Most of the remotes are just infra-red (IR) blasters, so you can record the signal they emit when you press a button and then repeat it with a software-controlled IR bluster.

I found BroadLink RM Mini3, and a plugin for Homebridge that could control it - homebridge-broadlink-rm-pro. Both of those combined together, it was just an evening of cursing at JavaScript to send the correct sequence of commands to navigate a complex menu for brightness control, and I could say “Hey Siri, turn on/off the projector,” or “Hey Siri, set the projector to minimum/medium/maximum,” or just pull my phone, and drag the slider. Hooray, I’m back to just one remote. Still not ideal, but better than two.

Homebridge dashboard

Renting an apartment means some restrictions on what you cannot do. For instance, you cannot change the lock most of the time. And there are some locks that auto-lock, which means that you can get locked out if the door closes while you’re outside without a key. We’ve been in that situation several times, and besides the sheer inconvenience, it usually means an expense - a fine from super during a night-time lockout, or paying locksmith services. Once, I was cooking breakfast and had to step out to accept mail, and the door closed behind my back while the gas stove was on. Luckily my wife happened to be inside - although I thought she was not home and was about to panic.

I decided to solve that problem with a smart lock so that we could always unlock the door from outside. The only one that worked for us was Candy House Sesame. It doesn’t require replacing the deadbolt or the mechanism but instead attaches on top of the knob. There was a plugin for Homebridge as well, but the only programmatic way to control a Sesame is via cloud API, which requires an internet connection. That contradicts my focus on offline-first smart home, but I couldn’t find any alternatives.

We also got a Dyson purifier, and there was a Homebridge plugin for it too. Dyson actually did an excellent job on auto mode, but whenever I’d need to tweak what it’s doing, I could just speak up, rather than look for remotes or apps to control it.

Migrating to HomeAssitant

Over the next two years, as I was looking to automate more complex scenarios, I got VOCOlinc VS1 contact sensors, VOCOlinc VP5X smart plugs, IKEA TRÅDFRI smart blinds, and eufy security cameras. All of them were HomeKit compatible, but whenever I had anything that wasn’t - I’d write a plugin for Homebridge to close the gap, and move on. E.g., as I set up owntone-server to stream music from a turntable to HomePods via AirPlay, I needed a way to pick speakers to stream to.

There were much more products compatible with Alexa or Google Home than with HomeKit. And other ones just stated that they only work with ZigBee or Z-Wave which I had no clue about back then. At the same time, I always could find something that would fit my setup, so I didn’t bother diving deeper into those things. In a sense, I was pretty ignorant of any home automation development outside of the HomeKit-centered universe.

I’ve got one pressing issue with HomeKit though. My automations would disappear every now and then. By the time, I was using an excellent 3-rd party app HomeKit Controller that provided a much better interface for configuring automations, and even had a concept of backups, but… The backups didn’t really work for me for some reason - something was always missing, or there were duplicates for some rules, and it was still quite mundane to navigate a long list of automations and conditions and enter them all on an iPhone or an iPad.

I was thinking about writing a Terraform plugin to control my HomeKit automations when two things happened. First, I figured out that my automations were corrupted by an old iPad that I signed into at some point, and left plugged into a charger somewhere under my desk. It ran an outdated version of iOS, was extremely sluggish, and barely could do anything. Apparently, it was sometimes taking over as a HomeKit hub and screwing up all incompatible configurations. Disabling HomeKit on that old iPad was sufficient to prevent further corruptions. I would’ve probably moved on, but the second thing that happened was that I ran across HomeAssistant, which changed everything.

In fact, I experimented with HomeAssistant back in 2018, but at the time, I was focused on having HomeKit in the center of my smart-home universe, so I didn’t bother digging into HomeAssistant too much, and it appeared to me as an over-complicated alternative to Homebridge. Now, I was ready to correct my past mistake. Over two years, it developed a lot and gained many new features, as well as a much nicer user interface. Compared to Homebridge, which merely serves as, erm, a bridge, HomeAssistant is an open-source home automation hub on its own. A smart home brain, of a sort. It also happened to work with HomeKit, at least by 2020, when I gave it another chance, and in two ways: it could connect to HomeKit similar to Homebridge, which allows using otherwise incompatible devices, but it also could behave as a HomeKit hub on its own, so that HomeKit compatible devices could connect to it, and be orchestrated by it.

Why did I bother at all? Not only HomeAssitant provides a much wider eco-system of plugins, but it also allows defining automations via a YAML DSL. This meant I could now easily enter much more complex automations, and I could use Git to solve version control and backup for my automations on a fundamental level.

Custom HomeAssistant Dashboard

I immediately threw away Homebridge and registered all my HomeKit devices with HomeAssistant - Hue and IKEA hubs, all of the VOCOlinc devices, etc. I then translated all my automations to YAML in _HomeAssitant_and exposed the devices themselves back to HomeKit, so I could still use Siri for voice-based control. The only exception were VOCOlinc VS1 contact sensors which use Bluetooth, and to date, HomeAssistant does not support Bluetooth accessories for HomeKit. I kept those connected to HomeKit, and the only automation I had in HomeKit was to mirror the state of those sensors to “virtual sensors” in HomeAssistant. Rest worked flawlessly.

Now I could hack my automations in YAML as never before, track all changes in Git, keep using Siri for voice control, and full Pandora’s box of new opportunities for home automation.

I must note that I reconsidered the use of the HomeKit app over time. Yes, it’s integrated into iOS to the degree nothing can compete with it, but the level of customizations you could do with HomeAssistant dashboards is so insanely good, that I just gave up on HomeKit app. Instead, I have a shortcut to open the HomeAssistant app on iOS at my fingertip, and I can do what I need much easier and faster than what it used to take me in HomeKit. I still use Siri though - I keep all of the devices exposed from HomeAssistant to HomeKit, but I just don’t use the HomeKit app.

For what it’s worth, I started running HomeAssistant on Raspberry Pi 4 8GB RAM, and it worked good, but boot time was quite long, and the web UI was somewhat slow to load. So I moved from an SD card to an SSD, and it became perfect. Over time, as I was trying to reduce the number of devices in my closet, I tried migrating it to a virtual machine (VM) running on my Synology NAS, and it worked without a hitch. There are lots of backup options that are available for HomeAssistant, but nothing compares for me to just taking an instantaneous snapshot of a VM before or after any major update or change. If I hadn’t had a NAS or any other host to run a VM on my local network, I would’ve stayed with a Raspberry Pi 4 running off an SSD.

ZigBee

My next big discovery was… learning about home automation communication protocols - ZigBee, Z-Wave, and Thread. Since I already had lots of Hue lights and a few IKEA blinds - all of which are ZigBee - I decided to settle on ZigBee, rather than complicate things by adding more protocols. I installed Zigbee2MQTT addon and bought CC2652-based adapter. Then… I disconnected all of the ZigBee accessories I had so far and connected them to the Zigbee2MQTT coordinator. At this point, I just plugged off Hue and IKEA hubs and stuffed them somewhere deep into the box with old electronics. Once you learn about how smart home accessories communicate with each other - which I should’ve done much-much earlier - you realize that more often than not, you can get away without using their proprietary hubs, even if the manufacturer insists you need [to pay for] one.

Now, not only I have had fewer devices on my local network, I had just one ZigBee mesh at home. And the way ZigBee works is such that the more devices you have, the more reliable it is. I used to have ZigBee accessories jamming each other, and interfering with Wi-Fi, but now they were working together. And, it was much easier to steer ZigBee and Wi-Fi bands to avoid interference as some of their channels overlap.

My ZigBee Mesh

I stopped using VOCOlinc VS1 Bluetooth contact sensors and replaced them with ZigBee ones from Aqara. I also bought a bunch of ZigBee buttons like Linkind 1-Key Remote Control and Aqara Cube to replace Flic buttons based on Bluetooth I’ve been using since Homebridge times.

Now I had the same number, if not more, of accessories working together in a much more reliable and responsive matter. For instance, it used to be that Hue motion sensor would notice motion, and send a message over ZigBee to the Hue hub. Next, Homebridge or HomeAssitant would need to poll Hue hub to get a new status, and polling too often with a large number of sensors could overload the hub. Recently Hue released a new version of their API that supports push updates which could dramatically improve the experience, but even with that, it wouldn’t be better than when HomeAssistant immediately gets a message from ZigBee coordinator plugged into it. The apartment we’re renting now has a tiny bathroom, and any delays in light activation based on the motion are pretty noticeable and irritating. Before I moved my Hue accessories to Zigbee2MQTT, that was an issue, but not anymore.

I was hesitating about moving Hue bulbs to Zigbee2MQTT, as I was afraid I’d lose the ability to sync lights with music. Unfortunately, I couldn’t find an app that would work directly with HomeAssistant and do just that, but… there is an integration for HomeAssistant that emulates Hue API so that HomeAssitant looks like a Hue hub. What does it mean? You take an app that can sync lights with music for Hue lights, and you just pick HomeAssistant as the endpoint, and voilà!.

Cannot recommend it enough, in other words.

ESPHome

We moved to yet another apartment, and it got split air conditioners (ACs) controlled with IR remotes. Unfortunately, the ACs were quite old, and there was no mode we could set and forget so that it’d be comfortable in the apartment. Also, during the day, we would want AC to blow towards the ceiling so that it wouldn’t freeze an infant crawling in front of it. But during the night, that would freeze us in our bed, so we would want it to blow towards the floor.

I got a Xiaomi Mijia LYWSD02 for every room to measure temperature and humidity (these send this information every few seconds, compared to Hue sensors that send the data irregularly) so that I can use wet bulb temperature to control ACs. The idea worked fine except for one caveat - with all the walls in between, my HomeAssistant couldn’t pick up Bluetooth signal from all sensors even with an advanced antenna. The only thing I saw others suggesting is to set up additional HomeAssistant instances in every room, have them receive the Bluetooth signal, and send the data to the central one over Wi-Fi. Definitely would work, but sounded quite involving, and updating and maintaining all those extra instances sounded quite mundane.

Here comes ESPHome. It’s not another replacement for something, but rather an addition, that works really well with HomeAssistant (in fact, the people behind HomeAssistant took over ESPHome and maintain both of them now). I did some micro-controller unit (MCU) programming back in college, but I was dreading just its mention ever since then. What ESPHome does, though, it generates the firmware for an ESP8266 or an ESP32 MCU based on a simple YAML config. That is, if there is a “component” that does what you need - or integrates with the accessory you need - you would just configure required parameters (e.g., Bluetooth MAC address for Xiaomi Mijia LYWSD02), click a few buttons, and you’re done. Even better, you only need to connect the MCU to ESPHome server (HomeAssistant VM in my case) for initial flashing. After that, it can re-flash it using Over-the-Air (OTA) updates over Wi-Fi.

Log streaming in ESPHome

Did I mention it integrates with HomeAssistant well? Well, that might be an understatement. If you configure a sensor in your MCU (e.g., Xiaomi Mijia LYWSD02), once you complete the initial configuration, it just magically appears in your HomeAssistant instance. Given the tiny size of ESP8266/ESP32 MCUs, it’s a trivial thing to tuck them anywhere in the same room where my _Xiaomi Mijia LYWSD02_s are, and just have them report data back to HomeAssistant over Wi-Fi. And since they support OTA updates, they don’t even need to be in any reachable place, just anywhere, where there is a USB power supply.

Besides the compact form-factor of MCUs, the other biggest benefit of ESPHome is that it supports a lot of different accessories and protocols. So even if all you got with HomeAssistant wasn’t enough, now you get even more.

As other parents may know, there is a period in a baby’s life when they have to learn to sleep through the night and consolidate their randomly scattered micro naps into a couple of longer ones. Ours didn’t really want to do that, and we were trying everything we could come up with. Among other things, I got curious about measuring air quality. Once I dug into the issue, I found that carbon dioxide (CO2) levels are pretty important, especially when you live in a noisy city, and may not ventilate your home frequently enough. Another thing I learned is that there are lots of cheap sensors on the market that focus on measuring particle levels (basically, dust), and then estimating CO2 levels based on it. This, obviously, doesn’t guarantee any accuracy, and the “real” CO2 sensors cost substantially more. I opted for Sensirion SCD30 and later SCD41, which are available in the US in the ballpark of $50 apiece. I got one for every room, hooked them up with ESP32 MCUs, and started looking at the data. And oh my…

Even with windows ajar, using a gas stove to fry eggs for breakfast, or a gas oven to bake a cheesecake in the evening, brings CO2 beyond the recommended threshold of 1,000 PPM

We indeed used to have abnormally high levels of CO2 in the entire apartment, and once we started ventilating based on the sensor data, not only our son started to sleep perfectly through the naps and through the night, but we also got rid of feeling overtired or having a hard time concentrating by the end of the day. I learned that frying eggs for breakfast on a gas stove sends CO2 to the moon unless you open windows for ventilation, and a gas oven is even worse than that. Of course, CO2 is not the only air quality characteristic, and ventilation might not be best when outdoor air quality is inferior, or you’re sensitive to the pollen that is in the season. Still, it gives you hugely important insight into your indoor environment.

Going Forward

At this point, I feel like I got more instruments for home automation in my hands than I can use, so I’m slowly grinding through all of the automation projects and enhancements I have on my todo list. I wonder if I’m missing some other big things that would compare to HomeAssistant or ESPHome?.. The only thing that still depends on the Internet connection in my setup today is voice assistant, and there seem to be quite a few options to try for fully-offline mode.

An important thing to remember is that doing anything sensible with smart home, or home automation, as I prefer to refer to it, takes effort and time. It’s not a thing consumers can take off the shelf, plug in, and see some magic. Reminds of the Black Mirror episode about what it takes to do a perfect smart home.

Another important note is that home automation doesn’t solve any fundamental problems. It just takes care of routine and mundane things. It’s like, when you know how to use a computer to drag some files around, versus being able to write a script, that does all of that, and you just need to run it.

I’m incredibly fond of various automations that I use daily by with voice or by pressing hidden buttons - depending on whether I have my hands free, or if I want to open my mouth - such as turning off all light, for when I go to bed or leave home, or controlling blinds and lights in the baby room for various modes like playtime, reading time, or sleep time.

Going back to the analogy with scripts I mentioned above, the only way it can get any better, is when you don’t even need to run the script, but when it runs on its own when needed. Imagine if you were getting work emails with some data, and you’d need to prepare a report on data in each of those? Now imagine if that report would get compiled automatically the moment the email lands in your inbox, and you actually don’t need to do anything, or just need to handle some edge cases. That’s what I’m talking about for home automations - the best part, at least in my opinion, is when it doesn’t require anything from you. When you can stay passive and do not need to initiate any action, and the right thing gets done on its own. That’s the trickiest one to configure, but once you do it, it’s a life-changer. One of such examples - as I mentioned above - is perfect light automation. If/when you get it right, it’s hard to over-appreciate it. My latest tweak is tuning the white balance throughout the day, and any old-fashioned lights just make my eyes hurt now. Or detecting when the baby wakes up in the morning and setting things up for them to play on their own for another hour so that you can get a bit of extra sleep time. Or - the latest thing I’m working on - having sensor data available to you in plain sight so that you don’t even need to ask the voice assistant. That’s like, you already know what’s the weather or CO2 level, and you don’t need to ask Siri for it. Thinking about an eInk display blending with the rest of the interior for now.

To wrap this up, I learned two fundamental things so far about home automation. First, this kind of hobby can keep you busy for many years. And second, when you’re looking back at where you were just a year ago, it always feels like your setup becomes exponentially more advanced.