LightwaveRF and Nest are currently not supported by Apples HomeKit and could be awhile until this happens. The wait is now over thanks to the HAP NodeJS bridge.
What is the HAP NodeJS Bridge?
The HAP NodeJS Bridge (by Khaos Tian) is basically a way to instantly enable any smart or connected home automation product to be used with Apple Homekit.
The HAP Bridge acts like a Homekit bridge and gives a platform to define each of your devices as an accessory.
Once you have the server running you will need a Homekit enabled app installed on your phone. If you have a Apple Developer licence you can click here for a demo as a start or you can download one of many new Homekit enabled apps from the AppStore (e.g. Eve).
After you’ve installed and configured the app, you can start using Siri to control your home. Commands include:
- Siri, turn on the living room lights
- Siri, set the temperature to 20 degrees
If your phone is plugged in for charging you don’t even need to touch your phone to control your devices, just say your command after “Hey Siri!”
How do you install and configure the HAP NodeJS Bridge?
The perquisite to installing the HAP bridge is that the systems needs to have NodeJS (atleast verision 0.12). The installation and launch details of the HAP Bridge can be found here: https://github.com/KhaosT/HAP-NodeJS and can be installed using the git clone command:
git clone https://github.com/KhaosT/HAP-NodeJS
The app configuration
Now that the server is running, let’s move on to the app. The demo app mentioned above is fairly simple to use. To link the app to the bridge simply click on add accessory and the bridge should be listed. Select the listed bridge and it will prompt for the code, the code can be found in the Bridge_Info.js (default is 031-45-154) file in the accessories folder. When that’s successful you will see the demo accessories.
You can now actually test Siri using the demo accessories!
Configuring the accessories
Nearly any smart/home automation accessory can be configured to work with this Homekit bridge. All you need to do is define an accessory file for each device. The accessory file defines the accessory and includes the actions possible, they are defined using object literal notification.
As I use Domoticz as my home automation platform, I’ve configured accessories based on that. I could have written a script that automatically grabs the devices from Domoticz and creates an accessory for each one, but I didn’t want to pollute my Homekit bridge with accessories which I won’t be controlling with Siri.
As most of my accessories will have common commands (e.g. Light on/off), I’ve created a shared class which will contain common actions.
Below is a snippet of the for Domoticz helper class (full class is here)
exports.switchAction = function (idx, action){ var post_options = { host: '192.168.0.7', port: '8089', path: '/json.htm?type=command¶m=switchlight&idx='+idx+'&switchcmd='+action, method: 'GET', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length } }; post(post_options); } exports.switchBrightness = function (idx, level){ //32 = 100% var dimlevel = level / 3.125; var post_options = { host: '192.168.0.7', port: '8089', path: '/json.htm?type=command¶m=switchlight&idx='+idx+'&switchcmd=Set%20Level&level='+dimlevel, method: 'GET', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': post_data.length } }; post(post_options); }
Once the helper class was created, I then create accessories for each of the devices I wanted to control. Click here for an example of the accessory definition. As Domoticz now supports Nest, I’ve also created a accessory for my Nest thermostat, which enables me to use Siri to change the temperature.
Once all the accessories (e.g. LightwaveRF swtiches and Nest etc..) are defined, if they will appear in the HomeKit app.
The accessories then can be assigned to Rooms, Zones and Trigger and Actions be created. By doing this you can tell Siri to turn on lights for particular rooms or zones.
Keeping the service running
To ensure that the HomeKit server is running all the time, I used a tool called Forever. Forever is a simple CLI tool for ensuring that a given script runs continuously.
Forever can be used using the following command:
forever start BridgedCore.js
Now you’re ready to use Siri to control your smart home…
Enjoy…