As of right now, the only HomeKit-certified smart plug available in Australia is the Elgato Eve Energy – which is bulky, expensive, and uses Bluetooth LE rather than WiFi (and thus can’t be used in automation).

TP-Link have two WiFi-enabled smart plugs available (HS100 / HS110). While these smart plugs can’t be directly used with HomeKit – by using Homebridge as a software HomeKit bridge, they work great!

Here’s the recipe:

Connect Smart Plug to WiFi

Follow the instructions that came with the smart plug to connect it to WiFi (ensure that this is the same WiFi network that everything else is connected to). Once the smart plug is connected to WiFi, there is no further need for the Kasa app.

Install (and upgrade) Node.js

The instructions below assume a Debian/Ubuntu installation – I’m currently using Ubuntu 16.04 LTS – they should also work on a Raspberry Pi:

sudo apt-get install npm

Check which version of Node.js is installed – you’ll need at least 4.3.2 for Homebridge and 6.5 for the TP-Link Smart Home plugin.

nodejs -v

For me, that command responded with “v4.2.6” – which is way too old. To upgrade to 6.11 (or any version that meets your needs – just change the last command):

sudo npm cache clean -f
sudo npm install -g n
sudo n 6.11.0

Reboot for good measure..

sudo reboot

Install Homebridge and TP-Link Smart Home plugin

sudo apt-get install libavahi-compat-libdnssd-dev
sudo npm install -g homebridge
sudo npm install -g homebridge-tplink-smarthome

Create ~/.homebridge/config.json:

{
    "bridge": {
        "name": "Homebridge",
        "username": "CC:22:3D:E3:CE:30",
        "port": 51826,
        "pin": "031-45-154"
    },
    
    "description": "Homebridge Server",

    "platforms": [
        {
            "platform": "TplinkSmarthome",
            "name": "TplinkSmarthome",

            "broadcast": "255.255.255.255",
            "devices": [],
            "deviceTypes": [],
            "macAddresses": [],
            "pollingInterval": 10,

            "addCustomCharacteristics": true,
            "inUseThreshold": 0,
            "switchModels": ["HS200"],
            "timeout": 5
        }
    ]
}

Test Homebridge

Run Homebridge directly at the command line to test:

homebridge

An ascii-art QR code will appear; you can use this code to add Homebridge to HomeKit using the Home app. Ignore warnings about the accessory not being certified..

As Homebridge starts up, you should see it load the TP-Link Smart Home plugin, then register and initialise the platform. Shortly afterwards, it will detect and add the smart plug(s) automatically – these should appear in the Home app. I then spent 10 minutes being all impressed that I could tell Siri to turn my heater on/off .. you may or may not be similarly enthralled.. 😉

Create systemd service for Homebridge

The instructions below assume you used the instructions above to install Node.js and Homebridge – paths may be different if you didn’t.

Pre-requisites

The following commands create the service user and directories, then moves the existing configuration into the appropriate locations for starting Homebridge as a service. Finally, set the relevant permissions..:

sudo useradd -M --system homebridge
sudo mkdir /var/lib/homebridge
sudo cp ~/.homebridge/config.json /var/lib/homebridge/
sudo cp -r ~/.homebridge/persist /var/lib/homebridge
sudo chmod -R 0777 /var/lib/homebridge

Systemd config files

Create /etc/default/homebridge:

# Defaults / Configuration options for homebridge
# The following settings tells homebridge where to find the config.json file and where to persist the data (i.e. pairing and others)
HOMEBRIDGE_OPTS=-U /var/lib/homebridge

# If you uncomment the following line, homebridge will log more 
# You can display this via systemd's journalctl: journalctl -f -u homebridge
# DEBUG=*

Create /etc/systemd/system/homebridge.service:

[Unit]
Description=Node.js HomeKit Server 
After=syslog.target network-online.target

[Service]
Type=simple
User=homebridge
EnvironmentFile=/etc/default/homebridge
ExecStart=/usr/local/bin/homebridge $HOMEBRIDGE_OPTS
Restart=on-failure
RestartSec=10
KillMode=process

[Install]
WantedBy=multi-user.target

Load service

sudo systemctl daemon-reload
sudo systemctl enable homebridge
sudo systemctl start homebridge

That’s it! You should now have a functioning Homebridge HomeKit bridge, with TP-Link smart plugs connected and working.

Links and Howtos

Here are the links and howtos I used to get myself up and running:
https://github.com/nfarina/homebridge
https://github.com/nfarina/homebridge/blob/master/config-sample.json
https://www.npmjs.com/package/homebridge-tplink-smarthome
https://gist.github.com/johannrichard/0ad0de1feb6adb9eb61a/
https://timleland.com/setup-homebridge-to-start-on-bootup/

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.