[UPDATE] There's a far better way to do this now that isn't limited to binary devices and lets you do all the automation in Hubitat where it's easy and powerful.
I've been chasing this one for a while. I'm not a fan of working too hard at making home automation work for me. This is one of the primary reasons why I'm here and no longer a SmartThings user, among several other disadvantages of that platform.
I'm addicted to home automation, so it should come of no surprise that I'm willing to try different systems, but I personally still haven't found anything I like as much, or offers as much capability in a single platform, with as little effort as Hubitat Elevation requires. My stuff just works. I don't have to spend time maintaining it or chasing hardware issues beyond the occasional device trouble that is just not completely avoidable. Everyone encounters it on every platform. But despite my early sketchy results with keeping many Xiaomi devices joined with HE due to their non-standard Zigbee, I have become very fond of them when attached to a Xiaomi Aqara hub. Like my beloved HE hub, the Xiaomi device, when paired to an Aqara Hub just work. No drops, no failures, incredible battery life, nice styling, small and very inexpensive.
But the downside of them is there's no direct way to sync the most commonly available hubs which include the current Aqara HomeKit hub and the Mijia Multimode Gateway. By using a HomeKit hub such as an Apple TV, HomePod, HomePod Mini, an always on iPad, there were simple ways to get the state of these devices synced with Hubitat, but only by investment in Apple hardware. And if you're not an Apple MacOS or iOS user, you simply couldn't do it very easily at all. Yes I've been told by Node-Red users that you could achieve it with Home Assistant and Node-Red. Now I know that Node-Red users swear by it for their automations, but setting up, learning and maintaining both Home Assistant and Node-Red seemed a fairly steep hill to climb for just a few Xiaomi devices.
So I've been playing with leveraging a specific capability of Home Assistant which, to my knowledge is completely unique to that platform. Don't mistake this for an "I'm now a fan of Home Assistant" post. For a free software, it's not unbearable, but for ease of use it's a far cry from Hubitat Elevation. And from what I've read, Open Z-Wave and many devices that don't fully function leaves one heck of a gap as a user friendly choice. So no, this is very much a post about getting really inexpensive, small and reliable Xiaomi devices into Hubitat for the purpose of automation with Rule Machine.
I would love for these device integrations to be created for HE. It would solve a lot of issues when it comes to the gaps in device compatibility. The Hubitat team has done a tremendous job in getting a ton of devices all working properly with the Hubitat Elevation hub, but there's a mountain of devices out there, and not all of them are well made or possible to integrate. One thing that remains very apparent is there's almost always a way to integrate devices with at least one system, but one stop shopping is a massive challenge. Hobbyists that want something and have the time can usually achieve it eventually. No business pressures or customers to please. If it works it works, if not, there's typically no company that's going to suffer as a result.
Compatibility
After setting up a simple to use Hubitat Elevation and Hoobs smart apartment for my daughter, I became a little more interested in what Hoobs is doing. Not because it's more powerful than pure Homebridge, but mainly because it was so very simple to setup and use. I downloaded the free image and wrote it to an SD card. About 10 minutes later I was adding HE devices to HomeKit. So I started toying with the concept of using Hoobs to facilitate the syncing of devices. To be clear, it cannot do that on its own, but there are some compatibility surprises with Home Assistant that make the two together a very easy link that can be run on a single computer, and probably would work fine on a Raspberry Pi 4 or in Docker.
Bridging the gap
HOOBS
Hoobs, for the unfamiliar is a fancy UI on top of Homebridge. But it's actually a little bit more than just that. It's also a simple dashboard for anything exposed to Hoobs. So with a very simple setup that takes only a few minutes, you can expose just about any device joined with Hubitat Elevation to Hoobs, and if you're an iOS or Mac user, you can also see them in the Apple Home app.
Home Assistant
Explaining what Home Assistant to this crowd seems almost silly, but there might be someone that's never heard of it. This open source home automation platform has been around for many years. It has been, and for the most part remains purely something that only home automation geeks like me would dare to touch (even though I've mostly avoided it until now). It's UI is not too bad looking, but it has a lot of terminology that I don't see used in other platforms, and it's apparent that it's a UI layered on top of Yaml. Home Assistant has a reputation of being difficult to install and setup at times. They definitely lived up to that for me trying to install it on a spare Mac. Several hours over the holidays were consumed to get that working. I would recommend anyone without a ton of patience and several hours to spare, just download the all in one image for Raspberry Pi.
[Edit]
For installation on the Mac (or any other computer), I really wish I had tried Virtual Box first, before going through all the struggle to install it through the Mac terminal by creating with a virtual volume and the adding all the dependencies. First, it doesn't support Hass.io so you don't have access to the Supervisor and the add-ons store, and second, it's SO MUCH more difficult to setup. I downloaded Oracle Virtual Box on a very old (2009 MacBook) and it installed in a minute, without requiring any additional downloads. I then followed the simple instructions for Virtual Box here, and the full Hass.io was ready in 5 minutes!
I gave the VM have the amount of RAM (1024) than the suggested 2GB (because 2GB is all the MacBook I'm using for this has available). It runs fine. Highly recommend anyone with a spare laptop computer, simply use Virtual Box for this. Much easier and less expensive than a dedicated RPi for this particular task.
Xiaomi Aqara
The Aqara HomeKit Hub is among the newest hubs coming out of China that support the Xiaomi Mijia, Aqara and several other device brands available to the Chinese market. Most of these devices are nice in appearance, inexpensive, small, have great battery life, and are very reliable (when joined with a Xiaomi hub). There is one very specific Xiaomi hub that can be joined to Hubitat Elevation with the community provided MiConnector app, or to Home Assistant. But the effort and uncertainty of getting everything working with that isn't all that reassuring to me personally.
How it works
When HE devices are exposed via Hoobs and thus HomeKit, the Homebridge application beneath all that eye candy is only sharing them in a single direction. HE to Hoobs. You also cannot see official HomeKit devices in Hoobs. Genuine HomeKit capable devices added via an Apple device will only appear in the Apple Home app, and you cannot get their status from Hoobs or Homebridge directly back into HE.
Home Assistant has a similar capability to share devices to a HomeKit network, but they also have a very interesting capability called HomeKit Controller. No idea how they have not been sued by Apple for the name alone, but here's how it works. They too cannot "see" devices that are in an official Apple HomeKit environment, but they can emulate a HomeKit hub (sort of). They definitely cannot share devices in iCloud, as that would bring on the Apple lawyers in the blink of an eye. Therefore there's also no remote access through the Apple Home app with this integration. However, if you disconnect a HomeKit compatible device from any official Apple HomeKit environment and instead join it via the HomeKit Controller integration, the devices can be controlled and their state will update in Home Assistant. So why does that matter, we're trying to get HomeKit devices synced in HE right? Stay with me, almost there.
Completing the link
When you install the HomeKit Controller integration in Home Assistant, there's a dialogue that asks for the HomeKit PIN. This PIN is how accessories are normally added to HomeKIt. Any hub or HomeKit capable device that isn't exposed via Hoobs or Homebridge will have a PIN code. That means that Hoobs also has a PIN code that can be added to the HomeKit Controller integration on Home Assistant, and so too can the HomeKit compatible Xiaomi Mijia and Aqara hubs. When you do that, all their devices are also exposed to Home Assistant.
Still with me?
So we expose devices to Hoobs, and its devices, plus all the Aqara HomeKit Hub or Mijia Multimode Gateway devices are now showing up and displaying their current state in Home Assistant. Once you have the state of HomeKit capable devices and devices exposed to HomeKit via Hoobs, you can link the ON/OFF, OPEN/CLOSED, etc. device states to a virtual device in HE. When you share the virtual device from Hubitat Elevation via Hoobs, the HomeKit Controller integration in Home Assistant will bring it into Home Assistant. So you simply create a basic automation in Home Assistant for the two states of the HomeKit enabled Xiaomi devices. That allows them to be synced with the Hubitat Virtual device, and there you have it. Xiaomi Aqara devices (most of them anyway) with status and control (where applicable) in Hubitat Elevation. Then the really difficult automaitons can more easily be built in HE Rule Machine.
Beyond Xiaomi
It should be apparent that if you can expose Xiaomi HomeKit enabled devices to HE this way, you can also expose just about any real HomeKit device to HE. And because there are a ton of Homebridge integrations that are really easy to install in Hoobs, you can expose them to the HomeKit controller integration, and thus sync them back to HE. Obviously this can also be used to sync devices joined directly with Home Assistant back to HE , but that is beyond the scope of this post.
Setup
- Download and install Hoobs (I didn't test with Homebridge but it should be possible as there is a PIN code in the config.json file). Easiest to download and image a single SD card to run on a Raspberry Pi by itself, but I have Hoobs running on an old Mac together with Home Assistant. The performance is good and the virtual devices react instantly to the real devices.
[Edit]
For installation on the Mac (or any other computer), I really wish I had tried Virtual Box first, before going through all the struggle to install it through the Mac terminal by creating with a virtual volume and the adding all the dependencies. First, it doesn't support Hass.io so you don't have access to the Supervisor and the add-ons store, and second, it's SO MUCH more difficult to setup. I downloaded Oracle Virtual Box on a very old (2009 MacBook) and it installed in a minute, without requiring any additional downloads. I then followed the simple instructions for Virtual Box here, and the full Hass.io was ready in 5 minutes!
NOTE: If you want to install Hoobs on a Mac like I did, use these instructions.
-
Search for the Hubitat plugin for HomeBridge with MakerAPI in the Hoobs plugin search and follow the instructions to setup MakerAPI on your HE hub for using it with Homebridge..
-
Download and install Home Assistant. I installed on the same old Mac that is running under MacOS El Capitan with Hoobs installed. Installing Home Assistant on a Mac was frustrating. Getting it set to use the correct version of Python with all the dependencies was a massive test of my patience, but I eventually got it to work. If anyone else wants to go this route, I can offer up the links that helped get me through the ordeal. I would recommend the complete, ready to go image for a Raspberry Pi, or maybe installing on a Docker image as I read many others recommend as I was searching for answers to the numerous issues I was facing.
-
Factory reset your Aqara HomeKit Hub or Mijia Multimode Gateway (HomeKit compatible). During the Aqara or Mijia configuration, the Aqara and Mi Home app will prompt you to join a HomeKit network if you have any iOS device on the network. Cancel that action or you will have to reset the device and start again.
-
Add the HomeKit Controller Integration to Home Assistant. It will prompt you for the PIN code of your accessory. Add the PIN from your Xiaomi Aqara HomeKit Hub or Mijia Multimode HomeKit compatible Gateway.
-
Add at least one device to your Xiaomi Aqara HomeKit Hub or Mijia Multimode HomeKit compatible Gateway to test. Restart Home Assistant.
- You should see the Xiaomi device in your Home Assistant device list. Test the device to ensure you see its state changing in Home Assistant.
- Create a virtual switch in HE and add it to the MakerAPI instance for Hoobs. Restart the Hoobs service.
- You should see your HE virtual switch in the Hoobs Accessories under the category "Unassigned". Actuate the switch from Hoobs and ensure you see it turn ON/OFF in HE.
- Locate the Home PIN in Hoobs. This is found in the Hoobs configuration (the gear icon in the lower left corner).
-
In Home Assistant, add the HomeKit Controller integration again, but this time enter the PIN from Hoobs. The integration must find a HomeKit compatible accessory that isn't already bound to a HomeKit network.
-
You should see both the Xiaomi hub and Hoobs added to the HomeKit Controller integration.
-
Restart Home Assistant again (if anyone knows how to make new devices appear without having to restart Home Assistant every time, please let me know so I can update the post).
-
You should now also see the HE virtual switch in the Home Assistant device list. Create an automation so when the device is inactive, closed or OFF, it will turn OFF the HE virtual switch.
- Create a second automation so when the device is active, open or ON, it will turn ON the HE virtual switch.
- Actuate your Xiaomi device. You should see the virtual switch in Hubitat Elevation changing state with the change in state of the real device. If it's a HomeKit outlet or a light, you should be able to also turn it ON or OFF from HE by toggling the HE virtual switch.
You can now repeat these steps for the remainder of your Xiaomi devices and you will be able to use the HE virtual devices synced to the Xiaomi real devices in your HE Rule Machine 4 automations.