From 6e61287f59c414300583a5d6c800f433f8d36d67 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 3 Aug 2015 08:33:41 -0700 Subject: [PATCH 01/25] Use WIP version of HAP-NodeJS refactor --- accessories/WeMo.js | 2 +- app.js | 130 ++++++++++---------------------------------- package.json | 2 +- 3 files changed, 32 insertions(+), 102 deletions(-) diff --git a/accessories/WeMo.js b/accessories/WeMo.js index 0313878..273e4b3 100644 --- a/accessories/WeMo.js +++ b/accessories/WeMo.js @@ -68,7 +68,7 @@ WeMoAccessory.prototype = { if (!err) { var binaryState = parseInt(result) that.log("power state for " + that.wemoName + " is: " + binaryState) - callback(binaryState) + callback(binaryState > 0 ? 1 : 0); } else { that.log(err) diff --git a/app.js b/app.js index 7ed29d1..272bde7 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,10 @@ var fs = require('fs'); var path = require('path'); var storage = require('node-persist'); -var crypto = require('crypto'); +var uuid = require('HAP-NodeJS').uuid; +var Bridge = require('HAP-NodeJS').Bridge; +var Accessory = require('HAP-NodeJS').Accessory; +var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); @@ -15,23 +18,34 @@ if (!fs.existsSync(configPath)) { } // Initialize persistent storage -storage.initSync(); +//storage.initSync(); + +// Start by creating our Bridge which will host all loaded Accessories +var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); // Load up the configuration file var config = JSON.parse(fs.readFileSync(configPath)); -// Just to prevent them getting garbage collected -var accessories = []; +// keep track of async calls we're waiting for callbacks on before we can start up +var asyncCalls = 0; function startup() { - if (config.platforms) loadPlatforms(); +// if (config.platforms) loadPlatforms(); if (config.accessories) loadAccessories(); + + bridge.publish({ + username: "CC:22:3D:E3:CE:27", + port: 51826, + pincode: "031-45-154", + category: Accessory.Categories.OTHER + }); } function loadAccessories() { // Instantiate all accessories in the config console.log("Loading " + config.accessories.length + " accessories..."); + for (var i=0; i Date: Tue, 4 Aug 2015 09:24:35 -0700 Subject: [PATCH 02/25] Update HAP-NodeJS version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dcdeedb..1f8a536 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#aaa5770488d698d777e7d7706909c3afa888b031", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#4bf650d", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From f71730cff6925692af83ef662e15837f72af2965 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 15:48:52 -0700 Subject: [PATCH 03/25] Restore platform support --- app.js | 58 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/app.js b/app.js index 272bde7..f692477 100644 --- a/app.js +++ b/app.js @@ -18,7 +18,7 @@ if (!fs.existsSync(configPath)) { } // Initialize persistent storage -//storage.initSync(); +storage.initSync(); // Start by creating our Bridge which will host all loaded Accessories var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); @@ -27,18 +27,19 @@ var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); var config = JSON.parse(fs.readFileSync(configPath)); // keep track of async calls we're waiting for callbacks on before we can start up +// this is hacky but this is all going away once we build proper plugin support var asyncCalls = 0; +var asyncWait = false; function startup() { -// if (config.platforms) loadPlatforms(); + asyncWait = true; + if (config.platforms) loadPlatforms(); if (config.accessories) loadAccessories(); + asyncWait = false; - bridge.publish({ - username: "CC:22:3D:E3:CE:27", - port: 51826, - pincode: "031-45-154", - category: Accessory.Categories.OTHER - }); + // publish now unless we're waiting on anyone + if (asyncCalls == 0) + publish(); } function loadAccessories() { @@ -81,6 +82,7 @@ function loadAccessories() { function loadPlatforms() { console.log("Loading " + config.platforms.length + " platforms..."); + for (var i=0; i Date: Tue, 4 Aug 2015 15:49:50 -0700 Subject: [PATCH 04/25] Use latest refactor commit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f8a536..f3c80ce 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#4bf650d", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#a03e73b", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From c756ea9456805546bb70679fcd9c4fb8f31a7a16 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:00:52 -0700 Subject: [PATCH 05/25] HAP-NodeJS Bump for stable IDs --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f3c80ce..564c097 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#a03e73b", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#b1d5257", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From f7f953b8d121f8f535319e09536798ed3b635bf5 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:21:06 -0700 Subject: [PATCH 06/25] Fix name/log var corruption --- app.js | 59 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/app.js b/app.js index f692477..e2fe09d 100644 --- a/app.js +++ b/app.js @@ -100,34 +100,39 @@ function loadPlatforms() { var platformInstance = new platformConstructor(log, platformConfig); - // query for devices - asyncCalls++; - platformInstance.accessories(function(foundAccessories){ - asyncCalls--; - // loop through accessories adding them to the list and registering them - for (var i = 0; i < foundAccessories.length; i++) { - var accessoryInstance = foundAccessories[i]; - - log("Initializing device with name " + accessoryInstance.name + "...") - - // Extract the raw "services" for this accessory which is a big array of objects describing the various - // hooks in and out of HomeKit for the HAP-NodeJS server. - var services = accessoryInstance.getServices(); - - // Create the actual HAP-NodeJS "Accessory" instance - var accessory = accessoryLoader.parseAccessoryJSON({ - displayName: name, - services: services - }); + // wrap name and log in a closure so they don't change in the callback + function getAccessories(name, log) { + asyncCalls++; + platformInstance.accessories(function(foundAccessories){ + asyncCalls--; + // loop through accessories adding them to the list and registering them + for (var i = 0; i < foundAccessories.length; i++) { + var accessoryInstance = foundAccessories[i]; + + log("Initializing device with name " + accessoryInstance.name + "...") + + // Extract the raw "services" for this accessory which is a big array of objects describing the various + // hooks in and out of HomeKit for the HAP-NodeJS server. + var services = accessoryInstance.getServices(); + + // Create the actual HAP-NodeJS "Accessory" instance + var accessory = accessoryLoader.parseAccessoryJSON({ + displayName: name, + services: services + }); - // add it to the bridge - bridge.addBridgedAccessory(accessory); - } - - // were we the last callback? - if (asyncCalls === 0 && !asyncWait) - publish(); - }) + // add it to the bridge + bridge.addBridgedAccessory(accessory); + } + + // were we the last callback? + if (asyncCalls === 0 && !asyncWait) + publish(); + }) + } + + // query for devices + getAccessories(name, log); } } From c9aea1b7317ab5d14d57b9f0ebbf20ebadb812c2 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 16:44:34 -0700 Subject: [PATCH 07/25] Initialize HAP storage --- app.js | 5 +++-- package.json | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index e2fe09d..b24ad18 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,7 @@ var fs = require('fs'); var path = require('path'); var storage = require('node-persist'); +var hap = require('HAP-NodeJS'); var uuid = require('HAP-NodeJS').uuid; var Bridge = require('HAP-NodeJS').Bridge; var Accessory = require('HAP-NodeJS').Accessory; @@ -17,8 +18,8 @@ if (!fs.existsSync(configPath)) { process.exit(1); } -// Initialize persistent storage -storage.initSync(); +// Initialize HAP-NodeJS +hap.init(); // Start by creating our Bridge which will host all loaded Accessories var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); diff --git a/package.json b/package.json index 564c097..760cb6b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#b1d5257", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#96414ff", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9653a3173d109ee9ffc8231a86d2aabd7a50fb66 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Tue, 4 Aug 2015 20:32:05 -0700 Subject: [PATCH 08/25] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 760cb6b..7e14532 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#96414ff", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#efaf9d2", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 43c03464363c29de30e78b92282c2de4a730ad2c Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 5 Aug 2015 08:55:19 -0700 Subject: [PATCH 09/25] [Sonos] SUB isn't playable --- platforms/Sonos.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/Sonos.js b/platforms/Sonos.js index 15523c6..7ff0efc 100644 --- a/platforms/Sonos.js +++ b/platforms/Sonos.js @@ -17,7 +17,7 @@ SonosPlatform.prototype = { that.log("Found device at " + device.host); device.deviceDescription(function (err, description) { - if (description["zoneType"] != '11') { + if (description["zoneType"] != '11' && description["zoneType"] != '8') { // 8 is the Sonos SUB that.log("Found playable device - " + description["roomName"]); // device is an instance of sonos.Sonos var accessory = new SonosAccessory(that.log, that.config, device, description); From 6fff108ccd250ed3cc0814ca2ddcdb6b010fae6b Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 6 Aug 2015 09:58:03 -0700 Subject: [PATCH 10/25] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7e14532..8b106e5 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#efaf9d2", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3b1eaa8", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 3a819e202d354f4e4583aaf830b3dc2183bcef7d Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 13 Aug 2015 09:28:50 -0700 Subject: [PATCH 11/25] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8b106e5..21429ea 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3b1eaa8", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3cd0026", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From e1647d22ad8fe7ffae4252fe027c6be50cb16d1f Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 13 Aug 2015 10:10:55 -0700 Subject: [PATCH 12/25] Bump HAP-NodeJS with socket fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 21429ea..0ae84c6 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "ad2usb": "git+https://github.com/alistairg/node-ad2usb.git#local", "carwingsjs": "0.0.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#3cd0026", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#04b61c9", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9f0aaa53d6bc7b3d3b06116a4611ee8f7870a034 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 13:48:27 -0700 Subject: [PATCH 13/25] HAP bump for socket timeouts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9473049..79367f3 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#04b61c9", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#ea91d4b", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 867aec36d87c4161bf15ed7a1a1e20eb7ff76c3a Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 14:08:53 -0700 Subject: [PATCH 14/25] One more bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 79367f3..1fa4052 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#ea91d4b", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#5ec4bea", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 84c08d360cc64985d7baa03cbefa6a670a18ed48 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 16:23:09 -0700 Subject: [PATCH 15/25] Bump HAP with new types --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1fa4052..29eba99 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#5ec4bea", + "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#d337abf", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From bf3d7460898448633a8f72d54ed974118c8bb4a5 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 21:45:16 -0700 Subject: [PATCH 16/25] Use now-official refactored HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 29eba99..8db6503 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/nfarina/HAP-NodeJS#d337abf", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#b237a56de3299fba82b1c5d988a1ac665bc44a6a", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9c63ce5017704dcfdad176acdc76a40cca060e11 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 21:51:25 -0700 Subject: [PATCH 17/25] Allow bridge to be configured in config.json Fixes #104 --- app.js | 15 +++++++++------ config-sample.json | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app.js b/app.js index b24ad18..2d6307c 100644 --- a/app.js +++ b/app.js @@ -21,12 +21,15 @@ if (!fs.existsSync(configPath)) { // Initialize HAP-NodeJS hap.init(); -// Start by creating our Bridge which will host all loaded Accessories -var bridge = new Bridge('HomeBridge', uuid.generate("HomeBridge")); - // Load up the configuration file var config = JSON.parse(fs.readFileSync(configPath)); +// pull out our custom Bridge settings from config.json, if any +var bridgeConfig = config.bridge || {}; + +// Start by creating our Bridge which will host all loaded Accessories +var bridge = new Bridge(bridgeConfig.name || 'Homebridge', uuid.generate("HomeBridge")); + // keep track of async calls we're waiting for callbacks on before we can start up // this is hacky but this is all going away once we build proper plugin support var asyncCalls = 0; @@ -139,9 +142,9 @@ function loadPlatforms() { function publish() { bridge.publish({ - username: "CC:22:3D:E3:CE:27", - port: 51826, - pincode: "031-45-154", + username: bridgeConfig.username || "CC:22:3D:E3:CE:27", + port: bridgeConfig.port || 51826, + pincode: bridgeConfig.pin || "031-45-154", category: Accessory.Categories.OTHER }); } diff --git a/config-sample.json b/config-sample.json index a9477d0..952067a 100644 --- a/config-sample.json +++ b/config-sample.json @@ -1,4 +1,11 @@ { + "bridge": { + "name": "Homebridge", + "username": "CC:22:3D:E3:CE:27", + "port": 51826, + "pin": "031-45-154" + }, + "description": "This is an example configuration file with all supported devices. You can use this as a template for creating your own configuration file containing devices you actually own.", "platforms": [ From 5df7ffb40ecafcafe341c9fce92cfbb896dd4972 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Wed, 19 Aug 2015 22:05:08 -0700 Subject: [PATCH 18/25] README update; `npm run start` uses DEBUG --- README.md | 28 +++++++++++++--------------- package.json | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 762a03f..d75b54e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# HomeBridge +# Homebridge -HomeBridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It includes a set of "shims" (found in the [accessories](accessories/) and [platforms](platforms/) folders) that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of "smart home" devices. +Homebridge is a lightweight NodeJS server you can run on your home network that emulates the iOS HomeKit API. It includes a set of "shims" (found in the [accessories](accessories/) and [platforms](platforms/) folders) that provide a basic bridge from HomeKit to various 3rd-party APIs provided by manufacturers of "smart home" devices. -Since Siri supports devices added through HomeKit, this means that with HomeBridge you can ask Siri to control devices that don't have any support for HomeKit at all. For instance, using the included shims, you can say things like: +Since Siri supports devices added through HomeKit, this means that with Homebridge you can ask Siri to control devices that don't have any support for HomeKit at all. For instance, using the included shims, you can say things like: * _Siri, unlock the front door._ ([Lockitron](https://lockitron.com)) * _Siri, open the garage door._ ([LiftMaster MyQ](https://www.myliftmaster.com)) @@ -17,7 +17,7 @@ Since Siri supports devices added through HomeKit, this means that with HomeBrid If you would like to support any other devices, please write a shim and create a pull request and I'd be happy to add it to this official list. # Shim types -There are 2 types of shims supported in HomeBridge. +There are 2 types of shims supported in Homebridge. * Accessory - Individual device * Platform - A full bridge to another system @@ -28,9 +28,9 @@ Accessories are individual devices you would like to bridge to HomeKit. You set ## Platforms -Platforms bridge entire systems to HomeKit. Platforms can be things like Wink or SmartThings or Vera. By adding a platform to your `config.json`, HomeBridge will automatically detect all of your devices for you. +Platforms bridge entire systems to HomeKit. Platforms can be things like Wink or SmartThings or Vera. By adding a platform to your `config.json`, Homebridge will automatically detect all of your devices for you. -All you have to do is add the right config options so HomeBridge can authenticate and communicate with your other system, and voila, your devices will be available to HomeKit via HomeBridge. +All you have to do is add the right config options so Homebridge can authenticate and communicate with your other system, and voila, your devices will be available to HomeKit via Homebridge. # Why? @@ -38,7 +38,7 @@ Technically, the device manufacturers should be the ones implementing the HomeKi # Credit -HomeBridge itself is basically just a set of shims and a README. The actual HomeKit API work was done by [KhaosT](http://twitter.com/khaost) in his [HAP-NodeJS](https://github.com/KhaosT/HAP-NodeJS) project. Additionally, many of the shims benefit from amazing NodeJS projects out there like `sonos` and `wemo` that implement all the interesting functionality. +Homebridge itself is basically just a set of shims and a README. The actual HomeKit API work was done by [KhaosT](http://twitter.com/khaost) in his [HAP-NodeJS](https://github.com/KhaosT/HAP-NodeJS) project. Additionally, many of the shims benefit from amazing NodeJS projects out there like `sonos` and `wemo` that implement all the interesting functionality. # Before you Begin @@ -50,8 +50,6 @@ I would call this project a "novelty" in its current form, and is for **intrepid You'll also need some patience, as Siri can be very strict about sentence structure, and occasionally she will forget about HomeKit altogether. But it's not surprising that HomeKit isn't rock solid, since almost no one can actually use it today besides developers who are creating hardware accessories for it. There are, to my knowledge, exactly zero licensed HomeKit devices on the market right now, so Apple can easily get away with this all being a work in progress. -Additionally, the shims I've created implement the bare minimum of HomeKit needed to provide basic functionality like turning things off and on. I haven't written any kind of good feedback or error handling, and although they support changing state, they don't support reading the current state, so if you ask questions like "Is my door unlocked?" Siri will respond with the default of "Nope!" no matter what. - # Getting Started OK, if you're still excited enough about ordering Siri to make your coffee (which, who wouldn't be!) then here's how to set things up. First, clone this repo: @@ -66,7 +64,7 @@ Now you should be able to run the homebridge server: $ cd homebridge $ npm run start - Starting HomeBridge server... + Starting Homebridge server... Couldn't find a config.json file [snip] The server won't do anything until you've created a `config.json` file containing your home devices (or _accessories_ in HomeKit parlance) or platforms you wish to make available to iOS. You can start by copying and modifying the included `config-sample.json` file which includes declarations for all supported accessories and platforms. @@ -74,7 +72,7 @@ The server won't do anything until you've created a `config.json` file containin Once you've added your devices and/or platforms, you should be able to run the server again and see them initialize: $ npm run start - Starting HomeBridge server... + Starting Homebridge server... Loading 6 accessories... [Speakers] Initializing 'Sonos' accessory... [Coffee Maker] Initializing 'WeMo' accessory... @@ -94,18 +92,18 @@ Fortunately, there are now a few apps in the App Store that can manage your Home There are also some free apps that work OK. Try [Insteon+](https://itunes.apple.com/US/app/id919270334?mt=8) or [Lutron](https://itunes.apple.com/us/app/lutron-app-for-caseta-wireless/id886753021?mt=8) or a number of others. +If you are a member of the iOS developer program, I highly recommend Apple's [HomeKit Catalog](https://developer.apple.com/library/ios/samplecode/HomeKitCatalog/Introduction/Intro.html) app, as it is reliable and comprehensive and free (and open source). + ## Adding HomeKit Accessories -Once you've gotten a HomeKit app running on your iOS device, you can begin adding accessories. The app should "discover" the accessories defined in your `config.json` file, assuming that you're still running the HomeBridge server and you're on the same Wifi network. +Once you've gotten a HomeKit app running on your iOS device, you can use it to add your Homebridge devices. The app should "discover" the single accessory "Homebridge", assuming that you're still running the Homebridge server and you're on the same Wifi network. Adding this accessory will automatically add all accessories and platforms defined in `config.json`. -When you attempt to add a device, it will ask for a "PIN code". The default code for _all_ HomeBridge accessories is `031-45-154`. Adding the device should create some files in the `persist` directory of the HomeBridge server, which stores the pairing relationship. +When you attempt to add Homebridge, it will ask for a "PIN code". The default code is `031-45-154` (but this can be changed, see `config-sample.json`). This process will create some files in the `persist` directory of the Homebridge server, which stores the pairing relationship. # Interacting with your Devices Once your device has been added to HomeKit, you should be able to tell Siri to control your devices. However, realize that Siri is a cloud service, and iOS may need some time to synchronize your device information with iCloud. -Also, keep in mind HomeKit is not very robust yet, and it is common for it to fail intermittently ("Sorry, I wasn't able to control your devices" etc.) then start working again for no reason. Also I've noticed that it will get cranky and stop working altogether sometimes. The usual voodoo applies here: reboot your device, restart the homebridge server, run your HomeKit iOS app and poke around, etc. - One final thing to remember is that Siri will almost always prefer its default phrase handling over HomeKit devices. For instance, if you name your Sonos device "Radio" and try saying "Siri, turn on the Radio" then Siri will probably start playing an iTunes Radio station on your phone. Even if you name it "Sonos" and say "Siri, turn on the Sonos", Siri will probably just launch the Sonos app instead. This is why, for instance, the suggested `name` for the Sonos shim in `config-samples.json` is "Speakers". # Final Notes diff --git a/package.json b/package.json index 8db6503..cc9207e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "HomeKit support for the impatient", "version": "0.0.0", "scripts": { - "start": "node app.js" + "start": "DEBUG=* node app.js" }, "repository": { "type": "git", From 84fe474ccff3f67dc37ff0e24239f42260a168cc Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 20 Aug 2015 11:52:24 -0700 Subject: [PATCH 19/25] Add startup note about migration --- app.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.js b/app.js index 2d6307c..89118b0 100644 --- a/app.js +++ b/app.js @@ -9,6 +9,12 @@ var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); +console.log("====================================================================="); +console.log("IMPORTANT: Homebridge is in the middle of some big changes."); +console.log(" Read more about it here:"); +console.log(" https://github.com/nfarina/homebridge/wiki/Migration-Guide"); +console.log("====================================================================="); + // Look for the configuration file var configPath = path.join(__dirname, "config.json"); From b45318c3a398d46f91b6f5de80a274a027fae27c Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 20 Aug 2015 11:53:40 -0700 Subject: [PATCH 20/25] Change default bridge username --- app.js | 2 +- config-sample.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 89118b0..72ecef4 100644 --- a/app.js +++ b/app.js @@ -148,7 +148,7 @@ function loadPlatforms() { function publish() { bridge.publish({ - username: bridgeConfig.username || "CC:22:3D:E3:CE:27", + username: bridgeConfig.username || "CC:22:3D:E3:CE:30", port: bridgeConfig.port || 51826, pincode: bridgeConfig.pin || "031-45-154", category: Accessory.Categories.OTHER diff --git a/config-sample.json b/config-sample.json index 952067a..adfe40c 100644 --- a/config-sample.json +++ b/config-sample.json @@ -1,7 +1,7 @@ { "bridge": { "name": "Homebridge", - "username": "CC:22:3D:E3:CE:27", + "username": "CC:22:3D:E3:CE:30", "port": 51826, "pin": "031-45-154" }, From 5f1df2792fe0e051744285435e266175edb8545f Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 20 Aug 2015 21:25:29 -0700 Subject: [PATCH 21/25] Better error handling for config.json problems --- app.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 72ecef4..235f53e 100644 --- a/app.js +++ b/app.js @@ -9,11 +9,12 @@ var accessoryLoader = require('HAP-NodeJS').AccessoryLoader; console.log("Starting HomeBridge server..."); -console.log("====================================================================="); +console.log("_____________________________________________________________________"); console.log("IMPORTANT: Homebridge is in the middle of some big changes."); console.log(" Read more about it here:"); console.log(" https://github.com/nfarina/homebridge/wiki/Migration-Guide"); -console.log("====================================================================="); +console.log("_____________________________________________________________________"); +console.log(""); // Look for the configuration file var configPath = path.join(__dirname, "config.json"); @@ -28,7 +29,14 @@ if (!fs.existsSync(configPath)) { hap.init(); // Load up the configuration file -var config = JSON.parse(fs.readFileSync(configPath)); +var config; +try { + config = JSON.parse(fs.readFileSync(configPath)); +} +catch (err) { + console.log("There was a problem reading your config.json file:\n\n" + err.stack); + process.exit(0); +} // pull out our custom Bridge settings from config.json, if any var bridgeConfig = config.bridge || {}; From 64c665cebb3acd0beb2995e8a5e8450edc3d24a2 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 20 Aug 2015 21:38:29 -0700 Subject: [PATCH 22/25] Better error display for "npm run" and config.json --- app.js | 6 ++++-- package.json | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index 235f53e..f4423b3 100644 --- a/app.js +++ b/app.js @@ -34,8 +34,10 @@ try { config = JSON.parse(fs.readFileSync(configPath)); } catch (err) { - console.log("There was a problem reading your config.json file:\n\n" + err.stack); - process.exit(0); + console.log("There was a problem reading your config.json file."); + console.log("Please try pasting your config.json file here to validate it: http://jsonlint.com"); + console.log(""); + throw err; } // pull out our custom Bridge settings from config.json, if any diff --git a/package.json b/package.json index cc9207e..83159a1 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "HomeKit support for the impatient", "version": "0.0.0", "scripts": { - "start": "DEBUG=* node app.js" + "start": "DEBUG=* node app.js || true" }, "repository": { "type": "git", From 7b873bdf48b0b0c47668ff813766fcbd866b0046 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Fri, 21 Aug 2015 07:56:44 -0700 Subject: [PATCH 23/25] Bump HAP-NodeJS --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 83159a1..5fcd934 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#b237a56de3299fba82b1c5d988a1ac665bc44a6a", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#legacy-updatevalue", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4", From 9ebf41415cbe05da241bdb0d14d503ac9befdef7 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Sat, 22 Aug 2015 08:13:11 -0700 Subject: [PATCH 24/25] Version bump for npm --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fcd934..47cfe0e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.0.0", + "version": "0.1.0", "scripts": { "start": "DEBUG=* node app.js || true" }, From d2547f7ae6e106ab6185de1255f8467d83fcea24 Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Sat, 22 Aug 2015 08:51:20 -0700 Subject: [PATCH 25/25] Fix HAP-NodeJS version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 47cfe0e..2814343 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "homebridge", "description": "HomeKit support for the impatient", - "version": "0.1.0", + "version": "0.1.1", "scripts": { "start": "DEBUG=* node app.js || true" }, @@ -15,7 +15,7 @@ "carwingsjs": "0.0.x", "color": "0.10.x", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#legacy-updatevalue", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#187174846dc4b8970efba74b9eb2968b35f15d87", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "mdns": "^2.2.4",