DIY,  Rant,  Technology

Server Build 2.0 Part 4 – HomeAssistant and Security Cameras

Now that we’ve setup our new server, created firewall rules, and created our VMs and Docker containers, it’s time for something new. HomeAssistant is a home automation platform. It’s highly modular and very actively developed. It’s opensource, and there are nerds all over the world contributing. Instead of being limited to devices that are “approved” to work with Alexa or Google Home or whatever Apple’s dumb version is called, you can get almost anything to work with HomeAssistant.

I have a love/hate relationship with HomeAssistant. I love the concept. I love how it works with so many things. I love how creative you can get with it. I love how most of the hardware is super affordable. But holy fuck do I hate how unreliable it is.

Let’s take a step back. My first attempt at a smart home was probably 8ish years ago. It consisted of some wifi smart bulbs and Alexa. It was pretty simple. “Alexa turn on the living room lights.” It was even cooler when they enabled “Computer” as a wake word. I could feel like I was in Star Trek. There were two issues, though. One, Alexa’s… questionable… privacy, and two, the bulbs were absolute shit. I have those ceiling lights where there are 2 or 3 bulbs under the same glass bowl. More often than not, only one bulb would turn on. So I’d try again. That bulb would turn off, but the others would turn on. Sometimes, they would just turn on randomly. I couldn’t tell if I was being hacked or what. Eventually I got frustrated, and went back to normal LEDs, and that thing on the wall with the lever that you move that turns the lights on and off. I can’t remember what it’s called. Anyway, then I heard about HomeAssistant.

HomeAssistant can run on a Pi, a VM, Docker, bare metal, or they sell their own mini computers specifically for HA. It acts as a hub. You can add integrations with all sorts of devices. Each device will create “entities”. Those entities will have values. You can then use those values to trigger actions. It’s all based on the concept of IfTTT (If this, then that). This can be as simple as “if I push this button, turn on this light”, or complicated, like “if the weather is above 60, and it’s sunny outside, and I’m home, then open the blinds”. There are people who have integrated their city’s garbage pickup schedule, to give them reminders. I’ve seen people setup pressure sensors on the floor by their bed, so when they get up and step on it, it turns the lights on. I’ve seen people use vibration sensors so they can tap the table, to turn on the TV. You are really only limited by the devices you have and your creativity.

There are three or four main technologies in play here. First is wifi. This is pretty standard. The wifi LED is on the same network as the HA, so they can connect to each other. The catch here, is that many of these devices phone home, and try to connect to outside servers. This is the main drawback of the original style of home automation. This made IOT devices easily compromised. Thus came ZigBee, Zwave, and Matter. These three technologies are local. That means they only connect to other devices on those networks. (ZigBee only talks to other ZigBee devices) They don’t have the ability to connect to the external internet. Each has it’s pros and cons, based on frequency, distance, and compatibility. ZigBee is open source. Zwave requires each device manufacturer to pay for approval. Matter is still pretty new. Zwave is more expensive. Matter seems to be the future, but there aren’t a lot of devices using it yet. So I opted for ZigBee.

ZigBee requires a hub. Mine was $30. If you’re running HA on a VM or Docker, be sure that USB pass through is enabled. Then go into Settings>Integrations, and search for ZigBee. It will then detect your hub, and start scanning for devices. If you’re installing a lot of lights throughout your home, I’d suggest doing one room at a time, so you can know which bulbs are which. Also, you’ll want a naming convention, because if you change a device’s name later, it can break your automations. It’s a lot easier to set it up once.

I’m not going to go over the thousands of integrations that are available. But I will note that there’s also the HACS (HomeAssistant Comunity Store) which has even more plugins, addons, and awesomeness.

As I mentioned, each device creates entities. For instance, my phone has an entity that shows if it’s charging or not. Another entity tells me if the screen is on. Or if DND mode is active. Meanwhile, a light might have an entity for if it’s on or off, and another that shows its power usage. So each device has different entities available. You can then use that to your advantage. In my case, let’s say I want to use my security camera (I’ll get into that later). It has an entity for detecting if a person is moving. I want to use that motion sensing to turn on the kitchen lights. That’s simple. “If Kitchen Camera person motion=true, then Kitchen Lights Group on=true, power=100%, color=warm white.” The actual screen to set these up is very different, but I’m trying to convert it into a text form that makes sense. If it doesn’t detect motion, it waits 20 seconds, then turns the lights off. Neat. But let’s say I have to get up in the middle of the night to get a drink of water. I don’t want those lights to blind me and wake me up. When I go to bed, I put my phone on DND. That’s an entity, so we can incorporate that into our automation. “If Kitchen Camera person motion=true, and Chris’ Phone dnd=true, then Kitchen Lights Group on=true, power=50%, color=red”. Now, the motion is detected, it checks if my phone is on DND, if it is, then it changes the lights to red, and only turns them up 50%.

There’s really a lot of different things you can do. Plus, you’re not limited to only smart devices. I have two ACs. Both are dumb ACs. They use IR remotes. Just like you can program a universal remote to work on different TVs, you can do something similar with AC remotes. I found an IR blaster that looks like a tiny jar of spices, that can work with HA, and you can teach it remote codes. The power cable, also contains a temperature and humidity sensor. So I can create an automation like this: “If Bedroom temp=>60 but <70, send FAN command. If Bedroom temp=>70, send COOL command. If Bedroom temp=<50, send POWER command.” This means that I can essentially “set a thermostat” in HomeAssistant, and it will tell the AC what to do to keep it somewhere close to the temperature I want. The IR blaster can also work with multiple devices, so in the living room, it can control the TV, the sound bar, the DVD player, and the AC. All from one itty bitty $20 hockey puck looking thing.

