The Smart Tiny House - Part 2: HomeKit & Homebridge
So last post I covered all the smart devices I have installed and this post I am going to cover the platforms I have used to connect them all.
As mentioned in the last post, I have installed several smart devices in my tiny house including bulbs, switches, air conditioner controller and irrigation controllers. Using just the iOS apps they come with I can control these from my iPhone and set some very basic automations through Apple HomeKit. I really wanted to hook in the data from my Victron solar power system however, and use that data to become more efficient with my power usage. But Victron didn't appear to be compatible with Apple HomeKit, they just had an iOS app.
"Works with HomeKit" vs iOS App
This is really key to understanding how to connect your devices. So Apple will happily allow you to connect your "Works with HomeKit" devices directly to HomeKit and then enable your one app (HomeKit) to control them all and facilitate clever automations, including Siri commands. But, like anything affiliated with Apple, there is a cost associated to integration with HomeKit and, as a result, not so many smart devices work with HomeKit. In my home, only my Netatmo Weather Station integrated directly with HomeKit. Everything else had to be controlled directly from the iOS app. So, yes, I could control the remaining devices with my iPhone, but only using their separate dedicated iOS apps. In some instances you can use Siri with these apps but it depends on the app developer and is often fairly clunky. Here's what I mean in a diagram:
I found HomeKit impossible to understand without something in there to let me explore. Adding a device is the first step in that, and it starts by selecting the + icon in the top left hand corner. I won't go into every step but its pretty straight forward.
From the main screen you can toggle devices on and off, you can see all the devices by room (according to how you defined them when you added them) and you can implement some automations. I think there are some suggestions there to help you with your first automations - usually stuff like when you arrive home, turn lights on. Its a good place to start but the suggestions are pretty basic.
So this is a great place to start exploring automations and have some fun. If you are not used to working with the logic of triggers and conditions, just google it and work with some examples. This doesn't take too long to pick up.
Then you can progress to Apple Shortcuts. Shortcuts allow you to create buttons to trigger actions such as a "Lets Cook" button that plays your favourite playlist to your HomePod and opens your favourite cooking app. You can also set a Siri command to start the shortcut by voice. Playing with shortcuts is good for really embedding how automations work and the endless possibilities. Google something like "useful Apple Shortcuts" and you will find suggestions of things you can set up. You can even download other people's shortcuts. This alone will absorb hours of time.
Now in my home, I only had one non-Apple device that would integrate directly with HomeKit. That was disappointing. In my googling to understand how I could make my smart devices work together I established that I could use a bridge, such as Homebridge, to get non-Apple HomeKit devices working together on HomeKit, because Homebridge does "work with Apple HomeKit". Here's how it fits in:
This appeared to be the simplest bridge so I went about learning how to implement this. Any bridge that monitors your devices has to be on all the time, and so if the entire point of the exercise is to be more efficient with your power usage, then leaving your MacBook running 24/7 is not going to achieve that goal. Also, as a laptop it is likely to travel and not be in the home all the time so thats not a good candidate to run things in your home when you are not there. A raspberry pi is a great low cost, low power option so I started the learning curve to get one up and running. I also had one lying around so I resurrected it.
I really wanted to understand my raspberry pi better so I connected it to a keyboard and monitor and installed a fresh copy of the OS and worked out how to install Homebridge on it. It ran as an application on the raspberry pi and required logging into the OS in order to operate it. That was kind of inconvenient as I had to install a remote networking tool and lots of fiddling within the terminal window so I could connect with my laptop (rather than re-connect all the peripherals every time). Once I could access it, it was pretty straight forward but the access wasn't ideal. I let it go but after a stint away from home some integrations started breaking so I decided to wipe it and start again. That's when I found a more convenient installation method.
Unless you are using your raspberry pi for something else, I highly recommend flashing your raspberry pi with the Homebridge image. The process means you simply access the application through an IP address on your network - no peripherals or remote networking required. I'm not going to go into the specifics of how to install it - just google it and watch some tutorials. You'll need to format and load the image on to the SD card of your raspberry pi, but it's pretty straight forward. The end result is something like this from your browser:
The interface is customisable so you can also see the devices (accessories) that you have connected and you can control them from here also. The way you add integrations is through the plugins menu option.
I'm about to switch off my Homebridge as I have moved over to Home Assistant so there is not much on my Homebridge right now, but adding devices is as simple as searching for a plugin. Currently I have the Homebridge UI plugin (which I think is there by default but this is where you can action updates), the Sensibo plugin (for the air conditioner controller) and the Orbit plugin. Now, I had to google B-Hyve and Homebridge to work out if there was a plugin as B-Hyve (my smart watering hardware) didn't come up when I searched here. Turns out that B-Hyve is the name of the hardware I purchased but it operates on a platform called Orbit. So searching for Orbit found a plugin that worked.
In the last post I mentioned that the Arlec and DETA lights and switches promote an app to use with them called Grid Connect. If you search for Grid Connect here you don't find anything useful. Do some googling and that's when you work out that the platform they operate on is called Tuya. Search for Tuya here and then you get a whole heap of options:
Working out which plugin to use requires more googling. You might find a forum post where someone is asking exactly that question, otherwise I tend to use apps that are verified and have been updated somewhat recently (last few months, as opposed to a couple of years ago). The little icon with the arrow in the bottom right corner of each plugin will open up the code repository if you want to see how often it gets updated, otherwise the date under the name is a good indication.
There is a bit more to adding a plugin, including finding your username and password for each device platform (which you would have needed to register the device when you paired it) but its not that hard and google will tell you what to do.
Once you have set this up, you generally don't need to access Homebridge very often, unless something stops working. It's a good idea to take a look every now and then as often the plugins need an update.
It's important to note that as this is running on a local computer (your raspberry pi) you can't access it away from your home network by default. Maybe thats obvious to you, maybe that's not. Apple HomeKit DOES allow you to access your devices remotely so that's a big part of why we want to introduce Homebridge to HomeKit. Also, Siri won't work unless she knows about it and HomeKit is what she refers to. So if Siri knows you have an air conditioner because it appears in HomeKit, then you can say "Hey Siri, turn on Air Conditioner" and she will do it.
Adding to HomeKit
So essentially, Homebridge appears to HomeKit as one more device you want to add. It just happens to be full of devices. HomeKit understands the concept of bridges and warns you that it might not work the way Apple intended it to but you go ahead anyway. You might notice in the first screenshot of the HomeKit UI there is a QR code. Basically when you go to add a new device in HomeKit you can add it with a QR code and that's what you scan. HomeKit wants to know where each device in the bridge is and what you want to call it but eventually it all appears. And now you can control all your smart devices from Apple HomeKit!
What about Victron?
Remember that I said the thing I really wanted to do was to integrate my Victron solar data to perform some cool automations? Did you notice there is a missing line in the schematic diagram from the solar panel? That's because there was no Homebridge plugin for Victron. Ugh. Some more googling and I discovered that there was another bridge that did have a Victron integration (of sorts) called Home Assistant and that an application called Node Red would help me design almost any automation I could think of.
I'll cover Home Assistant in the next post. But here's a teaser of what you can do: