Having fun with HomeKit and non-HomeKit devices

Wanting to build my knowledge around a few things – i’ve played around lately with Apple’s HomeKit – designed to make integration of smart home devices easy for anyone.

At the moment, the range of HomeKit supporting accessories is limited – especially within Australia. And I already had a few IoT devices from Belkin (Wemo), D-Link (IP Cameras), LIFX (Lights) and a Logitech Harmony Elite (Audio Visual) which did not offer HomeKit support. All these were in good working order, and there was no point replacing them.

I thought I’d spent a little time writing up my experience, sharing some things I learned along the way, in the hope it helps others going down the same journey – even if they’re only tinkering, or just trying to get their configuration right.

Enter Homebridge

After a bit of research, I stumbled upon a package called Homebridge – billed by its creator Nick Farina as “HomeKit support for the impatient”. I’ll let the Github homepage give you an overview of what it is:

Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It supports Plugins, which are community-contributed modules that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of “smart home” devices.

And yes, it does exactly what it says on the label. Installed on an existing machine, a home server, or even a Raspberry Pi if you have one kicking around, it’ll sit there and seamlessly integrate all these Non-HomeKit devices into HomeKit.

The collection of user-developed packages for Homebridge is huge, over 700 at the time of writing this article – covering everything from TV’s, power switches, lights, IP cameras, weather API’s, and so on.

Needless to say, this is exactly what I was after. And after a bit of exploring, I found that both Belkin Wemo and LIFX had packages already built; and it was possible to get my D-Link cameras also working with another package.

Here’s hoping this article helps you enjoy the Home and Siri features in iOS as easily as I have with your IoT devices that don’t currently support HomeKit.

With iOS 11 and HomeKit, do you still need Homebridge?

As covered during Apple’s WWDC 2017 event, software authentication will be introduced – and hardware developers will no longer require that every HomeKit device includes a specific security chip.

So, the usefulness of Homebridge long term will depend on how long it takes existing and active IoT platforms to release updated firmware that provides software authentication built in. For larger platforms and developers, this may be relatively quick.

For hardware which is end of life (EOL), not easily updated, or released by smaller companies, a Magic 8-Ball is going to be giving the best answers on when they’ll release (short version – not likely) – so Homebridge will be a great stop gap for you.

Environment

Initially, I installed Homebridge onto a 13″ 2016 Macbook Pro. However, I’ve recently elected to move the installation onto a Mac Mini running with macOS Server.

Current Non-HomeKit IoT hardware environment consists of:

  • Lighting
    • 4x LIFX Colour 1000 Lights
  • Power
    • 2x Belkin Wemo Insight Switches (great for power consumption monitoring)
    • 1x Belkin Wemo Switch
  • Security
    • 2x D-Link IR Day/Night cameras
    • 2x D-Link Day Cameras
  • Audio visual
    • Logitech Harmony Hub
    • Apple TV 4th Generation – needed as a home hub, for automation and remote control
      Note: You can use an iPad instead, but this will need to remain in the home at all times for these features to be available when away from home.
  • Low Voltage sensors/controllers

Future additions may include:

  • Additional Belkin switches
  • Additional LIFX lighting

 

How did I do it?

Pre-requsites

If you’re reading this article, let’s presume you’re the type of person who already has a good home internet connection and wifi network, so I’ll skip over that part.

To do this successfully, you will need the following:

  • A home computer or server that’s ‘always on’
    (i.e. Windows, macOS, Linux, or even some NAS boxes)
  • An Apple ID configured with both:
    • Two-factor Authentication, and
    • iCloud Keychain
  • Home hub
    The features you want will determine your minimum hardware requirements for the device you use as a home hub:

    • If you want to control accessories remotely: Apple TV (3rd generation)* or an Apple TV (4th generation) with tvOS 9.0 or later.
    • Automations and user permissions: You need an Apple TV (4th generation) with tvOS 10 or an iPad with iOS 10 or later.
  • Patience
    This will involve some trial, error, and some downloads. Don’t do this while tired, take your time, break it down into small pieces, and you’ll be amazed how well things work. This is especially true of when installing the Belkin Wemo Maker, as you’ll need to understand the device you’re connecting it to, what connections it offers, and have the manuals for it.

Installation

  1. Follow this guide for installing Homebridge on macOS:
    https://github.com/nfarina/homebridge/wiki/Install-Homebridge-on-macOS
  2. Install Homebrew (only needed if intending to view cameras with the homebridge-camera-ffmpeg package)
    https://brew.sh/

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  3. Install FFmpeg using Homebrew (Again, only needed if going to be using homebridge-camera-ffmpeg)
    $ brew install ffmpeg
  4. Install the relevant packages for my devices:
    $ npm install homebridge-camera-ffmpeg
    $ npm install homebridge-harmonyhub
    $ npm install homebridge-lifx-lan
    $ npm install homebridge-platform-wemo
  5. Complete your config.json configuration file (see more below).
  6. Run Homebridge
  7. Follow the Apple Support article Use the Home app on your iPhone, iPad, and iPod touch (HT204893) to get the Home app setup, create your rooms, connect to Homebridge, and assign accessories to rooms, setup favourites etc.
  8. Follow the Apple Support article Automate and remotely access your HomeKit accessories (HT207057) so you can create automations,  remotely control things away from home, and grant access to other people.

Configuration

When you go through the earlier installation steps, you’ll setup your config.json file.

If you’re new to JSON, I’d strongly suggest writing your config file in a text editor first, then testing it validates using JSONLint, before pasting it into your config file, saving, then starting up HomeKit.

