In my previous posts I have given an introduction to my smart-home setup and described the setup of my Philips Hue lights and Eve door sensors. Finally I have concluded with the HomeKit setup.
In this post I will describe the integration of devices that don't natively support HomeKit.

Introduction

I have already explained in my introduction post, and then again the other one focused on HomeKit, about the security and certification requirements that the manufacturers must go in order to make their devices compatible with HomeKit.
In some cases these integrations are announced and take some time, while in other cases there is no information about it.
Luckily there is a solution that allows to integrate some of these devices: Homebridge.

Homebridge is a NodeJS application that acts as a server, that acts like a bridge between the HomeKit server in your home and the external devices.
As Node.js is very portable, you can deploy it in almost any server you might have: a Windows PC, an Apple Mac, a Raspberry Pi or even some NAS supporting Docker, for example Synology.

I would say, during setup and configuration, Windows PCs and Apple Macs are very easy to install and configure (see configuration section later).
But these are also the least adapt for a running server. As I don't own any NAS, I have chosen the Raspberry Pi way, and I will describe here my setup.

Raspberry Pi setup

Even if you have a Pi, it's always better to re-install it to update the operative system and its software.
For the reset, I have followed the official Raspberry guideline Installing operating system images:

  • Download the latest version of Raspberry Pi Imager and install it.
  • Connect an SD card reader with the SD card inside.
  • Open Raspberry Pi Imager and choose the required OS from the list presented.
  • Choose the SD card you wish to write your image to.
  • Review your selections and click 'WRITE' to begin writing data to the SD card.

Raspbian

Once the writing has been completed, connect keyboard and mouse to the Pi, insert the memory card and boot the Pi.
Here you will be asked:

  • location, keyboard, language (you can override the language to English);
  • change the user password;
  • connect to your wi-fi;
  • update the operative system and its applications.

Then I suggest you to Enable SSH as described in SSH (Secure Shell): from Preferences | Raspberry Configuration | Interfaces tab | SSH: Enable

In this way you will be able to control your Pi from your computer, without the need of a locally attached keyboard and mouse.

You can run:

whoami
hostname -I

This should return the user pi and your local IP address, in my case 192.168.1.110.

So you can connect to your Pi from your Windows Pc or Apple Mac with:

ssh pi@192.168.1.110

where you will be asked your password.

Homebridge setup

For the Homebridge installation, I have followed the official documentation Install Homebridge on Raspbian.

Install Node.js

Install the LTS version of Node.js from the official repository, as well as additional dependencies:

# setup repo
curl -sL https://deb.nodesource.com/setup_12.x | sudo bash -

# install Node.js
sudo apt-get install -y nodejs gcc g++ make python

# test node is working
node -v

# upgrade npm (version 6.13.4 has issues with git dependencies)
sudo npm install -g npm

Install Homebridge and Homebridge Config UI X

Install Homebridge and Homebridge Config UI X using the following command:

sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x

To setup Homebridge as a service that will start on boot you can use the provided hb-service command.

sudo hb-service install --user homebridge

This command will do everything that is required to setup Homebridge and the Homebridge UI as a service on your system, it will create the homebridge user if it does not already exist, and create the default Homebridge config.json under /var/lib/homebridge if it does not already exist.

When setting up Homebridge as a service using this command, the UI will stay online even if Homebridge is crashing due to a bad plugin or configuration error.

Login to Homebridge Config UI X

The Homebridge Config UI X web interface will allow you to install, remove and update plugins, and modify the Homebridge config.json and manage other aspects of your Homebridge service.

Login to the web interface by going to http://< ip address of your server>:8581, for example in my case it is http://192.168.1.110:8581.

The default user is admin with password admin.

Here you will have a nice UI where you can monitor your Homebridge installation very conveniently from your browser on your local computer:

Homebridge

Note that from this UI you can conveniently update HomeBridge itself plus its plugins.

Logitech Harmony plugin

Once installed the Homebridge server, now you have to add a plugin for each device you want to integrate.
In my case, so far I need to integrate only the Logitech Harmony, a device used to control TV, Xbox, Amplifier, Blue-Ray reader and much more.

From the Plugin tab, search for Harmony:

Harmony-plugin

As shown in the above picture, you will find multiple results. I would suggest choosing the first plugin, that seems to be the most updated and supported.

Once installed, you will be asked a few parameters:

  • Name: the default name in the plugin documentation is HubName;
  • IP Address: you can find from the Harmony iOS app, under About | Versions | Hub IP Address;
  • Hub Name in Harmony App: in my case it is Harmony Hub.

These values will be used to fill-in the Json config file, that you can access from the Config tab.
The configuration file is documented in the Npm repository.

With the default configuration file, HomeKit adds a single TV accessory with multiple inputs, one for each Harmony Hub activity. I didn't find it user friendly at all.

So I have changed it, to expose the various activities as individual switches:

{
    "bridge": {
        "name": "Homebridge D30A",
        "username": "0E:84:C2:65:D3:0A",
        "port": 51496,
        "pin": "572-42-620"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8581,
            "platform": "config"
        },
        {
            "name": "HubName",
            "hubIP": "192.168.1.146",
            "hubName": "Harmony Hub",
            "platform": "HarmonyHubWebSocket",
            "TVAccessory": false,
            "switchAccessories": true
        }
    ]
}

Add to HomeKit

Once finished the configuration, you can go back to the Homebridge homepage, where you will be presented a QR code.
From the Home app on your iPhone, click "+" on the top right corner, Add Accessory, and scan the QR code.
This will add the bridge to the Home and (with my configuration above) a switch accessory for each activity.

Now, you can also use this accessories in your HomeKit scenes.

I have also renamed the accessory in HomeKit:

  • from "Watch Apple TV" to "Apple TV";
  • from "Play Xbox One X" to "Xbox One X"

In this way, I can say "Hey Siri, switch on Apple TV"