Ok. Let’s talk about the cameras. I mentioned in the first article of this series, that my old security camera system was old. It was unusable from modern computers, and the quality was what you’d expect from something 15 years ago. I’ve always hated the idea of internet enabled cameras. I simply do not trust them. I don’t want some random person in another country having the ability to watch me cooking. Or anything else. However, with my new found knowledge of firewalls I realized that I could get an internet connected device, and simply block it’s connection.

At this point, I had only dipped my toes into HomeAssistant, but I liked what I could do, so I looked for devices that worked with HA. Reolink came up. I checked online, and they were really affordable. It might have been a Black Friday sale or something, but I got an outside camera for $50, and 4 indoor cameras for $30 each. Hooray. However, I missed one tiny little thing. Only SOME of the Reolink cameras worked with HA. The outdoor camera? No issues. It was found right away, and I named it, and I was done. The indoor cameras, on the other hand, were a pain.

They worked. They did what they were supposed to do. But HA’s Reolink integration didn’t see them. It’s purely a firmware issue. There’s no reason for them to not work, other than Reolink doesn’t want them to. Well, time for some more research. It turns out there’s a camera protocol called “ONVIF”. There’s an integration for ONVIF. My cameras support ONVIF. And I still couldn’t get it working. It turned out that the feature wasn’t available on the Reolink Android app. You had to use the Windows app. I don’t use Windows. So I had to do it from a VM. Fine. Deep within the settings, I turned ONVIF on. HA saw them. I named them, and we are off to the races.

For a while. At some point, the cameras had a firmware update that didn’t allow HA, but did reset ONVIF back to off by default. I went back into my Windows VM, back to the Reolink app, back to the settings… and crashed the VM. Which also crashed my computer. Which also caused data loss. Which meant I had to reinstall Qubes on my laptop and start over. Fucking perfect. Eventually I got everything back up, and the cameras working again.

For a while. Then for some reason, the bedroom camera and the living room camera kept getting confused. The living room feed would show the bedroom. The bedroom kept showing as disconnected. After factory resetting them like 20 times, and fighting with Reolink’s tech support for what seemed like a month (during which time they refused to even entertain the possibility that the issue was the cameras. They insisted the problem was my network). Anyway, after fighting with them for a really long time, they finally sent me a replacement, and as of writing this, we are at… 3 months of everything working.

So now we’ve got all these cool devices and automations, but how do we want to control them? Sure, I can use the phone app. But what if my girlfriend comes over? Well, they do make some wall mounted options. They even make ZigBee light switches. Light switches. That’s what they’re called. Anyway, I live in an apartment, so that’s not really an option. Then I remembered I had an old tablet that I had purchased to use as an ebook reader, but ended up never using because I prefer real books. I simply did a reformat, and added the HA app on it. Then I created a basic user without admin privileges. That way the tablet can control the lights or whatever, without having the ability to change any configurations.

Then I started having fun with dashboards. You can use “cards” to display all of the information that is being funneled into HA. You can create buttons, sliders, graphs, all sorts of things. You can create different dashboards for different uses. Like, I have one for on my phone that controls my most often used devices, and another for the living room tablet that controls the devices in that room, and the main one for my laptop that shows everything.

Which brings me to my main issue with HA. The reliability. When it works, it’s amazing, bordering on magical. And to be clear, it works most of the time. There are times, however, where for no obvious reason, stuff just doesn’t work. Or things randomly start working and I haven’t changed anything. I had this idea for an automation. Wouldn’t it be cool if the TV would turn on when I got home from work? After searching various forums and websites, I came up with what seemed like a reasonable way to do this. I created an automation that tracked my location. If I was connected to my home wifi, I was listed as “home”. Once I disconnected from my wifi, it would change me to “away”. But if I go to take the trash out, and it kicks me off the wifi, I don’t want that to trigger the TV. So I added a wait time of 1 hour. If I was “away” for over an hour, and then was listed as “home” again, turn on the TV. It never worked. I couldn’t figure out what I was doing wrong. Eh. It’s literally one button on the remote. I can just turn it on like the ancients did.

Then 2 weeks ago, I got home from work and my TV was on. I assumed I had left it on, or maybe the cat sat on the remote and turned it on. Until it happened again. And again. Finally, after the 5th time of finding the TV on, I looked at Home Assistant, only to find that the automation had been executed. I changed literally nothing. Suddenly it’s working. I mean, I’m glad that it’s working, but at the same time, what the fuck?

Another example would be the $13 Voice Assistant project that got a lot of attention a couple of years ago. For the life of me, I couldn’t get it to work. I mean, it’s configured. It’s recognized in HA. It just doesn’t WORK. Wake word doesn’t work. Pushing the button turns the light on, but that’s it. And the speaker is so small and low powered, that if it talks, you can’t hear it. Completely fucking useless.

In the end, I think HomeAssistant is pretty amazing. It can be overwhelmingly complicated at first, but that’s just because it can do so many neat things. It’s not for everyone. It’s not something that your random family members will want to manage. But if you set it up for them, they’d be blown away with how awesome it is. I think it’s meant for hobbyists and tinkerers, and I look forward to each new version, just to see what new possibilities have been introduced.

My name is Chris. I currently live in Seattle, though I’m formerly from California. I'm a writer, comic, and superhero (allegedly). I complain. A lot. About everything. I also tell jokes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.