I’ve obfuscated a few things in here obviously, the README file for Homebridge explains how to create your config.json file, and includes a sample file you can build on.

And remember – don’t use the default PIN in the sample config file. Leaving it as the default is going to make you look pretty silly when someone finds you’re running Homebridge, connects to your homes’ wifi network that you thought was properly locked down, and starts turning on and off all manner of switches (or turning on the TV audio at 3am in the morning with the last channel you had on – which will endear you to the neighbours).

{
 "bridge": {
 "name": "Homebridge",
 "username": "XX:XX:XX:XX:XX:XX",
 "port": XXXX,
 "pin": "XXX-XX-XXX"
 },

"accessories": [],

"platforms": [{
 "platform": "LifxLan",
 "name": "LiFx"
 }, {
 "platform": "HarmonyHub",
 "name": "Harmony Hub"
 }, {
 "platform": "BelkinWeMo",
 "name": "WeMo Platform",
 "noMotionTimer": 60,
 "ignoredDevices": []
 }, {
 "platform": "Camera-ffmpeg",
 "cameras": [{
 "name": "Cam 1",
 "videoConfig": {
 "source": "-re -f mjpeg -i http://username:password@10.0.0.1/mjpeg.cgi -i http://username:password@10.0.0.1/audio.cgi",
 "stillImageSource": "-f mjpeg -i http://username:password@10.0.0.1/mjpeg.cgi",
 "maxStreams": 2,
 "maxWidth": 640,
 "maxHeight": 480,
 "maxFPS": 30
 }
 }, {
 "name": "Cam 2",
 "videoConfig": {
 "source": "-re -f mjpeg -i http://username:password@10.0.0.2/mjpeg.cgi -i http://username:password@10.0.0.2/audio.cgi",
 "stillImageSource": "-f mjpeg -i http://username:password@10.0.0.2/mjpeg.cgi",
 "maxStreams": 2,
 "maxWidth": 640,
 "maxHeight": 480,
 "maxFPS": 30
 }
 }, {
 "name": "Cam 3",
 "videoConfig": {
 "source": "-re -f mjpeg -i http://username:password@10.0.0.3/mjpeg.cgi -i http://username:password@10.0.0.3/audio.cgi",
 "stillImageSource": "-f mjpeg -i http://username:password@10.0.0.3/mjpeg.cgi",
 "maxStreams": 2,
 "maxWidth": 640,
 "maxHeight": 480,
 "maxFPS": 30
 }
 }]
 }]

 

Diagnosing problems

The quickest way to find any issues is to keep an eye on Homebridge’s logfile, using this command before you start Homebridge:

tail -f ~/.homebridge/logfile.log

From there, you’ll see the output of the logfile, and spot whatever is going on.

 

And the results…

Well, here it is – three quick scenes, all the accessories, all configured and ready to be controlled.

The Home app on iOS 10, all nicely configured, working, and responding happily to Siri commands.

 

Things I learned along the way

  • Cameras
    As long as your camera has a stream in a supported format, you should be able to integrate that camera. for the camera-ffmpeg package, there’s a growing list of known good configurations you can work from for various cameras. The good thing is that D-Link’s cameras have used the same URI’s for their features for as long as I can remember – so the posted known good configuration for the DCS-932 will work for pretty much any D-Link consumer camera in circulation.
  • macOS and FFmpeg
    I initially found this difficult, as I’d lost a lot of *nix experience over the time. I didn’t understand that I needed to install the FFmpeg packages first, and didn’t know the best way to do it. This detailed answer on Stack Overview set me right, and made me realise that Homebrew was the fastest way to install it, and keep the package up to date.
  • Garage Door
    Luckily, the garage door at the place I live has various connection terminals on its controller board for wired control of both open/close, and sensors to indicate if the door was opened or closed. This meant no need to buy a magnetic reed switch and install it – saving extra time and work. A quick read of the manual, and looking at a good article from someone else who’d used the Wemo Maker for the same purpose, enabled me to figure out the wiring I needed to use, and got it done in one go (For the sensor, wiring COM on the door controller to – on the Wemo Maker, and NC to S).

 

Things I can’t yet do

  • Cameras – Live view
    At the moment, the Apple Home app on iOS only show a new image every 60 seconds. I’ll be digging into that a bit more to understand how to improve the refresh rate, if at all possible. It may be a limitation of the platform package being used to do that, or something else entirely.
    The refresh rate has come down to 10sec in the Home app now, with no intervention on my part. Would still like to try and get it working to a stream, but that requires more reading and understanding on my part.
  • Cameras – Alerts
    There is at least one sensor package I’m yet to try, which uses the SMTP notification features of most cameras to provide alerts, or trigger actions when there are unexpected motions. I’m yet to sit down, understand which is the best package for my needs, and get going with it. Something to explore another time.
  • Harmony Elite – Other controls
    At present, the package can only switch your configured activities on and off. It can’t change volume, pass other commands (stop, play, pause, input, show TV guides, etc). Not being a programming person, or having a deep understanding of the HomeKit platform, that’s something I’m not able to tackle. Maybe there’s a smarter cookie out there who just might be able to achieve it.
  • Onkyo receiver/amplifier integration
    Whilst there is some NPM’s out there for network-controllable Onkyo receivers, i’ve not had any luck getting these working as yet. As i’m not a programming kind of person, it’ll be more trial and error with the existing packages to see if and how they work.
  • Air Conditioner
    Due to the range of the Harmony Elite’s IR senders, I can’t yet find a position which will successfully switch on and off the split system AC I have in one part of the house.