From 983f1362715fc3064c3b3fe5882f2d085449c227 Mon Sep 17 00:00:00 2001 From: ilcato Date: Tue, 15 Sep 2015 13:57:21 +0200 Subject: [PATCH 01/30] Create FibaroHC2.js --- platforms/FibaroHC2.js | 445 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 445 insertions(+) create mode 100644 platforms/FibaroHC2.js diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js new file mode 100644 index 0000000..25e093f --- /dev/null +++ b/platforms/FibaroHC2.js @@ -0,0 +1,445 @@ +// Fibaro Home Center 2 Platform Shim for HomeBridge +// +// Remember to add platform to config.json. Example: +// "platforms": [ +// { + "platform": "FibaroHC2", + "name": "FibaroHC2", + "host": "PUT IP ADDRESS OF YOUR HC2 HERE", + "username": "PUT USERNAME OF YOUR HC2 HERE", + "password": "PUT PASSWORD OF YOUR HC2 HERE" +// } +// ], +// +// 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. + +var types = require("HAP-NodeJS/accessories/types.js"); +var request = require("request"); + +function FibaroHC2Platform(log, config){ + this.log = log; + this.host = config["host"]; + this.username = config["username"]; + this.password = config["password"]; + this.auth = "Basic " + new Buffer(this.username + ":" + this.password).toString("base64"); + this.url = "http://"+this.host+"/api/devices"; +} + +FibaroHC2Platform.prototype = { + accessories: function(callback) { + this.log("Fetching Fibaro Home Center devices..."); + + var that = this; + var foundAccessories = []; + + request.get({ + url: this.url, + headers : { + "Authorization" : this.auth + }, + json: true + }, function(err, response, json) { + if (!err && response.statusCode == 200) { + if (json != undefined) { + json.map(function(s) { + that.log("Found: " + s.type); + if (s.visible == true) { + if (s.type == "com.fibaro.multilevelSwitch") { + accessory = new FibaroDimmerAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } else if (s.type == "com.fibaro.FGRM222") + { + accessory = new FibaroRollerShutterAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } else if (s.type == "com.fibaro.binarySwitch" || s.type == "com.fibaro.developer.bxs.virtualBinarySwitch") + { + accessory = new FibaroBinarySwitchAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } else if (s.type == "com.fibaro.FGMS001") + { + accessory = new FibaroMotionSensorAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } else if (s.type == "com.fibaro.temperatureSensor") + { + accessory = new FibaroTemperatureSensorAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } else if (s.type == "com.fibaro.doorSensor") + { + accessory = new FibaroDoorSensorAccessory(that, s.name, s.id); + foundAccessories.push(accessory); + } + + } + }) + } + callback(foundAccessories); + } else { + that.log("There was a problem authenticating with FibaroHC2."); + } + }); + + }, + getAccessoryValue: function(callback, returnBoolean, that) { + var url = "http://"+that.platform.host+"/api/devices/"+that.id+"/properties/value"; + request.get({ + headers : { + "Authorization" : that.platform.auth + }, + json: true, + url: url + }, function(err, response, json) { + that.platform.log(url); + if (!err && response.statusCode == 200) { + if (returnBoolean) + callback(json.value == 0 ? 0 : 1); + else + callback(json.value); + } else { + that.platform.log("There was a problem getting value from" + that.id); + } + }) + }, + getAccessoryServices: function(that) { + var services = [{ + sType: types.ACCESSORY_INFORMATION_STYPE, + characteristics: this.informationCharacteristics(that), + }, + { + sType: that.SERVICE_TYPE, + characteristics: this.controlCharacteristics(that) + }]; + this.log("Loaded services for " + that.name) + return services; + }, + command: function(c,value, that) { + var url = "http://"+this.host+"/api/devices/"+that.id+"/action/"+c; + var body = value != undefined ? JSON.stringify({ + "args": [ + value + ] + }) : null; + var method = "post"; + request({ + url: url, + body: body, + method: method, + headers: { + "Authorization" : this.auth + }, + }, function(err, response) { + if (err) { + that.platform.log("There was a problem sending command " + c + " to" + that.name); + that.platform.log(url); + } else { + that.platform.log(that.name + " sent command " + c); + that.platform.log(url); + } + }); + }, + informationCharacteristics: function(that) + { + return [ + { + cType: types.NAME_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: that.name, + supportEvents: false, + supportBonjour: false, + manfDescription: "Name of the accessory", + designedMaxLength: 255 + },{ + cType: types.MANUFACTURER_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: "Fibaro", + supportEvents: false, + supportBonjour: false, + manfDescription: "Manufacturer", + designedMaxLength: 255 + },{ + cType: types.MODEL_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: that.MODEL_TYPE, + supportEvents: false, + supportBonjour: false, + manfDescription: "Model", + designedMaxLength: 255 + },{ + cType: types.SERIAL_NUMBER_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: "A1S2NASF88EW", + supportEvents: false, + supportBonjour: false, + manfDescription: "SN", + designedMaxLength: 255 + },{ + cType: types.IDENTIFY_CTYPE, + onUpdate: null, + perms: ["pw"], + format: "bool", + initialValue: false, + supportEvents: false, + supportBonjour: false, + manfDescription: "Identify Accessory", + designedMaxLength: 1 + } + ] + }, + controlCharacteristics: function(that) { + var cTypes = []; + var l = that.CONTROL_CHARACTERISTICS.length; + for (var i = 0; i < l; i++) { + if (that.CONTROL_CHARACTERISTICS[i] == types.NAME_CTYPE) { + cTypes.push({ + cType: types.NAME_CTYPE, + onUpdate: null, + perms: ["pr"], + format: "string", + initialValue: that.name, + supportEvents: true, + supportBonjour: false, + manfDescription: "Name of service", + designedMaxLength: 255 + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.POWER_STATE_CTYPE) { + cTypes.push({ + cType: types.POWER_STATE_CTYPE, + onUpdate: function(value) { + if (value == 0) { + that.platform.command("turnOff", null, that) + } else { + that.platform.command("turnOn", null, that) + } + }, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, true, that); + }, + perms: ["pw","pr","ev"], + format: "bool", + initialValue: 0, + supportEvents: true, + supportBonjour: false, + manfDescription: "Change the power state", + designedMaxLength: 1 + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.BRIGHTNESS_CTYPE) { + cTypes.push({ + cType: types.BRIGHTNESS_CTYPE, + onUpdate: function(value) { that.platform.command("setValue", value, that); }, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, false, that); + }, + perms: ["pw","pr","ev"], + format: "int", + initialValue: 0, + supportEvents: true, + supportBonjour: false, + manfDescription: "Adjust Brightness of Light", + designedMinValue: 0, + designedMaxValue: 100, + designedMinStep: 10, + unit: "%" + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_CURRENT_POSITION_CTYPE) { + cTypes.push({ + cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, false, that); + }, + perms: ["pr","ev"], + format: "int", + initialValue: 0, + supportEvents: false, + supportBonjour: false, + manfDescription: "Current Blind Position", + designedMinValue: 0, + designedMaxValue: 100, + designedMinStep: 1, + unit: "%" + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_TARGET_POSITION_CTYPE) { + cTypes.push({ + cType: types.WINDOW_COVERING_TARGET_POSITION_CTYPE, + onUpdate: function(value) { that.platform.command("setValue", value, that); }, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, false, that); + }, + perms: ["pw","pr","ev"], + format: "int", + initialValue: 0, + supportEvents: false, + supportBonjour: false, + manfDescription: "Target Blind Position", + designedMinValue: 0, + designedMaxValue: 100, + designedMinStep: 1, + unit: "%" + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_OPERATION_STATE_CTYPE) { + cTypes.push({ + cType: types.WINDOW_COVERING_OPERATION_STATE_CTYPE, + perms: ["pr","ev"], + format: "int", + initialValue: 0, + supportEvents: false, + supportBonjour: false, + manfDescription: "Position State", + designedMinValue: 0, + designedMaxValue: 2, + designedMinStep: 1, + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.CURRENT_TEMPERATURE_CTYPE) { + cTypes.push({ + cType: types.CURRENT_TEMPERATURE_CTYPE, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, false, that); + }, + perms: ["pr","ev"], + format: "float", + unit: "celsius", + stepValue: 0.1, + initialValue: 0, + supportEvents: true, + supportBonjour: false, + manfDescription: "Get current temperature" + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.MOTION_DETECTED_CTYPE) { + cTypes.push({ + cType: types.MOTION_DETECTED_CTYPE, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, true, that); + }, + perms: ["pr","ev"], + format: "bool", + initialValue: 0, + supportEvents: true, + supportBonjour: false, + manfDescription: "Detect motion", + designedMaxLength: 1 + }); + } else if (that.CONTROL_CHARACTERISTICS[i] == types.CONTACT_SENSOR_STATE_CTYPE) { + cTypes.push({ + cType: types.CONTACT_SENSOR_STATE_CTYPE, + onRead: function(callback) { + that.platform.getAccessoryValue(callback, true, that); + }, + perms: ["pr","ev"], + format: "bool", + initialValue: 0, + supportEvents: true, + supportBonjour: false, + manfDescription: "Detect door contact", + designedMaxLength: 1 + }); + } + } + return cTypes + } +} + +function FibaroDimmerAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Dimmer"; + this.SERVICE_TYPE = types.LIGHTBULB_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.POWER_STATE_CTYPE, types.BRIGHTNESS_CTYPE]; +} + +FibaroDimmerAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +function FibaroRollerShutterAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Roller Shutter 2"; + this.SERVICE_TYPE = types.WINDOW_COVERING_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, types.WINDOW_COVERING_TARGET_POSITION_CTYPE, types.WINDOW_COVERING_OPERATION_STATE_CTYPE]; + +} + +FibaroRollerShutterAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +function FibaroBinarySwitchAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Binary Switch"; + this.SERVICE_TYPE = types.SWITCH_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.POWER_STATE_CTYPE]; +} + +FibaroBinarySwitchAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +function FibaroTemperatureSensorAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Temperature Sensor"; + this.SERVICE_TYPE = types.TEMPERATURE_SENSOR_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.CURRENT_TEMPERATURE_CTYPE]; +} + +FibaroTemperatureSensorAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +function FibaroMotionSensorAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Motion Sensor"; + this.SERVICE_TYPE = types.MOTION_SENSOR_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.MOTION_DETECTED_CTYPE]; +} + +FibaroMotionSensorAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +function FibaroDoorSensorAccessory(platform, name, id) { + // device info + this.platform = platform; + this.name = name; + this.id = id; + this.MODEL_TYPE = "Door Sensor"; + this.SERVICE_TYPE = types.CONTACT_SENSOR_STYPE; + this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.CONTACT_SENSOR_STATE_CTYPE]; +} + +FibaroDoorSensorAccessory.prototype = { + getServices: function() { + return this.platform.getAccessoryServices(this); + } +}; + +module.exports.platform = FibaroHC2Platform; From d36827f92de51ab86b6b5656730a9a0f4c310732 Mon Sep 17 00:00:00 2001 From: ilcato Date: Tue, 15 Sep 2015 14:26:42 +0200 Subject: [PATCH 02/30] Fixed comments --- platforms/FibaroHC2.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index 25e093f..14dbdd2 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -3,11 +3,11 @@ // Remember to add platform to config.json. Example: // "platforms": [ // { - "platform": "FibaroHC2", - "name": "FibaroHC2", - "host": "PUT IP ADDRESS OF YOUR HC2 HERE", - "username": "PUT USERNAME OF YOUR HC2 HERE", - "password": "PUT PASSWORD OF YOUR HC2 HERE" +// "platform": "FibaroHC2", +// "name": "FibaroHC2", +// "host": "PUT IP ADDRESS OF YOUR HC2 HERE", +// "username": "PUT USERNAME OF YOUR HC2 HERE", +// "password": "PUT PASSWORD OF YOUR HC2 HERE" // } // ], // From a041407104f3670a9081d8649014fd7132bd04a2 Mon Sep 17 00:00:00 2001 From: ilcato Date: Tue, 15 Sep 2015 19:03:08 +0200 Subject: [PATCH 03/30] Added automatic status update through event mechanism --- platforms/FibaroHC2.js | 99 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 7 deletions(-) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index 14dbdd2..6eef466 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -18,12 +18,14 @@ var types = require("HAP-NodeJS/accessories/types.js"); var request = require("request"); function FibaroHC2Platform(log, config){ - this.log = log; - this.host = config["host"]; - this.username = config["username"]; - this.password = config["password"]; - this.auth = "Basic " + new Buffer(this.username + ":" + this.password).toString("base64"); - this.url = "http://"+this.host+"/api/devices"; + this.log = log; + this.host = config["host"]; + this.username = config["username"]; + this.password = config["password"]; + this.auth = "Basic " + new Buffer(this.username + ":" + this.password).toString("base64"); + this.url = "http://"+this.host+"/api/devices"; + + startPollingUpdate( this ); } FibaroHC2Platform.prototype = { @@ -75,7 +77,7 @@ FibaroHC2Platform.prototype = { } callback(foundAccessories); } else { - that.log("There was a problem authenticating with FibaroHC2."); + that.log("There was a problem connecting with FibaroHC2."); } }); @@ -212,6 +214,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.POWER_STATE_CTYPE) { cTypes.push({ cType: types.POWER_STATE_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, true); + }, onUpdate: function(value) { if (value == 0) { that.platform.command("turnOff", null, that) @@ -233,6 +239,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.BRIGHTNESS_CTYPE) { cTypes.push({ cType: types.BRIGHTNESS_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, false); + }, onUpdate: function(value) { that.platform.command("setValue", value, that); }, onRead: function(callback) { that.platform.getAccessoryValue(callback, false, that); @@ -251,6 +261,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_CURRENT_POSITION_CTYPE) { cTypes.push({ cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, false); + }, onRead: function(callback) { that.platform.getAccessoryValue(callback, false, that); }, @@ -268,6 +282,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_TARGET_POSITION_CTYPE) { cTypes.push({ cType: types.WINDOW_COVERING_TARGET_POSITION_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, false); + }, onUpdate: function(value) { that.platform.command("setValue", value, that); }, onRead: function(callback) { that.platform.getAccessoryValue(callback, false, that); @@ -299,6 +317,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.CURRENT_TEMPERATURE_CTYPE) { cTypes.push({ cType: types.CURRENT_TEMPERATURE_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, false); + }, onRead: function(callback) { that.platform.getAccessoryValue(callback, false, that); }, @@ -314,6 +336,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.MOTION_DETECTED_CTYPE) { cTypes.push({ cType: types.MOTION_DETECTED_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, true); + }, onRead: function(callback) { that.platform.getAccessoryValue(callback, true, that); }, @@ -328,6 +354,10 @@ FibaroHC2Platform.prototype = { } else if (that.CONTROL_CHARACTERISTICS[i] == types.CONTACT_SENSOR_STATE_CTYPE) { cTypes.push({ cType: types.CONTACT_SENSOR_STATE_CTYPE, + onRegister: function(characteristic) { + characteristic.eventEnabled = true; + subscribeUpdate(characteristic, that, true); + }, onRead: function(callback) { that.platform.getAccessoryValue(callback, true, that); }, @@ -441,5 +471,60 @@ FibaroDoorSensorAccessory.prototype = { return this.platform.getAccessoryServices(this); } }; +var lastPoll=0; +var pollingUpdateRunning = false; + +function startPollingUpdate( platform ) +{ + if( pollingUpdateRunning ) + return; + pollingUpdateRunning = true; + + var updateUrl = "http://"+platform.host+"/api/refreshStates?last="+lastPoll; + + request.get({ + url: updateUrl, + headers : { + "Authorization" : platform.auth + }, + json: true + }, function(err, response, json) { + if (!err && response.statusCode == 200) { + if (json != undefined) { + lastPoll = json.last; + if (json.changes != undefined) { + json.changes.map(function(s) { + if (s.value != undefined) { + + var value=parseInt(s.value); + if (isNaN(value)) + value=(s.value === "true"); + for (i=0;i Date: Wed, 16 Sep 2015 21:56:09 +0200 Subject: [PATCH 04/30] Fixed status update --- platforms/FibaroHC2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index 6eef466..a1336d5 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -115,6 +115,11 @@ FibaroHC2Platform.prototype = { return services; }, command: function(c,value, that) { + if (that.doNotSet != undefined && that.doNotSet == true) { + that.doNotSet = false; + return; + } + var url = "http://"+this.host+"/api/devices/"+that.id+"/action/"+c; var body = value != undefined ? JSON.stringify({ "args": [ @@ -502,6 +507,7 @@ function startPollingUpdate( platform ) for (i=0;i Date: Fri, 18 Sep 2015 09:37:10 +0200 Subject: [PATCH 05/30] Cleanup KNX file names and markdown I found that the description was wrongly named and in the wrong folder. It is now named after the platform shim to appear next to it in listings, also the config-sample that comes along with it. As long as we do not go for own repositories and npm packages, should we consider folders for additional files if required? --- ...ig-sample-knx.json => KNX-sample-config.json} | 0 accessories/knxdevice.md => platforms/KNX.md | 16 ++++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) rename platforms/{config-sample-knx.json => KNX-sample-config.json} (100%) rename accessories/knxdevice.md => platforms/KNX.md (85%) diff --git a/platforms/config-sample-knx.json b/platforms/KNX-sample-config.json similarity index 100% rename from platforms/config-sample-knx.json rename to platforms/KNX-sample-config.json diff --git a/accessories/knxdevice.md b/platforms/KNX.md similarity index 85% rename from accessories/knxdevice.md rename to platforms/KNX.md index c9131cc..77dfe4d 100644 --- a/accessories/knxdevice.md +++ b/platforms/KNX.md @@ -1,7 +1,7 @@ # Syntax of the config.json In the platforms section, you can insert a KNX type platform. You need to configure all devices directly in the config.json. - +````json "platforms": [ { "platform": "KNX", @@ -33,8 +33,9 @@ You need to configure all devices directly in the config.json. ] } } - +```` In the accessories section (the array within the brackets [ ]) you can insert as many objects as you like in the following form +````json { "accessory_type": "knxdevice", "name": "Here goes your display name, this will be shown in HomeKit apps", @@ -43,8 +44,9 @@ In the accessories section (the array within the brackets [ ]) you can insert as } ] } - +```` You have to add services in the following syntax: +````json { "type": "SERVICENAME", "description": "This is just for you to remember things", @@ -62,9 +64,11 @@ You have to add services in the following syntax: ] } } -CHARACTERISTIC are properties that are dependent on the service type, so they are listed below. -Two kinds of addresses are supported: "Set":"1/2/3" is a writable group address, to which changes are sent if the service supports changing values. Changes on the bus are listened to, too. -"Listen":["1/2/3","1/2/4","1/2/5"] is an array of addresses that are listened to additionally. To these addresses never values get written, but the on startup the service will issue read requests to ALL addresses listed in Set: and in Listen: +```` +`CHARACTERISTICx` are properties that are dependent on the service type, so they are listed below. + +Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group address, to which changes are sent if the service supports changing values. Changes on the bus are listened to, too. +`"Listen":["1/2/3","1/2/4","1/2/5"]` is an array of addresses that are listened to additionally. To these addresses never values get written, but the on startup the service will issue *KNX read requests* to ALL addresses listed in `Set:` and in `Listen:` # Supported Services and their characteristics From 76a5fd3b7f4f0fef556d84c24de833e89710767f Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 18 Sep 2015 09:40:38 +0200 Subject: [PATCH 06/30] markdown \ test --- platforms/KNX.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/KNX.md b/platforms/KNX.md index 77dfe4d..f46cf98 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -74,7 +74,7 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres # Supported Services and their characteristics ## Lightbulb - On: DPT 1, 1 as on, 0 as off + On: DPT 1, 1 as on, 0 as off
Brightness: DPT5 percentage, 100% (=255) the brightest From 24a8dcb8cc08be0412903057d8272b4e4fc8d03a Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 18 Sep 2015 09:45:08 +0200 Subject: [PATCH 07/30] more markdown formatting --- platforms/KNX.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/platforms/KNX.md b/platforms/KNX.md index f46cf98..dbfd23c 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -74,17 +74,18 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres # Supported Services and their characteristics ## Lightbulb - On: DPT 1, 1 as on, 0 as off
- Brightness: DPT5 percentage, 100% (=255) the brightest + - On: DPT 1, 1 as on, 0 as off + - Brightness: DPT5 percentage, 100% (=255) the brightest ## LockMechanism -LockCurrentState: DPT 1, 1 as secured +- LockCurrentState: DPT 1, 1 as secured OR (but not both:) -LockCurrentStateSecured0: DPT 1, 0 as secured +- LockCurrentStateSecured0: DPT 1, 0 as secured -LockTargetState: DPT 1, 1 as secured -LockTargetStateSecured0: DPT 1, 0 as secured +- LockTargetState: DPT 1, 1 as secured +OR +- LockTargetStateSecured0: DPT 1, 0 as secured ## Thermostat CurrentTemperature: DPT9 in °C [listen only] From f802d845092007246934e23c1df0d19885fa1081 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 18 Sep 2015 09:47:52 +0200 Subject: [PATCH 08/30] Even more markdown formatting --- platforms/KNX.md | 53 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/platforms/KNX.md b/platforms/KNX.md index dbfd23c..22b3aee 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -79,51 +79,48 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres ## LockMechanism -- LockCurrentState: DPT 1, 1 as secured -OR (but not both:) +- LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** - LockCurrentStateSecured0: DPT 1, 0 as secured -- LockTargetState: DPT 1, 1 as secured -OR +- LockTargetState: DPT 1, 1 as secured **OR** - LockTargetStateSecured0: DPT 1, 0 as secured ## Thermostat -CurrentTemperature: DPT9 in °C [listen only] -TargetTemperature: DPT9, values 0..40°C only, all others are ignored -CurrentHeatingCoolingState: DPT5 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] -TargetHeatingCoolingState: as above +- CurrentTemperature: DPT9 in °C [listen only] +- TargetTemperature: DPT9, values 0..40°C only, all others are ignored +- CurrentHeatingCoolingState: DPT5 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] +- TargetHeatingCoolingState: as above ## TemperatureSensor -CurrentTemperature: DPT9 in °C [listen only] +- CurrentTemperature: DPT9 in °C [listen only] ## Window -CurrentPosition: DPT5 percentage -TargetPosition: DPT5 percentage -PositionState: DPT5 value [listen only] +- CurrentPosition: DPT5 percentage +- TargetPosition: DPT5 percentage +- PositionState: DPT5 value [listen only] ## WindowCovering -CurrentPosition: DPT5 percentage -TargetPosition: DPT5 percentage -PositionState: DPT5 value [listen only] +- CurrentPosition: DPT5 percentage +- TargetPosition: DPT5 percentage +- PositionState: DPT5 value [listen only] ### not yet supported -HoldPosition -TargetHorizontalTiltAngle -TargetVerticalTiltAngle -CurrentHorizontalTiltAngle -CurrentVerticalTiltAngle -ObstructionDetected +- HoldPosition +- TargetHorizontalTiltAngle +- TargetVerticalTiltAngle +- CurrentHorizontalTiltAngle +- CurrentVerticalTiltAngle +- ObstructionDetected ## ContactSensor -ContactSensorState: DPT 1, 0 as contact -OR -ContactSensorStateContact1: DPT 1, 1 as contact +- ContactSensorState: DPT 1, 0 as contact **OR** +- ContactSensorStateContact1: DPT 1, 1 as contact -StatusActive: DPT 1, 1 as true -StatusFault: DPT 1, 1 as true -StatusTampered: DPT 1, 1 as true -StatusLowBattery: DPT 1, 1 as true +- StatusActive: DPT 1, 1 as true +- StatusFault: DPT 1, 1 as true +- StatusTampered: DPT 1, 1 as true +- StatusLowBattery: DPT 1, 1 as true # DISCLAIMER From 93ea0dedede1e5576e304b8ce8c34477c4d724a1 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 18 Sep 2015 10:28:31 +0200 Subject: [PATCH 09/30] Cleanup and new devices Added services: - Switch - Outlet --- accessories/knxdevice.js | 347 +++++++++++++++++++-------------------- platforms/KNX.md | 44 ++--- 2 files changed, 193 insertions(+), 198 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 824b9dd..b554b9a 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -1,13 +1,16 @@ -/* +/** * This is a KNX universal accessory shim. * This is NOT the version for dynamic installation * New 2015-09-16: Welcome iOS9.0 -new features includ: -services: -Window -WindowCovering -ContactSensor +new features include: +- services: +- Window +- WindowCovering +- ContactSensor +New 2015-0918: +- Services Switch and Outlet +- Code cleanup * */ var Service = require("HAP-NodeJS").Service; @@ -102,7 +105,6 @@ KNXDevice.prototype = { }.bind(this)); }.bind(this)); }, - // issues an all purpose read request on the knx bus // DOES NOT WAIT for an answer. Please register the address with a callback using registerGA() function knxread: function(groupAddress){ @@ -132,7 +134,6 @@ KNXDevice.prototype = { }.bind(this)); }.bind(this)); }, - // issuing multiple read requests at once knxreadarray: function (groupAddresses) { if (groupAddresses.constructor.toString().indexOf("Array") > -1) { @@ -147,7 +148,9 @@ KNXDevice.prototype = { this.knxread (groupAddresses); } }, - +/** Write special type routines + * + */ // special types knxwrite_percent: function(callback, groupAddress, value) { var numericValue = 0; @@ -159,10 +162,9 @@ KNXDevice.prototype = { } this.knxwrite(callback, groupAddress,'DPT5',numericValue); }, - - - // need to spit registers into types - +/** Registering routines + * + */ // boolean: get 0 or 1 from the bus, write boolean knxregister_bool: function(addresses, characteristic) { this.log("knx registering BOOLEAN " + addresses); @@ -201,7 +203,6 @@ KNXDevice.prototype = { } }.bind(this)); }, - // float knxregister_float: function(addresses, characteristic) { this.log("knx registering FLOAT " + addresses); @@ -216,8 +217,6 @@ KNXDevice.prototype = { }.bind(this)); }, - - // what about HVAC heating cooling types? knxregister_HVAC: function(addresses, characteristic) { this.log("knx registering HVAC " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ @@ -245,7 +244,7 @@ KNXDevice.prototype = { characteristic.setValue(HAPvalue, undefined, 'fromKNXBus'); }.bind(this)); }, - // to do! KNX: DPT 20.102 = One Byte like DPT5 + /** KNX HVAC (heating, ventilation, and air conditioning) types do not really match to homekit types: // 0 = Auto // 1 = Comfort // 2 = Standby @@ -257,8 +256,8 @@ KNXDevice.prototype = { // Characteristic.TargetHeatingCoolingState.HEAT = 1; // Characteristic.TargetHeatingCoolingState.COOL = 2; // Characteristic.TargetHeatingCoolingState.AUTO = 3; - - + AUTO (3) is not allowed as return type from devices! +*/ // undefined, has to match! knxregister: function(addresses, characteristic) { this.log("knx registering " + addresses); @@ -268,14 +267,14 @@ KNXDevice.prototype = { }.bind(this)); }, - /* - * set methods used for creating callbacks, such as - * var Characteristic = myService.addCharacteristic(new Characteristic.Brightness()) - * .on('set', function(value, callback, context) { - * this.setPercentage(value, callback, context, this.config[index].Set) - * }.bind(this)); - * - */ +/** set methods used for creating callbacks + * such as + * var Characteristic = myService.addCharacteristic(new Characteristic.Brightness()) + * .on('set', function(value, callback, context) { + * this.setPercentage(value, callback, context, this.config[index].Set) + * }.bind(this)); + * + */ setBooleanState: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { this.log(gaddress + " event ping pong, exit!"); @@ -308,7 +307,6 @@ KNXDevice.prototype = { } }, - setPercentage: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { this.log("event ping pong, exit!"); @@ -324,7 +322,6 @@ KNXDevice.prototype = { this.knxwrite(callback, gaddress,'DPT5',numericValue); } }, - setFloat: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { this.log(gaddress + " event ping pong, exit!"); @@ -340,7 +337,6 @@ KNXDevice.prototype = { this.knxwrite(callback, gaddress,'DPT9',numericValue); } }, - setHVACState: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { this.log(gaddress + " event ping pong, exit!"); @@ -371,21 +367,16 @@ KNXDevice.prototype = { } }, - - +/** identify dummy + * + */ identify: function(callback) { this.log("Identify requested!"); callback(); // success }, - - - /* - * function getXXXXXXXService(config) - * - * returns a configured service object to the caller (accessory/device) - * - */ - +/** bindCharacteristic + * initializes callbacks for 'set' events (from HK) and for KNX bus reads (to HK) + */ bindCharacteristic: function(myService, characteristicType, valueType, config) { var myCharacteristic = myService.getCharacteristic(characteristicType); if (myCharacteristic === undefined) { @@ -453,7 +444,60 @@ KNXDevice.prototype = { } return myCharacteristic; // for chaining or whatsoever }, - +/** + * function getXXXXXXXService(config) + * returns a configured service object to the caller (accessory/device) + * + * @param config + * pass a configuration array parsed from config.json + * specifically for this service + * + */ + getContactSenserService: function(config) { +// Characteristic.ContactSensorState.CONTACT_DETECTED = 0; +// Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1; + + // some sanity checks + if (config.type !== "ContactSensor") { + this.log("[ERROR] ContactSensor Service for non 'ContactSensor' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] ContactSensor Service without 'name' property called"); + return undefined; + } + + var myService = new Service.ContactSensor(config.name,config.name); + if (config.ContactSensorState) { + this.log("ContactSensor ContactSensorState characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.ContactSensorState); + } else if (config.ContactSensorStateContact1) { + this.log("ContactSensor ContactSensorStateContact1 characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.ContactSensorState, "BoolReverse", config.ContactSensorStateContact1); + } + //optionals + if (config.StatusActive) { + this.log("ContactSensor StatusActive characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusActive); + this.bindCharacteristic(myService, Characteristic.StatusActive, "Bool", config.StatusActive); + } + if (config.StatusFault) { + this.log("ContactSensor StatusFault characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusFault); + this.bindCharacteristic(myService, Characteristic.StatusFault, "Bool", config.StatusFault); + } + if (config.StatusTampered) { + this.log("ContactSensor StatusTampered characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusTampered); + this.bindCharacteristic(myService, Characteristic.StatusTampered, "Bool", config.StatusTampered); + } + if (config.StatusLowBattery) { + this.log("ContactSensor StatusLowBattery characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusLowBattery); + this.bindCharacteristic(myService, Characteristic.StatusLowBattery, "Bool", config.StatusLowBattery); + } + return myService; + }, getLightbulbService: function(config) { // some sanity checks //this.config = config; @@ -482,13 +526,13 @@ KNXDevice.prototype = { //iterate(myService); return myService; }, - getLockMechanismService: function(config) { - // some sanity checks - //this.config = config; + +/** //this.config = config; // Characteristic.LockCurrentState.UNSECURED = 0; // Characteristic.LockCurrentState.SECURED = 1; - +*/ + // some sanity checks if (config.type !== "LockMechanism") { this.log("[ERROR] LockMechanism Service for non 'LockMechanism' service called"); return undefined; @@ -497,6 +541,7 @@ KNXDevice.prototype = { this.log("[ERROR] LockMechanism Service without 'name' property called"); return undefined; } + var myService = new Service.LockMechanism(config.name,config.name); // LockCurrentState if (config.LockCurrentState) { @@ -520,28 +565,61 @@ KNXDevice.prototype = { //iterate(myService); return myService; }, - + getOutletService: function(config) { + /** + * this.addCharacteristic(Characteristic.On); + * this.addCharacteristic(Characteristic.OutletInUse); + */ + // some sanity checks + if (config.type !== "Outlet") { + this.log("[ERROR] Outlet Service for non 'Outlet' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] Outlet Service without 'name' property called"); + return undefined; + } + var myService = new Service.Outlet(config.name,config.name); + // On (and Off) + if (config.On) { + this.log("Outlet on/off characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.On, "Bool", config.On); + } // OutletInUse characteristic + if (config.OutletInUse) { + this.log("Outlet on/off characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.OutletInUse, "Bool", config.OutletInUse); + } + return myService; + }, + getSwitchService: function(config) { + // some sanity checks + if (config.type !== "Switch") { + this.log("[ERROR] Switch Service for non 'Switch' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] Switch Service without 'name' property called"); + return undefined; + } + var myService = new Service.Switch(config.name,config.name); + // On (and Off) + if (config.On) { + this.log("Switch on/off characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.On, "Bool", config.On); + } // On characteristic + return myService; + }, getThermostatService: function(config) { - - -// // Required Characteristics -// this.addCharacteristic(Characteristic.CurrentHeatingCoolingState); -// this.addCharacteristic(Characteristic.TargetHeatingCoolingState); -// this.addCharacteristic(Characteristic.CurrentTemperature); //check -// this.addCharacteristic(Characteristic.TargetTemperature); // -// this.addCharacteristic(Characteristic.TemperatureDisplayUnits); - // -// // Optional Characteristics -// this.addOptionalCharacteristic(Characteristic.CurrentRelativeHumidity); -// this.addOptionalCharacteristic(Characteristic.TargetRelativeHumidity); -// this.addOptionalCharacteristic(Characteristic.CoolingThresholdTemperature); -// this.addOptionalCharacteristic(Characteristic.HeatingThresholdTemperature); - +/** + // Optional Characteristics + this.addOptionalCharacteristic(Characteristic.CurrentRelativeHumidity); + this.addOptionalCharacteristic(Characteristic.TargetRelativeHumidity); + this.addOptionalCharacteristic(Characteristic.CoolingThresholdTemperature); + this.addOptionalCharacteristic(Characteristic.HeatingThresholdTemperature); +*/ // some sanity checks - - if (config.type !== "Thermostat") { this.log("[ERROR] Thermostat Service for non 'Thermostat' service called"); return undefined; @@ -550,6 +628,7 @@ KNXDevice.prototype = { this.log("[ERROR] Thermostat Service without 'name' property called"); return undefined; } + var myService = new Service.Thermostat(config.name,config.name); // CurrentTemperature) if (config.CurrentTemperature) { @@ -581,15 +660,9 @@ KNXDevice.prototype = { } return myService; }, - - // temperature sensor type (iOS9 assumed) getTemperatureSensorService: function(config) { - - // some sanity checks - - if (config.type !== "TemperatureSensor") { this.log("[ERROR] TemperatureSensor Service for non 'TemperatureSensor' service called"); return undefined; @@ -606,28 +679,18 @@ KNXDevice.prototype = { } return myService; }, - - - - // window type (iOS9 assumed) getWindowService: function(config) { -// Service.Window = function(displayName, subtype) { -// Service.call(this, displayName, '0000008B-0000-1000-8000-0026BB765291', subtype); -// -// // Required Characteristics -// this.addCharacteristic(Characteristic.CurrentPosition); -// this.addCharacteristic(Characteristic.TargetPosition); -// this.addCharacteristic(Characteristic.PositionState); -// -// // Optional Characteristics -// this.addOptionalCharacteristic(Characteristic.HoldPosition); -// this.addOptionalCharacteristic(Characteristic.ObstructionDetected); -// this.addOptionalCharacteristic(Characteristic.Name); - - // Characteristic.PositionState.DECREASING = 0; -// Characteristic.PositionState.INCREASING = 1; -// Characteristic.PositionState.STOPPED = 2; - +/** + Optional Characteristics + this.addOptionalCharacteristic(Characteristic.HoldPosition); + this.addOptionalCharacteristic(Characteristic.ObstructionDetected); + this.addOptionalCharacteristic(Characteristic.Name); + + PositionState values: The KNX blind actuators I have return only MOVING=1 and STOPPED=0 + Characteristic.PositionState.DECREASING = 0; + Characteristic.PositionState.INCREASING = 1; + Characteristic.PositionState.STOPPED = 2; +*/ // some sanity checks @@ -656,34 +719,17 @@ KNXDevice.prototype = { } return myService; }, - - -// /** -// * Service "Window Covering" -// */ -// -// Service.WindowCovering = function(displayName, subtype) { -// Service.call(this, displayName, '0000008C-0000-1000-8000-0026BB765291', subtype); -// -// // Required Characteristics -// this.addCharacteristic(Characteristic.CurrentPosition); -// this.addCharacteristic(Characteristic.TargetPosition); -// this.addCharacteristic(Characteristic.PositionState); -// -// // Optional Characteristics -// this.addOptionalCharacteristic(Characteristic.HoldPosition); -// this.addOptionalCharacteristic(Characteristic.TargetHorizontalTiltAngle); -// this.addOptionalCharacteristic(Characteristic.TargetVerticalTiltAngle); -// this.addOptionalCharacteristic(Characteristic.CurrentHorizontalTiltAngle); -// this.addOptionalCharacteristic(Characteristic.CurrentVerticalTiltAngle); -// this.addOptionalCharacteristic(Characteristic.ObstructionDetected); -// this.addOptionalCharacteristic(Characteristic.Name); -// }; getWindowCoveringService: function(config) { - + /** + // Optional Characteristics + this.addOptionalCharacteristic(Characteristic.HoldPosition); + this.addOptionalCharacteristic(Characteristic.TargetHorizontalTiltAngle); + this.addOptionalCharacteristic(Characteristic.TargetVerticalTiltAngle); + this.addOptionalCharacteristic(Characteristic.CurrentHorizontalTiltAngle); + this.addOptionalCharacteristic(Characteristic.CurrentVerticalTiltAngle); + this.addOptionalCharacteristic(Characteristic.ObstructionDetected); + */ // some sanity checks - - if (config.type !== "WindowCovering") { this.log("[ERROR] WindowCovering Service for non 'WindowCovering' service called"); return undefined; @@ -692,8 +738,8 @@ KNXDevice.prototype = { this.log("[ERROR] WindowCovering Service without 'name' property called"); return undefined; } - var myService = new Service.WindowCovering(config.name,config.name); + var myService = new Service.WindowCovering(config.name,config.name); if (config.CurrentPosition) { this.log("WindowCovering CurrentPosition characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.CurrentPosition); @@ -709,64 +755,6 @@ KNXDevice.prototype = { return myService; }, -// Service.ContactSensor = function(displayName, subtype) { -// Service.call(this, displayName, '00000080-0000-1000-8000-0026BB765291', subtype); -// -// // Required Characteristics -// this.addCharacteristic(Characteristic.ContactSensorState); -// -// // Optional Characteristics -// this.addOptionalCharacteristic(Characteristic.StatusActive); -// this.addOptionalCharacteristic(Characteristic.StatusFault); -// this.addOptionalCharacteristic(Characteristic.StatusTampered); -// this.addOptionalCharacteristic(Characteristic.StatusLowBattery); -// this.addOptionalCharacteristic(Characteristic.Name); -// }; -// Characteristic.ContactSensorState.CONTACT_DETECTED = 0; -// Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1; - getContactSenserService: function(config) { - // some sanity checks - if (config.type !== "ContactSensor") { - this.log("[ERROR] ContactSensor Service for non 'ContactSensor' service called"); - return undefined; - } - if (!config.name) { - this.log("[ERROR] ContactSensor Service without 'name' property called"); - return undefined; - } - var myService = new Service.ContactSensor(config.name,config.name); - - if (config.ContactSensorState) { - this.log("ContactSensor ContactSensorState characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.ContactSensorState); - } else if (config.ContactSensorStateContact1) { - this.log("ContactSensor ContactSensorStateContact1 characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.ContactSensorState, "BoolReverse", config.ContactSensorStateContact1); - } - //optionals - if (config.StatusActive) { - this.log("ContactSensor StatusActive characteristic enabled"); - myService.addCharacteristic(Characteristic.StatusActive); - this.bindCharacteristic(myService, Characteristic.StatusActive, "Bool", config.StatusActive); - } - if (config.StatusFault) { - this.log("ContactSensor StatusFault characteristic enabled"); - myService.addCharacteristic(Characteristic.StatusFault); - this.bindCharacteristic(myService, Characteristic.StatusFault, "Bool", config.StatusFault); - } - if (config.StatusTampered) { - this.log("ContactSensor StatusTampered characteristic enabled"); - myService.addCharacteristic(Characteristic.StatusTampered); - this.bindCharacteristic(myService, Characteristic.StatusTampered, "Bool", config.StatusTampered); - } - if (config.StatusLowBattery) { - this.log("ContactSensor StatusLowBattery characteristic enabled"); - myService.addCharacteristic(Characteristic.StatusLowBattery); - this.bindCharacteristic(myService, Characteristic.StatusLowBattery, "Bool", config.StatusLowBattery); - } - return myService; - }, - /* assemble the device ***************************************************************************************************/ @@ -788,8 +776,8 @@ KNXDevice.prototype = { accessoryServices.push(informationService); - iterate(this.config); -// throw new Error("STOP"); + //iterate(this.config); + if (!this.config.services){ this.log("No services found in accessory?!") } @@ -814,6 +802,9 @@ KNXDevice.prototype = { case "LockMechanism": accessoryServices.push(this.getLockMechanismService(configService)); break; + case "Switch": + accessoryServices.push(this.getSwitchService(configService)); + break; case "TemperatureSensor": accessoryServices.push(this.getTemperatureSensorService(configService)); break; diff --git a/platforms/KNX.md b/platforms/KNX.md index 22b3aee..6512835 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -19,19 +19,16 @@ You need to configure all devices directly in the config.json. "name": "Living Room North Lamp", "On": { "Set": "1/1/6", - "Listen": [ - "1/1/63" - ] + "Listen": ["1/1/63"] }, "Brightness": { "Set": "1/1/62", - "Listen": [ - "1/1/64" - ] + "Listen": ["1/1/64"] } } ] } + ] } ```` In the accessories section (the array within the brackets [ ]) you can insert as many objects as you like in the following form @@ -73,28 +70,42 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres # Supported Services and their characteristics +## ContactSensor +- ContactSensorState: DPT 1, 0 as contact **OR** +- ContactSensorStateContact1: DPT 1, 1 as contact + +- StatusActive: DPT 1, 1 as true +- StatusFault: DPT 1, 1 as true +- StatusTampered: DPT 1, 1 as true +- StatusLowBattery: DPT 1, 1 as true ## Lightbulb - On: DPT 1, 1 as on, 0 as off - Brightness: DPT5 percentage, 100% (=255) the brightest ## LockMechanism -- LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** +- LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** - LockCurrentStateSecured0: DPT 1, 0 as secured -- LockTargetState: DPT 1, 1 as secured **OR** +- LockTargetState: DPT 1, 1 as secured **OR** - LockTargetStateSecured0: DPT 1, 0 as secured +## Outlet + - On: DPT 1, 1 as on, 0 as off + - OutletInUse: DPT 1, 1 as on, 0 as off + +## Switch + - On: DPT 1, 1 as on, 0 as off + +## TemperatureSensor +- CurrentTemperature: DPT9 in °C [listen only] + ## Thermostat - CurrentTemperature: DPT9 in °C [listen only] - TargetTemperature: DPT9, values 0..40°C only, all others are ignored - CurrentHeatingCoolingState: DPT5 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] - TargetHeatingCoolingState: as above - -## TemperatureSensor -- CurrentTemperature: DPT9 in °C [listen only] - ## Window - CurrentPosition: DPT5 percentage - TargetPosition: DPT5 percentage @@ -113,16 +124,9 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres - CurrentVerticalTiltAngle - ObstructionDetected -## ContactSensor -- ContactSensorState: DPT 1, 0 as contact **OR** -- ContactSensorStateContact1: DPT 1, 1 as contact -- StatusActive: DPT 1, 1 as true -- StatusFault: DPT 1, 1 as true -- StatusTampered: DPT 1, 1 as true -- StatusLowBattery: DPT 1, 1 as true # DISCLAIMER -This is work in progress! +**This is work in progress!** From 91f6ccb2d4ea2d21902e0a144c8046ba77880f45 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 18 Sep 2015 13:18:27 +0200 Subject: [PATCH 10/30] Added LightSensor Service --- accessories/knxdevice.js | 27 ++++++++++++++++++++++++--- platforms/KNX.md | 6 ++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index b554b9a..db93fd4 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -526,6 +526,25 @@ KNXDevice.prototype = { //iterate(myService); return myService; }, + getLightSensorService: function(config) { + + // some sanity checks + if (config.type !== "LightSensor") { + this.log("[ERROR] LightSensor Service for non 'LightSensor' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] LightSensor Service without 'name' property called"); + return undefined; + } + var myService = new Service.LightSensor(config.name,config.name); + // CurrentTemperature) + if (config.CurrentAmbientLightLevel) { + this.log("LightSensor CurrentAmbientLightLevel characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.CurrentAmbientLightLevel, "Float", config.CurrentAmbientLightLevel); + } + return myService; + }, getLockMechanismService: function(config) { /** //this.config = config; @@ -756,10 +775,9 @@ KNXDevice.prototype = { }, + - /* assemble the device ***************************************************************************************************/ - - +/* assemble the device ***************************************************************************************************/ getServices: function() { // you can OPTIONALLY create an information service if you wish to override @@ -799,6 +817,9 @@ KNXDevice.prototype = { case "Lightbulb": accessoryServices.push(this.getLightbulbService(configService)); break; + case "LightSensor": + accessoryServices.push(this.getLightSensorService(configService)); + break; case "LockMechanism": accessoryServices.push(this.getLockMechanismService(configService)); break; diff --git a/platforms/KNX.md b/platforms/KNX.md index 6512835..937af45 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -78,15 +78,17 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres - StatusFault: DPT 1, 1 as true - StatusTampered: DPT 1, 1 as true - StatusLowBattery: DPT 1, 1 as true + ## Lightbulb - On: DPT 1, 1 as on, 0 as off - Brightness: DPT5 percentage, 100% (=255) the brightest - + +## LightSensor +- CurrentAmbientLightLevel: DPT 9, 0 to 100000 Lux ## LockMechanism - LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** - LockCurrentStateSecured0: DPT 1, 0 as secured - - LockTargetState: DPT 1, 1 as secured **OR** - LockTargetStateSecured0: DPT 1, 0 as secured From 32877abc98fbd124cffb88083883faaa31b9b028 Mon Sep 17 00:00:00 2001 From: ilcato Date: Fri, 18 Sep 2015 17:33:36 +0200 Subject: [PATCH 11/30] Complete refactoring and adoption of new API Added support for LightSensor --- platforms/FibaroHC2.js | 540 ++++++++++++----------------------------- 1 file changed, 157 insertions(+), 383 deletions(-) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index a1336d5..c3e92e8 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -15,6 +15,8 @@ // The default code for all HomeBridge accessories is 031-45-154. var types = require("HAP-NodeJS/accessories/types.js"); +var Service = require("HAP-NodeJS").Service; +var Characteristic = require("HAP-NodeJS").Characteristic; var request = require("request"); function FibaroHC2Platform(log, config){ @@ -47,31 +49,27 @@ FibaroHC2Platform.prototype = { json.map(function(s) { that.log("Found: " + s.type); if (s.visible == true) { - if (s.type == "com.fibaro.multilevelSwitch") { - accessory = new FibaroDimmerAccessory(that, s.name, s.id); + var accessory = null; + if (s.type == "com.fibaro.multilevelSwitch") + accessory = new FibaroDimmerAccessory(that, s); + else if (s.type == "com.fibaro.FGRM222" || s.type == "com.fibaro.FGR221") + accessory = new FibaroRollerShutterAccessory(that, s); + else if (s.type == "com.fibaro.binarySwitch" || s.type == "com.fibaro.developer.bxs.virtualBinarySwitch") + accessory = new FibaroBinarySwitchAccessory(that, s); + else if (s.type == "com.fibaro.FGMS001" || s.type == "com.fibaro.motionSensor") + accessory = new FibaroMotionSensorAccessory(that, s); + else if (s.type == "com.fibaro.temperatureSensor") + accessory = new FibaroTemperatureSensorAccessory(that, s); + else if (s.type == "com.fibaro.doorSensor") + accessory = new FibaroDoorSensorAccessory(that, s); + else if (s.type == "com.fibaro.lightSensor") + accessory = new FibaroLightSensorAccessory(that, s); + if (accessory != null) { + accessory.getServices = function() { + return that.getServices(accessory); + }; foundAccessories.push(accessory); - } else if (s.type == "com.fibaro.FGRM222") - { - accessory = new FibaroRollerShutterAccessory(that, s.name, s.id); - foundAccessories.push(accessory); - } else if (s.type == "com.fibaro.binarySwitch" || s.type == "com.fibaro.developer.bxs.virtualBinarySwitch") - { - accessory = new FibaroBinarySwitchAccessory(that, s.name, s.id); - foundAccessories.push(accessory); - } else if (s.type == "com.fibaro.FGMS001") - { - accessory = new FibaroMotionSensorAccessory(that, s.name, s.id); - foundAccessories.push(accessory); - } else if (s.type == "com.fibaro.temperatureSensor") - { - accessory = new FibaroTemperatureSensorAccessory(that, s.name, s.id); - foundAccessories.push(accessory); - } else if (s.type == "com.fibaro.doorSensor") - { - accessory = new FibaroDoorSensorAccessory(that, s.name, s.id); - foundAccessories.push(accessory); - } - + } } }) } @@ -82,49 +80,10 @@ FibaroHC2Platform.prototype = { }); }, - getAccessoryValue: function(callback, returnBoolean, that) { - var url = "http://"+that.platform.host+"/api/devices/"+that.id+"/properties/value"; - request.get({ - headers : { - "Authorization" : that.platform.auth - }, - json: true, - url: url - }, function(err, response, json) { - that.platform.log(url); - if (!err && response.statusCode == 200) { - if (returnBoolean) - callback(json.value == 0 ? 0 : 1); - else - callback(json.value); - } else { - that.platform.log("There was a problem getting value from" + that.id); - } - }) - }, - getAccessoryServices: function(that) { - var services = [{ - sType: types.ACCESSORY_INFORMATION_STYPE, - characteristics: this.informationCharacteristics(that), - }, - { - sType: that.SERVICE_TYPE, - characteristics: this.controlCharacteristics(that) - }]; - this.log("Loaded services for " + that.name) - return services; - }, command: function(c,value, that) { - if (that.doNotSet != undefined && that.doNotSet == true) { - that.doNotSet = false; - return; - } - var url = "http://"+this.host+"/api/devices/"+that.id+"/action/"+c; var body = value != undefined ? JSON.stringify({ - "args": [ - value - ] + "args": [ value ] }) : null; var method = "post"; request({ @@ -144,338 +103,153 @@ FibaroHC2Platform.prototype = { } }); }, - informationCharacteristics: function(that) - { - return [ - { - cType: types.NAME_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: that.name, - supportEvents: false, - supportBonjour: false, - manfDescription: "Name of the accessory", - designedMaxLength: 255 - },{ - cType: types.MANUFACTURER_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: "Fibaro", - supportEvents: false, - supportBonjour: false, - manfDescription: "Manufacturer", - designedMaxLength: 255 - },{ - cType: types.MODEL_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: that.MODEL_TYPE, - supportEvents: false, - supportBonjour: false, - manfDescription: "Model", - designedMaxLength: 255 - },{ - cType: types.SERIAL_NUMBER_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: "A1S2NASF88EW", - supportEvents: false, - supportBonjour: false, - manfDescription: "SN", - designedMaxLength: 255 - },{ - cType: types.IDENTIFY_CTYPE, - onUpdate: null, - perms: ["pw"], - format: "bool", - initialValue: false, - supportEvents: false, - supportBonjour: false, - manfDescription: "Identify Accessory", - designedMaxLength: 1 + getAccessoryValue: function(callback, returnBoolean, that) { + var url = "http://"+that.platform.host+"/api/devices/"+that.id+"/properties/value"; + request.get({ + headers : { + "Authorization" : that.platform.auth + }, + json: true, + url: url + }, function(err, response, json) { + that.platform.log(url); + if (!err && response.statusCode == 200) { + if (returnBoolean) + callback(undefined, json.value == 0 ? 0 : 1); + else + callback(undefined, json.value); + } else { + that.platform.log("There was a problem getting value from" + that.id); } - ] + }) }, - controlCharacteristics: function(that) { - var cTypes = []; - var l = that.CONTROL_CHARACTERISTICS.length; - for (var i = 0; i < l; i++) { - if (that.CONTROL_CHARACTERISTICS[i] == types.NAME_CTYPE) { - cTypes.push({ - cType: types.NAME_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: that.name, - supportEvents: true, - supportBonjour: false, - manfDescription: "Name of service", - designedMaxLength: 255 - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.POWER_STATE_CTYPE) { - cTypes.push({ - cType: types.POWER_STATE_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, true); - }, - onUpdate: function(value) { - if (value == 0) { - that.platform.command("turnOff", null, that) - } else { - that.platform.command("turnOn", null, that) - } - }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, true, that); - }, - perms: ["pw","pr","ev"], - format: "bool", - initialValue: 0, - supportEvents: true, - supportBonjour: false, - manfDescription: "Change the power state", - designedMaxLength: 1 - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.BRIGHTNESS_CTYPE) { - cTypes.push({ - cType: types.BRIGHTNESS_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, false); - }, - onUpdate: function(value) { that.platform.command("setValue", value, that); }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, false, that); - }, - perms: ["pw","pr","ev"], - format: "int", - initialValue: 0, - supportEvents: true, - supportBonjour: false, - manfDescription: "Adjust Brightness of Light", - designedMinValue: 0, - designedMaxValue: 100, - designedMinStep: 10, - unit: "%" - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_CURRENT_POSITION_CTYPE) { - cTypes.push({ - cType: types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, false); - }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, false, that); - }, - perms: ["pr","ev"], - format: "int", - initialValue: 0, - supportEvents: false, - supportBonjour: false, - manfDescription: "Current Blind Position", - designedMinValue: 0, - designedMaxValue: 100, - designedMinStep: 1, - unit: "%" - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_TARGET_POSITION_CTYPE) { - cTypes.push({ - cType: types.WINDOW_COVERING_TARGET_POSITION_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, false); - }, - onUpdate: function(value) { that.platform.command("setValue", value, that); }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, false, that); - }, - perms: ["pw","pr","ev"], - format: "int", - initialValue: 0, - supportEvents: false, - supportBonjour: false, - manfDescription: "Target Blind Position", - designedMinValue: 0, - designedMaxValue: 100, - designedMinStep: 1, - unit: "%" - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.WINDOW_COVERING_OPERATION_STATE_CTYPE) { - cTypes.push({ - cType: types.WINDOW_COVERING_OPERATION_STATE_CTYPE, - perms: ["pr","ev"], - format: "int", - initialValue: 0, - supportEvents: false, - supportBonjour: false, - manfDescription: "Position State", - designedMinValue: 0, - designedMaxValue: 2, - designedMinStep: 1, - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.CURRENT_TEMPERATURE_CTYPE) { - cTypes.push({ - cType: types.CURRENT_TEMPERATURE_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, false); - }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, false, that); - }, - perms: ["pr","ev"], - format: "float", - unit: "celsius", - stepValue: 0.1, - initialValue: 0, - supportEvents: true, - supportBonjour: false, - manfDescription: "Get current temperature" - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.MOTION_DETECTED_CTYPE) { - cTypes.push({ - cType: types.MOTION_DETECTED_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, true); - }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, true, that); - }, - perms: ["pr","ev"], - format: "bool", - initialValue: 0, - supportEvents: true, - supportBonjour: false, - manfDescription: "Detect motion", - designedMaxLength: 1 - }); - } else if (that.CONTROL_CHARACTERISTICS[i] == types.CONTACT_SENSOR_STATE_CTYPE) { - cTypes.push({ - cType: types.CONTACT_SENSOR_STATE_CTYPE, - onRegister: function(characteristic) { - characteristic.eventEnabled = true; - subscribeUpdate(characteristic, that, true); - }, - onRead: function(callback) { - that.platform.getAccessoryValue(callback, true, that); - }, - perms: ["pr","ev"], - format: "bool", - initialValue: 0, - supportEvents: true, - supportBonjour: false, - manfDescription: "Detect door contact", - designedMaxLength: 1 - }); - } - } - return cTypes - } + getInformationService: function(homebridgeAccessory) { + var informationService = new Service.AccessoryInformation(); + informationService + .setCharacteristic(Characteristic.Name, homebridgeAccessory.name) + .setCharacteristic(Characteristic.Manufacturer, homebridgeAccessory.manufacturer) + .setCharacteristic(Characteristic.Model, homebridgeAccessory.model) + .setCharacteristic(Characteristic.SerialNumber, homebridgeAccessory.serialNumber); + return informationService; + }, + bindCharacteristicEvents: function(characteristic, homebridgeAccessory) { + var onOff = characteristic.format == "bool" ? true : false; + var readOnly = characteristic.writable == undefined || characteristic.writable == false ? true : false; + subscribeUpdate(characteristic, homebridgeAccessory, onOff); + if (!readOnly) { + characteristic + .on('set', function(value, callback, context) { + if( context !== 'fromFibaro' ) { + if (onOff) + homebridgeAccessory.platform.command(value == 0 ? "turnOff": "turnOn", null, homebridgeAccessory); + else + homebridgeAccessory.platform.command("setValue", value, homebridgeAccessory); + } + callback(); + }.bind(this) ); + } + characteristic + .on('get', function(callback) { + homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory); + }.bind(this) ); + }, + getServices: function(homebridgeAccessory) { + var informationService = homebridgeAccessory.platform.getInformationService(homebridgeAccessory); + for (var i=0; i < homebridgeAccessory.characteristics.length; i++) { + var characteristic = homebridgeAccessory.controlService.getCharacteristic(homebridgeAccessory.characteristics[i]); + if (characteristic == undefined) + characteristic = homebridgeAccessory.controlService.addCharacteristic(homebridgeAccessory.characteristics[i]); + homebridgeAccessory.platform.bindCharacteristicEvents(characteristic, homebridgeAccessory); + } + + return [informationService, homebridgeAccessory.controlService]; + } } -function FibaroDimmerAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Dimmer"; - this.SERVICE_TYPE = types.LIGHTBULB_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.POWER_STATE_CTYPE, types.BRIGHTNESS_CTYPE]; +function FibaroDimmerAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.Lightbulb(this.name); + this.characteristics = [Characteristic.On, Characteristic.Brightness]; } -FibaroDimmerAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; - -function FibaroRollerShutterAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Roller Shutter 2"; - this.SERVICE_TYPE = types.WINDOW_COVERING_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.WINDOW_COVERING_CURRENT_POSITION_CTYPE, types.WINDOW_COVERING_TARGET_POSITION_CTYPE, types.WINDOW_COVERING_OPERATION_STATE_CTYPE]; - +function FibaroRollerShutterAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.WindowCovering(this.name); + this.characteristics = [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState]; } -FibaroRollerShutterAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; - -function FibaroBinarySwitchAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Binary Switch"; - this.SERVICE_TYPE = types.SWITCH_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.POWER_STATE_CTYPE]; +function FibaroBinarySwitchAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.Switch(this.name); + this.characteristics = [Characteristic.On]; } -FibaroBinarySwitchAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; - -function FibaroTemperatureSensorAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Temperature Sensor"; - this.SERVICE_TYPE = types.TEMPERATURE_SENSOR_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.CURRENT_TEMPERATURE_CTYPE]; +function FibaroMotionSensorAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = "Motion Sensor"; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.MotionSensor(this.name); + this.characteristics = [Characteristic.MotionDetected]; } -FibaroTemperatureSensorAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; - -function FibaroMotionSensorAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Motion Sensor"; - this.SERVICE_TYPE = types.MOTION_SENSOR_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.MOTION_DETECTED_CTYPE]; +function FibaroTemperatureSensorAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.TemperatureSensor(this.name); + this.characteristics = [Characteristic.CurrentTemperature]; } -FibaroMotionSensorAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; - -function FibaroDoorSensorAccessory(platform, name, id) { - // device info - this.platform = platform; - this.name = name; - this.id = id; - this.MODEL_TYPE = "Door Sensor"; - this.SERVICE_TYPE = types.CONTACT_SENSOR_STYPE; - this.CONTROL_CHARACTERISTICS = [types.NAME_CTYPE, types.CONTACT_SENSOR_STATE_CTYPE]; +function FibaroDoorSensorAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.ContactSensor(this.name); + this.characteristics = [Characteristic.ContactSensorState]; +} + +function FibaroLightSensorAccessory(platform, s) { + this.platform = platform; + this.remoteAccessory = s; + this.id = s.id; + this.name = s.name; + this.model = s.type; + this.manufacturer = "Fibaro"; + this.serialNumber = ""; + this.controlService = new Service.LightSensor(this.name); + this.characteristics = [Characteristic.CurrentAmbientLightLevel]; } -FibaroDoorSensorAccessory.prototype = { - getServices: function() { - return this.platform.getAccessoryServices(this); - } -}; var lastPoll=0; var pollingUpdateRunning = false; @@ -507,11 +281,10 @@ function startPollingUpdate( platform ) for (i=0;i Date: Sat, 19 Sep 2015 10:12:35 +0200 Subject: [PATCH 12/30] Added support for Fibaro Outlet --- platforms/FibaroHC2.js | 94 ++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 59 deletions(-) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index c3e92e8..c18d0dd 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -64,10 +64,20 @@ FibaroHC2Platform.prototype = { accessory = new FibaroDoorSensorAccessory(that, s); else if (s.type == "com.fibaro.lightSensor") accessory = new FibaroLightSensorAccessory(that, s); + else if (s.type == "com.fibaro.FGWP101") + accessory = new FibaroOutletAccessory(that, s); + if (accessory != null) { accessory.getServices = function() { return that.getServices(accessory); }; + accessory.platform = that; + accessory.remoteAccessory = s; + accessory.id = s.id; + accessory.name = s.name; + accessory.model = s.type; + accessory.manufacturer = "Fibaro"; + accessory.serialNumber = ""; foundAccessories.push(accessory); } } @@ -103,23 +113,30 @@ FibaroHC2Platform.prototype = { } }); }, - getAccessoryValue: function(callback, returnBoolean, that) { - var url = "http://"+that.platform.host+"/api/devices/"+that.id+"/properties/value"; + getAccessoryValue: function(callback, returnBoolean, homebridgeAccessory, powerValue) { + var url = "http://"+homebridgeAccessory.platform.host+"/api/devices/"+homebridgeAccessory.id+"/properties/"; + if (powerValue) + url = url + "power"; + else + url = url + "value"; + request.get({ headers : { - "Authorization" : that.platform.auth + "Authorization" : homebridgeAccessory.platform.auth }, json: true, url: url }, function(err, response, json) { - that.platform.log(url); + homebridgeAccessory.platform.log(url); if (!err && response.statusCode == 200) { - if (returnBoolean) + if (powerValue) { + callback(undefined, parseFloat(json.value) > 1.0 ? true : false); + } else if (returnBoolean) callback(undefined, json.value == 0 ? 0 : 1); else callback(undefined, json.value); } else { - that.platform.log("There was a problem getting value from" + that.id); + homebridgeAccessory.platform.log("There was a problem getting value from" + homebridgeAccessory.id); } }) }, @@ -135,6 +152,7 @@ FibaroHC2Platform.prototype = { bindCharacteristicEvents: function(characteristic, homebridgeAccessory) { var onOff = characteristic.format == "bool" ? true : false; var readOnly = characteristic.writable == undefined || characteristic.writable == false ? true : false; + var powerValue = (characteristic.UUID == "00000026-0000-1000-8000-0026BB765291") ? true : false; subscribeUpdate(characteristic, homebridgeAccessory, onOff); if (!readOnly) { characteristic @@ -150,7 +168,7 @@ FibaroHC2Platform.prototype = { } characteristic .on('get', function(callback) { - homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory); + homebridgeAccessory.platform.getAccessoryValue(callback, onOff, homebridgeAccessory, powerValue); }.bind(this) ); }, getServices: function(homebridgeAccessory) { @@ -167,89 +185,45 @@ FibaroHC2Platform.prototype = { } function FibaroDimmerAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.Lightbulb(this.name); this.characteristics = [Characteristic.On, Characteristic.Brightness]; } function FibaroRollerShutterAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.WindowCovering(this.name); this.characteristics = [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState]; } function FibaroBinarySwitchAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.Switch(this.name); this.characteristics = [Characteristic.On]; } function FibaroMotionSensorAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = "Motion Sensor"; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.MotionSensor(this.name); this.characteristics = [Characteristic.MotionDetected]; } function FibaroTemperatureSensorAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.TemperatureSensor(this.name); this.characteristics = [Characteristic.CurrentTemperature]; } function FibaroDoorSensorAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.ContactSensor(this.name); this.characteristics = [Characteristic.ContactSensorState]; } function FibaroLightSensorAccessory(platform, s) { - this.platform = platform; - this.remoteAccessory = s; - this.id = s.id; - this.name = s.name; - this.model = s.type; - this.manufacturer = "Fibaro"; - this.serialNumber = ""; this.controlService = new Service.LightSensor(this.name); this.characteristics = [Characteristic.CurrentAmbientLightLevel]; } +function FibaroOutletAccessory(platform, s) { + this.controlService = new Service.Outlet(this.name); + this.characteristics = [Characteristic.On, Characteristic.OutletInUse]; +} + var lastPoll=0; var pollingUpdateRunning = false; @@ -281,10 +255,12 @@ function startPollingUpdate( platform ) for (i=0;i 1.0 ? true : false, undefined, 'fromFibaro'); + } else if ((subscription.onOff && typeof(value) == "boolean") || !subscription.onOff) + subscription.characteristic.setValue(value, undefined, 'fromFibaro'); else - subscription.characteristic.setValue(value == 0 ? false : true, undefined, 'fromFibaro'); + subscription.characteristic.setValue(value == 0 ? false : true, undefined, 'fromFibaro'); } } } From 387e7ec9cebd750aa9dcbd4a06178d5edb64b85d Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Sat, 19 Sep 2015 15:19:11 +0200 Subject: [PATCH 13/30] KNX support for Garage Door Opener The garage door opener device MUST adhere to HomeKit numeric conventions, see KNX.md documentation --- accessories/knxdevice.js | 90 +++++++++++++++++++++++++++++++++++++--- platforms/KNX.md | 71 +++++++++++++++++++++---------- 2 files changed, 134 insertions(+), 27 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index db93fd4..f94f5b2 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -322,6 +322,21 @@ KNXDevice.prototype = { this.knxwrite(callback, gaddress,'DPT5',numericValue); } }, + setInt: function(value, callback, context, gaddress) { + if (context === 'fromKNXBus') { + this.log("event ping pong, exit!"); + if (callback) { + callback(); + } + } else { + var numericValue = 0; + if (value && value>=0 && value<=255) { + numericValue = value; // assure 1..255 for KNX bus + } + this.log("Setting "+gaddress+" int to %s (%s)", value, numericValue); + this.knxwrite(callback, gaddress,'DPT5',numericValue); + } + }, setFloat: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { this.log(gaddress + " event ping pong, exit!"); @@ -406,6 +421,11 @@ KNXDevice.prototype = { this.setFloat(value, callback, context, config.Set); }.bind(this)); break; + case "Int": + myCharacteristic.on('set', function(value, callback, context) { + this.setInt(value, callback, context, config.Set); + }.bind(this)); + break; case "HVAC": myCharacteristic.on('set', function(value, callback, context) { this.setHVACState(value, callback, context, config.Set); @@ -432,6 +452,10 @@ KNXDevice.prototype = { case "Float": this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic); break; + case "Int": + // use float as return type for ints, for we don't care + this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic); + break; case "HVAC": this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic); break; @@ -498,6 +522,62 @@ KNXDevice.prototype = { } return myService; }, + getGarageDoorOpenerService: function(config) { +// // Required Characteristics +// this.addCharacteristic(Characteristic.CurrentDoorState); +// this.addCharacteristic(Characteristic.TargetDoorState); +// this.addCharacteristic(Characteristic.ObstructionDetected); +// Characteristic.CurrentDoorState.OPEN = 0; +// Characteristic.CurrentDoorState.CLOSED = 1; +// Characteristic.CurrentDoorState.OPENING = 2; +// Characteristic.CurrentDoorState.CLOSING = 3; +// Characteristic.CurrentDoorState.STOPPED = 4; +// // +// // Optional Characteristics +// this.addOptionalCharacteristic(Characteristic.LockCurrentState); +// this.addOptionalCharacteristic(Characteristic.LockTargetState); + // The value property of LockCurrentState must be one of the following: +// Characteristic.LockCurrentState.UNSECURED = 0; +// Characteristic.LockCurrentState.SECURED = 1; +// Characteristic.LockCurrentState.JAMMED = 2; +// Characteristic.LockCurrentState.UNKNOWN = 3; + + // some sanity checks + if (config.type !== "GarageDoorOpener") { + this.log("[ERROR] GarageDoorOpener Service for non 'GarageDoorOpener' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] GarageDoorOpener Service without 'name' property called"); + return undefined; + } + + var myService = new Service.GarageDoorOpener(config.name,config.name); + if (config.CurrentDoorState) { + this.log("GarageDoorOpener CurrentDoorState characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.CurrentDoorState, "Int", config.CurrentDoorState); + } + if (config.TargetDoorState) { + this.log("GarageDoorOpener TargetDoorState characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.TargetDoorState, "Int", config.TargetDoorState); + } + if (config.ObstructionDetected) { + this.log("GarageDoorOpener ObstructionDetected characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.ObstructionDetected, "Bool", config.ObstructionDetected); + } + //optionals + if (config.LockCurrentState) { + this.log("GarageDoorOpener LockCurrentState characteristic enabled"); + myService.addCharacteristic(Characteristic.LockCurrentState); + this.bindCharacteristic(myService, Characteristic.LockCurrentState, "Int", config.LockCurrentState); + } + if (config.LockTargetState) { + this.log("GarageDoorOpener LockTargetState characteristic enabled"); + myService.addCharacteristic(Characteristic.LockTargetState); + this.bindCharacteristic(myService, Characteristic.LockTargetState, "Bool", config.LockTargetState); + } + return myService; + }, getLightbulbService: function(config) { // some sanity checks //this.config = config; @@ -657,11 +737,6 @@ KNXDevice.prototype = { // TargetTemperature if available if (config.TargetTemperature) { this.log("Thermostat TargetTemperature characteristic enabled"); - - // DEBUG - console.log("default value: " + myService.getCharacteristic(Characteristic.TargetTemperature).value); - // DEBUG - // default boundary too narrow for thermostats myService.getCharacteristic(Characteristic.TargetTemperature).minimumValue=0; // °C myService.getCharacteristic(Characteristic.TargetTemperature).maximumValue=40; // °C @@ -790,7 +865,7 @@ KNXDevice.prototype = { informationService .setCharacteristic(Characteristic.Manufacturer, "Opensource Community") .setCharacteristic(Characteristic.Model, "KNX Universal Device") - .setCharacteristic(Characteristic.SerialNumber, "Version 1.1"); + .setCharacteristic(Characteristic.SerialNumber, "Version 1.1.2"); accessoryServices.push(informationService); @@ -814,6 +889,9 @@ KNXDevice.prototype = { case "ContactSensor": accessoryServices.push(this.getContactSenserService(configService)); break; + case "GarageDoorOpener": + accessoryServices.push(this.getGarageDoorOpenerService(configService)); + break; case "Lightbulb": accessoryServices.push(this.getLightbulbService(configService)); break; diff --git a/platforms/KNX.md b/platforms/KNX.md index 937af45..2eba871 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -71,47 +71,76 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres # Supported Services and their characteristics ## ContactSensor -- ContactSensorState: DPT 1, 0 as contact **OR** -- ContactSensorStateContact1: DPT 1, 1 as contact +- ContactSensorState: DPT 1.002, 0 as contact **OR** +- ContactSensorStateContact1: DPT 1.002, 1 as contact + +- StatusActive: DPT 1.011, 1 as true +- StatusFault: DPT 1.011, 1 as true +- StatusTampered: DPT 1.011, 1 as true +- StatusLowBattery: DPT 1.011, 1 as true + +## GarageDoorOpener +- CurrentDoorState: DPT5 integer value in range 0..4 + // Characteristic.CurrentDoorState.OPEN = 0; + // Characteristic.CurrentDoorState.CLOSED = 1; + // Characteristic.CurrentDoorState.OPENING = 2; + // Characteristic.CurrentDoorState.CLOSING = 3; + // Characteristic.CurrentDoorState.STOPPED = 4; + +- TargetDoorState: DPT5 integer value in range 0..1 + // Characteristic.TargetDoorState.OPEN = 0; + // Characteristic.TargetDoorState.CLOSED = 1; + +- ObstructionDetected: DPT1, 1 as true + +- LockCurrentState: DPT5 integer value in range 0..3 + // Characteristic.LockCurrentState.UNSECURED = 0; + // Characteristic.LockCurrentState.SECURED = 1; + // Characteristic.LockCurrentState.JAMMED = 2; + // Characteristic.LockCurrentState.UNKNOWN = 3; + +- LockTargetState: DPT5 integer value in range 0..1 + // Characteristic.LockTargetState.UNSECURED = 0; + // Characteristic.LockTargetState.SECURED = 1; + -- StatusActive: DPT 1, 1 as true -- StatusFault: DPT 1, 1 as true -- StatusTampered: DPT 1, 1 as true -- StatusLowBattery: DPT 1, 1 as true ## Lightbulb - - On: DPT 1, 1 as on, 0 as off - - Brightness: DPT5 percentage, 100% (=255) the brightest + - On: DPT 1.001, 1 as on, 0 as off + - Brightness: DPT5.001 percentage, 100% (=255) the brightest ## LightSensor -- CurrentAmbientLightLevel: DPT 9, 0 to 100000 Lux +- CurrentAmbientLightLevel: DPT 9.004, 0 to 100000 Lux -## LockMechanism +## LockMechanism (This is poorly mapped!) - LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** - LockCurrentStateSecured0: DPT 1, 0 as secured - LockTargetState: DPT 1, 1 as secured **OR** - LockTargetStateSecured0: DPT 1, 0 as secured +*ToDo here: correction of mappings, HomeKit reqires lock states UNSECURED=0, SECURED=1, JAMMED = 2, UNKNOWN=3* + + ## Outlet - - On: DPT 1, 1 as on, 0 as off - - OutletInUse: DPT 1, 1 as on, 0 as off + - On: DPT 1.001, 1 as on, 0 as off + - OutletInUse: DPT 1.011, 1 as on, 0 as off ## Switch - - On: DPT 1, 1 as on, 0 as off + - On: DPT 1.001, 1 as on, 0 as off ## TemperatureSensor -- CurrentTemperature: DPT9 in °C [listen only] +- CurrentTemperature: DPT9.001 in °C [listen only] ## Thermostat -- CurrentTemperature: DPT9 in °C [listen only] -- TargetTemperature: DPT9, values 0..40°C only, all others are ignored -- CurrentHeatingCoolingState: DPT5 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] -- TargetHeatingCoolingState: as above +- CurrentTemperature: DPT9.001 in °C [listen only] +- TargetTemperature: DPT9.001, values 0..40°C only, all others are ignored +- CurrentHeatingCoolingState: DPT20.102 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] +- TargetHeatingCoolingState: DPT20.102 HVAC, as above ## Window -- CurrentPosition: DPT5 percentage -- TargetPosition: DPT5 percentage -- PositionState: DPT5 value [listen only] +- CurrentPosition: DPT5.001 percentage +- TargetPosition: DPT5.001 percentage +- PositionState: DPT5.005 value [listen only: 0 Increasing, 1 Decreasing, 2 Stopped] ## WindowCovering - CurrentPosition: DPT5 percentage From eec663a5c8e1a6c69d7388686edc664a88460163 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Sat, 19 Sep 2015 18:37:19 +0200 Subject: [PATCH 14/30] Routines for unsigned int values, such as enumeration like types --- accessories/knxdevice.js | 44 +++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index f94f5b2..6c95a1a 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -8,9 +8,11 @@ new features include: - Window - WindowCovering - ContactSensor -New 2015-0918: +New 2015-09-18: - Services Switch and Outlet - Code cleanup +New 2015-09-19: +- GarageDoorOpener Service * */ var Service = require("HAP-NodeJS").Service; @@ -148,20 +150,7 @@ KNXDevice.prototype = { this.knxread (groupAddresses); } }, -/** Write special type routines - * - */ - // special types - knxwrite_percent: function(callback, groupAddress, value) { - var numericValue = 0; - if (value && value>=0 && value <= 100) { - numericValue = 255*value/100; // convert 1..100 to 1..255 for KNX bus - } else { - this.log("[ERROR] Percentage value ot of bounds "); - numericValue = 0; - } - this.knxwrite(callback, groupAddress,'DPT5',numericValue); - }, + /** Registering routines * */ @@ -210,11 +199,22 @@ KNXDevice.prototype = { this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); var hk_value = Math.round(val*10)/10; if (hk_value>=characteristic.minimumValue && hk_value<=characteristic.maximumValue) { - characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decoimal for HomeKit + characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decimal for HomeKit } else { this.log("Value %s out of bounds %s...%s ",hk_value, characteristic.minimumValue, characteristic.maximumValue); } - + }.bind(this)); + }, + //integer + knxregister_int: function(addresses, characteristic) { + this.log("knx registering FLOAT " + addresses); + knxd_registerGA(addresses, function(val, src, dest, type){ + this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + if (val>=(characteristic.minimumValue || 0) && val<=(characteristic.maximumValue || 255) { + characteristic.setValue(val, undefined, 'fromKNXBus'); + } else { + this.log("Value %s out of bounds %s...%s ",hk_value, (characteristic.minimumValue || 0), (characteristic.maximumValue || 255)); + } }.bind(this)); }, knxregister_HVAC: function(addresses, characteristic) { @@ -431,9 +431,10 @@ KNXDevice.prototype = { this.setHVACState(value, callback, context, config.Set); }.bind(this)); break; - default: + default: { this.log("[ERROR] unknown type passed"); - throw new Error("[ERROR] unknown type passed"); + throw new Error("[ERROR] unknown type passed"); + } } } if ([config.Set].concat(config.Listen || []).length>0) { @@ -453,8 +454,7 @@ KNXDevice.prototype = { this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic); break; case "Int": - // use float as return type for ints, for we don't care - this.knxregister_float([config.Set].concat(config.Listen || []), myCharacteristic); + this.knxregister_int([config.Set].concat(config.Listen || []), myCharacteristic); break; case "HVAC": this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic); @@ -559,6 +559,8 @@ KNXDevice.prototype = { } if (config.TargetDoorState) { this.log("GarageDoorOpener TargetDoorState characteristic enabled"); + //myService.getCharacteristic(Characteristic.TargetDoorState).minimumValue=0; // + //myService.getCharacteristic(Characteristic.TargetDoorState).maximumValue=4; // this.bindCharacteristic(myService, Characteristic.TargetDoorState, "Int", config.TargetDoorState); } if (config.ObstructionDetected) { From 84c51aa27a7162423f7568233e623e06219f1a8e Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Sat, 19 Sep 2015 21:24:55 +0200 Subject: [PATCH 15/30] GarageDoorOpener fixed --- accessories/knxdevice.js | 2 +- platforms/KNX-sample-config.json | 56 +++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 6c95a1a..642d925 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -210,7 +210,7 @@ KNXDevice.prototype = { this.log("knx registering FLOAT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); - if (val>=(characteristic.minimumValue || 0) && val<=(characteristic.maximumValue || 255) { + if (val>=(characteristic.minimumValue || 0) && val<=(characteristic.maximumValue || 255)) { characteristic.setValue(val, undefined, 'fromKNXBus'); } else { this.log("Value %s out of bounds %s...%s ",hk_value, (characteristic.minimumValue || 0), (characteristic.maximumValue || 255)); diff --git a/platforms/KNX-sample-config.json b/platforms/KNX-sample-config.json index d74a14f..2c29736 100644 --- a/platforms/KNX-sample-config.json +++ b/platforms/KNX-sample-config.json @@ -7,8 +7,8 @@ }, "description": "This is an example configuration file for KNX platform shim", "hint": "Always paste into jsonlint.com validation page before starting your homebridge, saves a lot of frustration", - "hint2":"Replace all group addresses by current addresses of your installation, these are arbitrary examples!", - "hint3":"For valid services and their characteristics have a look at the knxdevice.md file in folder accessories!" + "hint2": "Replace all group addresses by current addresses of your installation, these are arbitrary examples!", + "hint3": "For valid services and their characteristics have a look at the knxdevice.md file in folder accessories!", "platforms": [ { "platform": "KNX", @@ -74,7 +74,7 @@ }, { "accessory_type": "knxdevice", - "description":"sample device with multiple services. Multiple services of different types are widely supported", + "description": "sample device with multiple services. Multiple services of different types are widely supported", "name": "Office", "services": [ { @@ -102,11 +102,11 @@ "type": "WindowCovering", "description": "iOS9 Window covering (blinds etc) type, still WIP", "name": "Blinds", - "Target": { + "TargetPosition": { "Set": "1/2/3", "Listen": "1/2/4" }, - "Current": { + "CurrentPosition": { "Set": "1/3/1", "Listen": "1/3/2" }, @@ -115,22 +115,40 @@ } } ] - },{ - "accessory_type": "knxdevice", - - "description":"sample contact sensor device", - "name": "Office", - "services": [ - { - "type": "ContactSensor", - "name": "Office Door", - "ContactSensorState": { - "Listen": "5/3/5" + }, + { + "accessory_type": "knxdevice", + "description": "sample contact sensor device", + "name": "Office Contact", + "services": [ + { + "type": "ContactSensor", + "name": "Office Door", + "ContactSensorState": { + "Listen": "5/3/5" + } } - }, - + ] + }, + { + "accessory_type": "knxdevice", + "description": "sample garage door opener", + "name": "Office Garage", + "services": [ + { + "type": "GarageDoorOpener", + "name": "Office Garage Opener", + "CurrentDoorState": { + "Listen": "5/4/5" + }, + "TargetDoorState": { + "Listen": "5/4/6" + } + } + ] + } ] } ], "accessories": [] -} +} \ No newline at end of file From 48f613f8ae1be2b80fcad54d9a2de965cc6db8f9 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Sat, 19 Sep 2015 21:47:07 +0200 Subject: [PATCH 16/30] New Motion Sensor service --- accessories/knxdevice.js | 48 +++++++++++++++++++++++++++++++++++++++- platforms/KNX.md | 7 ++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 642d925..9ce2b5e 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -12,7 +12,8 @@ New 2015-09-18: - Services Switch and Outlet - Code cleanup New 2015-09-19: -- GarageDoorOpener Service +- GarageDoorOpener Service +- MotionSensor Service * */ var Service = require("HAP-NodeJS").Service; @@ -666,6 +667,48 @@ KNXDevice.prototype = { //iterate(myService); return myService; }, + getMotionSenserService: function(config) { +// Characteristic.ContactSensorState.CONTACT_DETECTED = 0; +// Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1; + + // some sanity checks + if (config.type !== "MotionSensor") { + this.log("[ERROR] MotionSensor Service for non 'MotionSensor' service called"); + return undefined; + } + if (!config.name) { + this.log("[ERROR] MotionSensor Service without 'name' property called"); + return undefined; + } + + var myService = new Service.MotionSensor(config.name,config.name); + if (config.ContactSensorState) { + this.log("MotionSensor MotionDetected characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.MotionDetected, "Bool", config.MotionDetected); + } + //optionals + if (config.StatusActive) { + this.log("MotionSensor StatusActive characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusActive); + this.bindCharacteristic(myService, Characteristic.StatusActive, "Bool", config.StatusActive); + } + if (config.StatusFault) { + this.log("MotionSensor StatusFault characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusFault); + this.bindCharacteristic(myService, Characteristic.StatusFault, "Bool", config.StatusFault); + } + if (config.StatusTampered) { + this.log("MotionSensor StatusTampered characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusTampered); + this.bindCharacteristic(myService, Characteristic.StatusTampered, "Bool", config.StatusTampered); + } + if (config.StatusLowBattery) { + this.log("MotionSensor StatusLowBattery characteristic enabled"); + myService.addCharacteristic(Characteristic.StatusLowBattery); + this.bindCharacteristic(myService, Characteristic.StatusLowBattery, "Bool", config.StatusLowBattery); + } + return myService; + }, getOutletService: function(config) { /** * this.addCharacteristic(Characteristic.On); @@ -903,6 +946,9 @@ KNXDevice.prototype = { case "LockMechanism": accessoryServices.push(this.getLockMechanismService(configService)); break; + case "MotionSensor": + accessoryServices.push(this.getMotionSensorService(configService)); + break; case "Switch": accessoryServices.push(this.getSwitchService(configService)); break; diff --git a/platforms/KNX.md b/platforms/KNX.md index 2eba871..c3b4fe3 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -120,6 +120,13 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres *ToDo here: correction of mappings, HomeKit reqires lock states UNSECURED=0, SECURED=1, JAMMED = 2, UNKNOWN=3* +## MotionSensor +- MotionDetected: DPT 1.002, 1 as motion detected + +- StatusActive: DPT 1.011, 1 as true +- StatusFault: DPT 1.011, 1 as true +- StatusTampered: DPT 1.011, 1 as true +- StatusLowBattery: DPT 1.011, 1 as true ## Outlet - On: DPT 1.001, 1 as on, 0 as off From 80b2a047d42d3da815c38ed784d421f10ec9ca05 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Sat, 19 Sep 2015 21:56:20 +0200 Subject: [PATCH 17/30] Typo fixes --- accessories/knxdevice.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 9ce2b5e..5801249 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -667,7 +667,7 @@ KNXDevice.prototype = { //iterate(myService); return myService; }, - getMotionSenserService: function(config) { + getMotionSensorService: function(config) { // Characteristic.ContactSensorState.CONTACT_DETECTED = 0; // Characteristic.ContactSensorState.CONTACT_NOT_DETECTED = 1; @@ -682,7 +682,7 @@ KNXDevice.prototype = { } var myService = new Service.MotionSensor(config.name,config.name); - if (config.ContactSensorState) { + if (config.MotionDetected) { this.log("MotionSensor MotionDetected characteristic enabled"); this.bindCharacteristic(myService, Characteristic.MotionDetected, "Bool", config.MotionDetected); } From 67fb6e8b4decde8b42a80fe54e1df3661696a664 Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 21 Sep 2015 00:59:26 +0200 Subject: [PATCH 18/30] fixing thermostat. switch the order of the characteristics now my stellaZ thermostat is shown correct in apps like eve and insteon+ --- platforms/ZWayServer.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/platforms/ZWayServer.js b/platforms/ZWayServer.js index 5b79c8e..70c2d6e 100644 --- a/platforms/ZWayServer.js +++ b/platforms/ZWayServer.js @@ -89,11 +89,11 @@ ZWayServerPlatform.prototype = { //TODO: Unify this with getVDevServices, so there's only one place with mapping between service and vDev type. //Note: Order matters! var primaryDeviceClasses = [ - "switchBinary", "thermostat", - "sensorBinary.Door/Window", "sensorMultilevel.Temperature", - "switchMultilevel" + "switchMultilevel", + "switchBinary", + "sensorBinary.Door/Window" ]; var that = this; @@ -226,24 +226,24 @@ ZWayServerAccessory.prototype = { var typeKey = ZWayServerPlatform.getVDevTypeKey(vdev); var services = [], service; switch (typeKey) { - case "switchBinary": - services.push(new Service.Switch(vdev.metrics.title)); - break; - case "switchMultilevel": - services.push(new Service.Lightbulb(vdev.metrics.title)); - break; - case "thermostat": + case "thermostat": services.push(new Service.Thermostat(vdev.metrics.title)); break; case "sensorMultilevel.Temperature": services.push(new Service.TemperatureSensor(vdev.metrics.title)); break; - case "sensorBinary.Door/Window": - services.push(new Service.GarageDoorOpener(vdev.metrics.title)); + case "switchMultilevel": + services.push(new Service.Lightbulb(vdev.metrics.title)); break; case "battery.Battery": services.push(new Service.BatteryService(vdev.metrics.title)); break; + case "switchBinary": + services.push(new Service.Switch(vdev.metrics.title)); + break; + case "sensorBinary.Door/Window": + services.push(new Service.GarageDoorOpener(vdev.metrics.title)); + break; case "sensorMultilevel.Luminiscence": services.push(new Service.LightSensor(vdev.metrics.title)); break; From 625b9f47df2061f11099753108bc2d38364ebd6e Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Mon, 21 Sep 2015 08:17:46 -0700 Subject: [PATCH 19/30] Bump HAP-NodeJS Closes #181 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d0eb41c..3a3ca74 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "color": "0.10.x", "eibd": "^0.3.1", "elkington": "kevinohara80/elkington", - "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#0030b35856e04ee2b42f0d05839feaa5c44cbd1f", + "hap-nodejs": "git+https://github.com/KhaosT/HAP-NodeJS#4650e771f356a220868d873d16564a6be6603ff7", "harmonyhubjs-client": "^1.1.4", "harmonyhubjs-discover": "git+https://github.com/swissmanu/harmonyhubjs-discover.git", "lifx-api": "^1.0.1", From ca232f3111305803b2d418764312c72762c534cf Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Fri, 25 Sep 2015 00:26:07 -0400 Subject: [PATCH 20/30] Noted updated for requirement to successfully get HAP-NodeJS installed. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 641e32f..2748494 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,13 @@ You'll also need some patience, as Siri can be very strict about sentence struct # 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: +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. + +**Note:** You'll need to make sure you have the following package installed for your platform. + + * libavahi-compat-libdnssd-dev + +First, clone this repo: $ git clone https://github.com/nfarina/homebridge.git $ cd homebridge @@ -60,6 +66,7 @@ OK, if you're still excited enough about ordering Siri to make your coffee (whic **Node**: You'll need to have NodeJS version 0.12.x or better installed for required submodule `HAP-NodeJS` to load. + Now you should be able to run the homebridge server: $ cd homebridge From bb3381e10af1c472f81422608b8b91e240a8cc8c Mon Sep 17 00:00:00 2001 From: Nick Farina Date: Thu, 24 Sep 2015 22:15:58 -0700 Subject: [PATCH 21/30] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2748494..ab3b98a 100644 --- a/README.md +++ b/README.md @@ -54,9 +54,7 @@ You'll also need some patience, as Siri can be very strict about sentence struct 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. -**Note:** You'll need to make sure you have the following package installed for your platform. - - * libavahi-compat-libdnssd-dev +**Note:** If you're running on Linux, you'll need to make sure you have the `libavahi-compat-libdnssd-dev` package installed. First, clone this repo: @@ -64,7 +62,7 @@ First, clone this repo: $ cd homebridge $ npm install -**Node**: You'll need to have NodeJS version 0.12.x or better installed for required submodule `HAP-NodeJS` to load. +**Note**: You'll need to have NodeJS version 0.12.x or better installed for required submodule `HAP-NodeJS` to load. Now you should be able to run the homebridge server: From c6c45d9e3db184b94b1fd9a32e2b38264dc2e9df Mon Sep 17 00:00:00 2001 From: ilcato Date: Sun, 27 Sep 2015 13:00:57 +0200 Subject: [PATCH 22/30] Fixed incompatibility with new version of HAP-Node.js --- platforms/FibaroHC2.js | 65 +++++++++++------------------------------- 1 file changed, 16 insertions(+), 49 deletions(-) diff --git a/platforms/FibaroHC2.js b/platforms/FibaroHC2.js index c18d0dd..4567b40 100644 --- a/platforms/FibaroHC2.js +++ b/platforms/FibaroHC2.js @@ -51,22 +51,21 @@ FibaroHC2Platform.prototype = { if (s.visible == true) { var accessory = null; if (s.type == "com.fibaro.multilevelSwitch") - accessory = new FibaroDimmerAccessory(that, s); + accessory = new FibaroAccessory(new Service.Lightbulb(s.name), [Characteristic.On, Characteristic.Brightness]); else if (s.type == "com.fibaro.FGRM222" || s.type == "com.fibaro.FGR221") - accessory = new FibaroRollerShutterAccessory(that, s); + accessory = new FibaroAccessory(new Service.WindowCovering(s.name), [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState]); else if (s.type == "com.fibaro.binarySwitch" || s.type == "com.fibaro.developer.bxs.virtualBinarySwitch") - accessory = new FibaroBinarySwitchAccessory(that, s); + accessory = new FibaroAccessory(new Service.Switch(s.name), [Characteristic.On]); else if (s.type == "com.fibaro.FGMS001" || s.type == "com.fibaro.motionSensor") - accessory = new FibaroMotionSensorAccessory(that, s); + accessory = new FibaroAccessory(new Service.MotionSensor(s.name), [Characteristic.MotionDetected]); else if (s.type == "com.fibaro.temperatureSensor") - accessory = new FibaroTemperatureSensorAccessory(that, s); + accessory = new FibaroAccessory(new Service.TemperatureSensor(s.name), [Characteristic.CurrentTemperature]); else if (s.type == "com.fibaro.doorSensor") - accessory = new FibaroDoorSensorAccessory(that, s); + accessory = new FibaroAccessory(new Service.ContactSensor(s.name), [Characteristic.ContactSensorState]); else if (s.type == "com.fibaro.lightSensor") - accessory = new FibaroLightSensorAccessory(that, s); + accessory = new FibaroAccessory(new Service.LightSensor(s.name), [Characteristic.CurrentAmbientLightLevel]); else if (s.type == "com.fibaro.FGWP101") - accessory = new FibaroOutletAccessory(that, s); - + accessory = new FibaroAccessory(new Service.Outlet(s.name), [Characteristic.On, Characteristic.OutletInUse]); if (accessory != null) { accessory.getServices = function() { return that.getServices(accessory); @@ -150,8 +149,11 @@ FibaroHC2Platform.prototype = { return informationService; }, bindCharacteristicEvents: function(characteristic, homebridgeAccessory) { - var onOff = characteristic.format == "bool" ? true : false; - var readOnly = characteristic.writable == undefined || characteristic.writable == false ? true : false; + var onOff = characteristic.props.format == "bool" ? true : false; + var readOnly = true; + for (var i = 0; i < characteristic.props.perms.length; i++) + if (characteristic.props.perms[i] == "pw") + readOnly = false; var powerValue = (characteristic.UUID == "00000026-0000-1000-8000-0026BB765291") ? true : false; subscribeUpdate(characteristic, homebridgeAccessory, onOff); if (!readOnly) { @@ -184,44 +186,9 @@ FibaroHC2Platform.prototype = { } } -function FibaroDimmerAccessory(platform, s) { - this.controlService = new Service.Lightbulb(this.name); - this.characteristics = [Characteristic.On, Characteristic.Brightness]; -} - -function FibaroRollerShutterAccessory(platform, s) { - this.controlService = new Service.WindowCovering(this.name); - this.characteristics = [Characteristic.CurrentPosition, Characteristic.TargetPosition, Characteristic.PositionState]; -} - -function FibaroBinarySwitchAccessory(platform, s) { - this.controlService = new Service.Switch(this.name); - this.characteristics = [Characteristic.On]; -} - -function FibaroMotionSensorAccessory(platform, s) { - this.controlService = new Service.MotionSensor(this.name); - this.characteristics = [Characteristic.MotionDetected]; -} - -function FibaroTemperatureSensorAccessory(platform, s) { - this.controlService = new Service.TemperatureSensor(this.name); - this.characteristics = [Characteristic.CurrentTemperature]; -} - -function FibaroDoorSensorAccessory(platform, s) { - this.controlService = new Service.ContactSensor(this.name); - this.characteristics = [Characteristic.ContactSensorState]; -} - -function FibaroLightSensorAccessory(platform, s) { - this.controlService = new Service.LightSensor(this.name); - this.characteristics = [Characteristic.CurrentAmbientLightLevel]; -} - -function FibaroOutletAccessory(platform, s) { - this.controlService = new Service.Outlet(this.name); - this.characteristics = [Characteristic.On, Characteristic.OutletInUse]; +function FibaroAccessory(controlService, characteristics) { + this.controlService = controlService; + this.characteristics = characteristics; } var lastPoll=0; From 2a66eac0584c9d38d97bcf987874d1e67bc1c2a0 Mon Sep 17 00:00:00 2001 From: S'pht'Kr Date: Mon, 28 Sep 2015 06:12:25 +0200 Subject: [PATCH 23/30] Fix for multiple devices, refactor, and custom Service+Characteristic --- platforms/YamahaAVR.js | 219 +++++++++++++++++++++++++---------------- 1 file changed, 133 insertions(+), 86 deletions(-) diff --git a/platforms/YamahaAVR.js b/platforms/YamahaAVR.js index f554fa0..1659c0f 100644 --- a/platforms/YamahaAVR.js +++ b/platforms/YamahaAVR.js @@ -1,5 +1,10 @@ var types = require("HAP-NodeJS/accessories/types.js"); +var inherits = require('util').inherits; +var debug = require('debug')('YamahaAVR'); +var Service = require("HAP-NodeJS").Service; +var Characteristic = require("HAP-NodeJS").Characteristic; var Yamaha = require('yamaha-nodejs'); +var Q = require('q'); var mdns = require('mdns'); //workaround for raspberry pi var sequence = [ @@ -12,10 +17,53 @@ function YamahaAVRPlatform(log, config){ this.log = log; this.config = config; this.playVolume = config["play_volume"]; + this.minVolume = config["min_volume"] || -50.0; + this.maxVolume = config["max_volume"] || -20.0; + this.gapVolume = this.maxVolume - this.minVolume; this.setMainInputTo = config["setMainInputTo"]; + this.expectedDevices = config["expected_devices"] || 100; + this.discoveryTimeout = config["discovery_timeout"] || 30; this.browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence}); } +// Custom Characteristics and service... + +YamahaAVRPlatform.AudioVolume = function() { + Characteristic.call(this, 'Audio Volume', '00001001-0000-1000-8000-135D67EC4377'); + this.format = 'uint8'; + this.unit = 'percentage'; + this.maximumValue = 100; + this.minimumValue = 0; + this.stepValue = 1; + this.readable = true; + this.writable = true; + this.supportsEventNotification = true; + this.value = this.getDefaultValue(); +}; +inherits(YamahaAVRPlatform.AudioVolume, Characteristic); + +YamahaAVRPlatform.Muting = function() { + Characteristic.call(this, 'Muting', '00001002-0000-1000-8000-135D67EC4377'); + this.format = 'bool'; + this.readable = true; + this.writable = true; + this.supportsEventNotification = true; + this.value = this.getDefaultValue(); +}; +inherits(YamahaAVRPlatform.Muting, Characteristic); + +YamahaAVRPlatform.AudioDeviceService = function(displayName, subtype) { + Service.call(this, displayName, '00000001-0000-1000-8000-135D67EC4377', subtype); + + // Required Characteristics + this.addCharacteristic(YamahaAVRPlatform.AudioVolume); + + // Optional Characteristics + this.addOptionalCharacteristic(YamahaAVRPlatform.Muting); +}; +inherits(YamahaAVRPlatform.AudioDeviceService, Service); + + YamahaAVRPlatform.prototype = { accessories: function(callback) { this.log("Getting Yamaha AVR devices."); @@ -24,7 +72,9 @@ YamahaAVRPlatform.prototype = { var browser = this.browser; browser.stop(); browser.removeAllListeners('serviceUp'); // cleanup listeners - + var accessories = []; + var timer, timeElapsed = 0, checkCyclePeriod = 5000; + browser.on('serviceUp', function(service){ var name = service.name; //console.log('Found HTTP service "' + name + '"'); @@ -36,12 +86,36 @@ YamahaAVRPlatform.prototype = { var sysId = sysConfig.YAMAHA_AV.System[0].Config[0].System_ID[0]; that.log("Found Yamaha " + sysModel + " - " + sysId + ", \"" + name + "\""); var accessory = new YamahaAVRAccessory(that.log, that.config, service, yamaha, sysConfig); - callback([accessory]); + accessories.push(accessory); + if(accessories.length >= this.expectedDevices) + timeoutFunction(); // We're done, call the timeout function now. + //callback([accessory]); }, function(err){ return; - }) + }); }); browser.start(); + + // The callback can only be called once...so we'll have to find as many as we can + // in a fixed time and then call them in. + var timeoutFunction = function(){ + if(accessories.length >= that.expectedDevices){ + clearTimeout(timer); + } else { + timeElapsed += checkCyclePeriod; + if(timeElapsed > that.discoveryTimeout * 1000){ + that.log("Waited " + that.discoveryTimeout + " seconds, stopping discovery."); + } else { + timer = setTimeout(timeoutFunction, checkCyclePeriod); + return; + } + } + browser.stop(); + browser.removeAllListeners('serviceUp'); + that.log("Discovery finished, found " + accessories.length + " Yamaha AVR devices."); + callback(accessories); + }; + timer = setTimeout(timeoutFunction, checkCyclePeriod); } }; @@ -56,6 +130,9 @@ function YamahaAVRAccessory(log, config, mdnsService, yamaha, sysConfig) { this.serviceName = mdnsService.name + " Speakers"; this.setMainInputTo = config["setMainInputTo"]; this.playVolume = this.config["play_volume"]; + this.minVolume = config["min_volume"] || -50.0; + this.maxVolume = config["max_volume"] || -20.0; + this.gapVolume = this.maxVolume - this.minVolume; } YamahaAVRAccessory.prototype = { @@ -66,104 +143,74 @@ YamahaAVRAccessory.prototype = { if (playing) { - yamaha.powerOn().then(function(){ + return yamaha.powerOn().then(function(){ if (that.playVolume) return yamaha.setVolumeTo(that.playVolume*10); - else return { then: function(f, r){ f(); } }; + else return Q(); }).then(function(){ if (that.setMainInputTo) return yamaha.setMainInputTo(that.setMainInputTo); - else return { then: function(f, r){ f(); } }; + else return Q(); }).then(function(){ if (that.setMainInputTo == "AirPlay") return yamaha.SendXMLToReceiver( 'Play' ); - else return { then: function(f, r){ f(); } }; - //else return Promise.fulfilled(undefined); + else return Q(); }); } else { - yamaha.powerOff(); + return yamaha.powerOff(); } }, getServices: function() { var that = this; - return [{ - sType: types.ACCESSORY_INFORMATION_STYPE, - characteristics: [{ - cType: types.NAME_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: this.name, - supportEvents: false, - supportBonjour: false, - manfDescription: "Name of the accessory", - designedMaxLength: 255 - },{ - cType: types.MANUFACTURER_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: "Yamaha", - supportEvents: false, - supportBonjour: false, - manfDescription: "Manufacturer", - designedMaxLength: 255 - },{ - cType: types.MODEL_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: this.sysConfig.YAMAHA_AV.System[0].Config[0].Model_Name[0], - supportEvents: false, - supportBonjour: false, - manfDescription: "Model", - designedMaxLength: 255 - },{ - cType: types.SERIAL_NUMBER_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: this.sysConfig.YAMAHA_AV.System[0].Config[0].System_ID[0], - supportEvents: false, - supportBonjour: false, - manfDescription: "SN", - designedMaxLength: 255 - },{ - cType: types.IDENTIFY_CTYPE, - onUpdate: null, - perms: ["pw"], - format: "bool", - initialValue: false, - supportEvents: false, - supportBonjour: false, - manfDescription: "Identify Accessory", - designedMaxLength: 1 - }] - },{ - sType: types.SWITCH_STYPE, - characteristics: [{ - cType: types.NAME_CTYPE, - onUpdate: null, - perms: ["pr"], - format: "string", - initialValue: this.serviceName, - supportEvents: false, - supportBonjour: false, - manfDescription: "Name of service", - designedMaxLength: 255 - },{ - cType: types.POWER_STATE_CTYPE, - onUpdate: function(value) { that.setPlaying(value); }, - perms: ["pw","pr","ev"], - format: "bool", - initialValue: false, - supportEvents: false, - supportBonjour: false, - manfDescription: "Change the playback state of the Yamaha AV Receiver", - designedMaxLength: 1 - }] - }]; + var informationService = new Service.AccessoryInformation(); + var yamaha = this.yamaha; + + informationService + .setCharacteristic(Characteristic.Name, this.name) + .setCharacteristic(Characteristic.Manufacturer, "Yamaha") + .setCharacteristic(Characteristic.Model, this.sysConfig.YAMAHA_AV.System[0].Config[0].Model_Name[0]) + .setCharacteristic(Characteristic.SerialNumber, this.sysConfig.YAMAHA_AV.System[0].Config[0].System_ID[0]); + + var switchService = new Service.Switch("Power State"); + switchService.getCharacteristic(Characteristic.On) + .on('get', function(callback, context){ + yamaha.isOn().then(function(result){ + callback(false, result); + }.bind(this)); + }.bind(this)) + .on('set', function(powerOn, callback){ + this.setPlaying(powerOn).then(function(){ + callback(false, powerOn); + }, function(error){ + callback(error, !powerOn); //TODO: Actually determine and send real new status. + }); + }.bind(this)); + + var audioDeviceService = new YamahaAVRPlatform.AudioDeviceService("Audio Functions"); + audioDeviceService.getCharacteristic(YamahaAVRPlatform.AudioVolume) + .on('get', function(callback, context){ + yamaha.getBasicInfo().done(function(basicInfo){ + var v = basicInfo.getVolume()/10.0; + var p = 100 * ((v - that.minVolume) / that.gapVolume); + p = p < 0 ? 0 : p > 100 ? 100 : Math.round(p); + debug("Got volume percent of " + p + "%"); + callback(false, p); + }); + }) + .on('set', function(p, callback){ + var v = ((p / 100) * that.gapVolume) + that.minVolume; + v = Math.round(v*10.0); + debug("Setting volume to " + v); + yamaha.setVolumeTo(v).then(function(){ + callback(false, p); + }); + }) + .getValue(null, null); // force an asynchronous get + + + return [informationService, switchService, audioDeviceService]; + } }; From ba5722c5174ec2fba0fa0b6670aaf6ebdaa2e936 Mon Sep 17 00:00:00 2001 From: Raoul Date: Wed, 30 Sep 2015 09:21:59 +0200 Subject: [PATCH 24/30] props update minValue, maxValue used in Temperature devices (Apple's default values too narrow for beer coolers I've heard) adapted call syntax for "Simplify Characteristic properties" https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 --- accessories/knxdevice.js | 51 +++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 5801249..6efbbe3 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -195,26 +195,44 @@ KNXDevice.prototype = { }, // float knxregister_float: function(addresses, characteristic) { + // update for props refactor https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR50 + + var validValue = true; + var hk_value = 0.0; this.log("knx registering FLOAT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); - var hk_value = Math.round(val*10)/10; - if (hk_value>=characteristic.minimumValue && hk_value<=characteristic.maximumValue) { + // make hk_value compliant to properties + if (characteristic.props.minStep) { + // quantize + hk_value = Math.round(val/characteristic.props.minStep)*characteristic.props.minStep; + } else { + hk_value = val; + } + // range check + validValue = true; // assume validity at beginning + if (characteristic.props.minValue) { + validValue = validValue && (hk_value>=characteristic.props.minValue); + } + if (characteristic.props.maxValue) { + validValue = validValue && (hk_value<=characteristic.props.maxValue); + } + if (validValue) { characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decimal for HomeKit } else { - this.log("Value %s out of bounds %s...%s ",hk_value, characteristic.minimumValue, characteristic.maximumValue); + this.log("Accessory "+ this.name +":" + characteristic.displayName+ ": Value %s out of bounds %s...%s ",hk_value, characteristic.props.minValue, characteristic.props.maxValue); } }.bind(this)); }, //integer knxregister_int: function(addresses, characteristic) { - this.log("knx registering FLOAT " + addresses); + this.log("knx registering INT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); - if (val>=(characteristic.minimumValue || 0) && val<=(characteristic.maximumValue || 255)) { + if (val>=(characteristic.props.minValue || 0) && val<=(characteristic.props.maxValue || 255)) { characteristic.setValue(val, undefined, 'fromKNXBus'); } else { - this.log("Value %s out of bounds %s...%s ",hk_value, (characteristic.minimumValue || 0), (characteristic.maximumValue || 255)); + this.log("Accessory "+ this.name +":" + characteristic.displayName+ ": Value %s out of bounds %s...%s ",hk_value, (characteristic.props.minValue || 0), (characteristic.props.maxValue || 255)); } }.bind(this)); }, @@ -775,16 +793,25 @@ KNXDevice.prototype = { var myService = new Service.Thermostat(config.name,config.name); // CurrentTemperature) + // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 if (config.CurrentTemperature) { this.log("Thermostat CurrentTemperature characteristic enabled"); + myService.getCharacteristic(Characteristic.CurrentTemperature).setProps({ + minValue: config.CurrentTemperature.minValue || -40, + maxValue: config.CurrentTemperature.maxValue || 60 + }); // °C by default this.bindCharacteristic(myService, Characteristic.CurrentTemperature, "Float", config.CurrentTemperature); } // TargetTemperature if available if (config.TargetTemperature) { this.log("Thermostat TargetTemperature characteristic enabled"); // default boundary too narrow for thermostats - myService.getCharacteristic(Characteristic.TargetTemperature).minimumValue=0; // °C - myService.getCharacteristic(Characteristic.TargetTemperature).maximumValue=40; // °C + // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 + myService.getCharacteristic(Characteristic.TargetTemperature).setProps({ + minValue: config.TargetTemperature.minValue || 0, + maxValue: config.TargetTemperature.maxValue || 40 + }); + this.bindCharacteristic(myService, Characteristic.TargetTemperature, "Float", config.TargetTemperature); } // HVAC @@ -812,10 +839,16 @@ KNXDevice.prototype = { } var myService = new Service.TemperatureSensor(config.name,config.name); // CurrentTemperature) + // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 if (config.CurrentTemperature) { - this.log("TemperatureSensor CurrentTemperature characteristic enabled"); + this.log("Thermostat CurrentTemperature characteristic enabled"); + myService.getCharacteristic(Characteristic.CurrentTemperature).setProps({ + minValue: config.CurrentTemperature.minValue || -40, + maxValue: config.CurrentTemperature.maxValue || 60 + }); // °C by default this.bindCharacteristic(myService, Characteristic.CurrentTemperature, "Float", config.CurrentTemperature); } + return myService; }, getWindowService: function(config) { From 54f0c2f0cb894b77e78032311e3bf54252646aa0 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Wed, 30 Sep 2015 20:03:20 +0200 Subject: [PATCH 25/30] Doc updates --- platforms/KNX-sample-config.json | 306 ++++++++++++++++--------------- platforms/KNX.md | 2 +- 2 files changed, 155 insertions(+), 153 deletions(-) diff --git a/platforms/KNX-sample-config.json b/platforms/KNX-sample-config.json index 2c29736..86e070b 100644 --- a/platforms/KNX-sample-config.json +++ b/platforms/KNX-sample-config.json @@ -1,154 +1,156 @@ { - "bridge": { - "name": "Homebridge", - "username": "CC:22:3D:E3:CE:30", - "port": 51826, - "pin": "031-45-154" - }, - "description": "This is an example configuration file for KNX platform shim", - "hint": "Always paste into jsonlint.com validation page before starting your homebridge, saves a lot of frustration", - "hint2": "Replace all group addresses by current addresses of your installation, these are arbitrary examples!", - "hint3": "For valid services and their characteristics have a look at the knxdevice.md file in folder accessories!", - "platforms": [ - { - "platform": "KNX", - "name": "KNX", - "knxd_ip": "192.168.178.205", - "knxd_port": 6720, - "accessories": [ - { - "accessory_type": "knxdevice", - "description": "Only generic type knxdevice is supported, all previous knx types have been merged into that.", - "name": "Living Room North Lamp", - "services": [ - { - "type": "Lightbulb", - "description": "iOS8 Lightbulb type, supports On (Switch) and Brightness", - "name": "Living Room North Lamp", - "On": { - "Set": "1/1/6", - "Listen": [ - "1/1/63" - ] - }, - "Brightness": { - "Set": "1/1/62", - "Listen": [ - "1/1/64" - ] - } - } - ], - "services-description": "Services is an array, you CAN have multiple service types in one accessory, though it is not fully supported in many iOS HK apps, such as EVE and myTouchHome" - }, - { - "accessory_type": "knxdevice", - "name": "Office Temperature", - "description": "iOS8.4.1 TemperatureSensor type, supports CurrentTemperature", - "services": [ - { - "type": "TemperatureSensor", - "name": "Raumtemperatur", - "CurrentTemperature": { - "Listen": "3/3/44" - } - } - ] - }, - { - "accessory_type": "knxdevice", - "name": "Office Window Lock", - "services": [ - { - "type": "LockMechanism", - "description": "iOS8 Lock mechanism, Supports LockCurrentStateSecured0 OR LockCurrentState, LockTargetStateSecured0 OR LockTargetState, use depending if LOCKED is 0 or 1", - "name": "Office Window Lock", - "LockCurrentStateSecured0": { - "Listen": "5/3/15" - }, - "LockTargetStateSecured0": { - "Listen": "5/3/15" - } - } - ] - }, - { - "accessory_type": "knxdevice", - "description": "sample device with multiple services. Multiple services of different types are widely supported", - "name": "Office", - "services": [ - { - "type": "Lightbulb", - "name": "Office Lamp", - "On": { - "Set": "1/3/5" - } - }, - { - "type": "Thermostat", - "description": "iOS8 Thermostat type, supports CurrentTemperature, TargetTemperature, CurrentHeatingCoolingState ", - "name": "Raumtemperatur", - "CurrentTemperature": { - "Listen": "3/3/44" - }, - "TargetTemperature": { - "Set": "3/3/94" - }, - "CurrentHeatingCoolingState": { - "Listen": "3/3/64" - } - }, - { - "type": "WindowCovering", - "description": "iOS9 Window covering (blinds etc) type, still WIP", - "name": "Blinds", - "TargetPosition": { - "Set": "1/2/3", - "Listen": "1/2/4" - }, - "CurrentPosition": { - "Set": "1/3/1", - "Listen": "1/3/2" - }, - "PositionState": { - "Listen": "2/7/1" - } - } - ] - }, - { - "accessory_type": "knxdevice", - "description": "sample contact sensor device", - "name": "Office Contact", - "services": [ - { - "type": "ContactSensor", - "name": "Office Door", - "ContactSensorState": { - "Listen": "5/3/5" - } - } - ] - }, - { - "accessory_type": "knxdevice", - "description": "sample garage door opener", - "name": "Office Garage", - "services": [ - { - "type": "GarageDoorOpener", - "name": "Office Garage Opener", - "CurrentDoorState": { - "Listen": "5/4/5" - }, - "TargetDoorState": { - "Listen": "5/4/6" - } - } - ] - } - ] - } - ], - "accessories": [] + "bridge": { + "name": "Homebridge", + "username": "CC:22:3D:E3:CE:30", + "port": 51826, + "pin": "031-45-154" + }, + "description": "This is an example configuration file for KNX platform shim", + "hint": "Always paste into jsonlint.com validation page before starting your homebridge, saves a lot of frustration", + "hint2": "Replace all group addresses by current addresses of your installation, these are arbitrary examples!", + "hint3": "For valid services and their characteristics have a look at the knxdevice.md file in folder accessories!", + "platforms": [ + { + "platform": "KNX", + "name": "KNX", + "knxd_ip": "192.168.178.205", + "knxd_port": 6720, + "accessories": [ + { + "accessory_type": "knxdevice", + "description": "Only generic type knxdevice is supported, all previous knx types have been merged into that.", + "name": "Living Room North Lamp", + "services": [ + { + "type": "Lightbulb", + "description": "iOS8 Lightbulb type, supports On (Switch) and Brightness", + "name": "Living Room North Lamp", + "On": { + "Set": "1/1/6", + "Listen": [ + "1/1/63" + ] + }, + "Brightness": { + "Set": "1/1/62", + "Listen": [ + "1/1/64" + ] + } + } + ], + "services-description": "Services is an array, you CAN have multiple service types in one accessory, though it is not fully supported in many iOS HK apps, such as EVE and myTouchHome" + }, + { + "accessory_type": "knxdevice", + "name": "Office Temperature", + "description": "iOS8.4.1 TemperatureSensor type, supports CurrentTemperature", + "services": [ + { + "type": "TemperatureSensor", + "name": "Raumtemperatur", + "CurrentTemperature": { + "Listen": "3/3/44" + } + } + ] + }, + { + "accessory_type": "knxdevice", + "name": "Office Window Lock", + "services": [ + { + "type": "LockMechanism", + "description": "iOS8 Lock mechanism, Supports LockCurrentStateSecured0 OR LockCurrentState, LockTargetStateSecured0 OR LockTargetState, use depending if LOCKED is 0 or 1", + "name": "Office Window Lock", + "LockCurrentStateSecured0": { + "Listen": "5/3/15" + }, + "LockTargetStateSecured0": { + "Listen": "5/3/15" + } + } + ] + }, + { + "accessory_type": "knxdevice", + "description": "sample device with multiple services. Multiple services of different types are widely supported", + "name": "Office", + "services": [ + { + "type": "Lightbulb", + "name": "Office Lamp", + "On": { + "Set": "1/3/5" + } + }, + { + "type": "Thermostat", + "description": "iOS8 Thermostat type, supports CurrentTemperature, TargetTemperature, CurrentHeatingCoolingState ", + "name": "Raumtemperatur", + "CurrentTemperature": { + "Listen": "3/3/44" + }, + "TargetTemperature": { + "Set": "3/3/94" + }, + "CurrentHeatingCoolingState": { + "Listen": "3/3/64" + } + }, + { + "type": "WindowCovering", + "description": "iOS9 Window covering (blinds etc) type, still WIP", + "name": "Blinds", + "TargetPosition": { + "Set": "1/2/3", + "Listen": "1/2/4" + }, + "CurrentPosition": { + "Set": "1/3/1", + "Listen": "1/3/2" + }, + "PositionState": { + "Listen": "2/7/1" + } + } + ] + }, + { + "accessory_type": "knxdevice", + "description": "sample contact sensor device", + "name": "Office Contact", + "services": [ + { + "type": "ContactSensor", + "name": "Office Door", + "ContactSensorState": { + "Listen": "5/3/5" + } + } + ] + }, + { + "accessory_type": "knxdevice", + "description": "sample garage door opener", + "name": "Office Garage", + "services": [ + { + "type": "GarageDoorOpener", + "name": "Office Garage Opener", + "CurrentDoorState": { + "Listen": "5/4/5" + }, + "TargetDoorState": { + "Listen": "5/4/6" + } + } + ] + } + ] + } + ], + "accessories": [ + + ] } \ No newline at end of file diff --git a/platforms/KNX.md b/platforms/KNX.md index c3b4fe3..bab706d 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -152,7 +152,7 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres ## WindowCovering - CurrentPosition: DPT5 percentage - TargetPosition: DPT5 percentage -- PositionState: DPT5 value [listen only] +- PositionState: DPT5 value [listen only: 0 Closing, 1 Opening, 2 STopped] ### not yet supported - HoldPosition From 98ee9f8f95d7f2debada459b96b4cdba4a8b39ff Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Wed, 30 Sep 2015 22:07:33 +0200 Subject: [PATCH 26/30] Return value guarding; Cleaner logs --- accessories/knxdevice.js | 154 +++++++++++++++++++-------------------- platforms/KNX.md | 33 ++++++++- 2 files changed, 108 insertions(+), 79 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index 6efbbe3..b2967c2 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -159,7 +159,7 @@ KNXDevice.prototype = { knxregister_bool: function(addresses, characteristic) { this.log("knx registering BOOLEAN " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); + this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); // iterate(characteristic); characteristic.setValue(val ? 1 : 0, undefined, 'fromKNXBus'); }.bind(this)); @@ -167,7 +167,7 @@ KNXDevice.prototype = { knxregister_boolReverse: function(addresses, characteristic) { this.log("knx registering BOOLEAN " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); + this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); // iterate(characteristic); characteristic.setValue(val ? 0 : 1, undefined, 'fromKNXBus'); }.bind(this)); @@ -176,19 +176,19 @@ KNXDevice.prototype = { knxregister_percent: function(addresses, characteristic) { this.log("knx registering PERCENT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); if (type !== "DPT5") { this.log("[ERROR] Received value cannot be a percentage value"); } else { - if (!characteristic.timeout) { - if (characteristic.timeout < Date.now()) { +// if (!characteristic.timeout) { +// if (characteristic.timeout < Date.now()) { characteristic.setValue(Math.round(val/255*100), undefined, 'fromKNXBus'); - } else { - this.log("Blackout time"); - } - } else { - characteristic.setValue(Math.round(val/255*100), undefined, 'fromKNXBus'); - } // todo get the boolean logic right into one OR expresssion +// } else { +// this.log("Blackout time"); +// } +// } else { +// characteristic.setValue(Math.round(val/255*100), undefined, 'fromKNXBus'); +// } // todo get the boolean logic right into one OR expresssion } }.bind(this)); @@ -199,13 +199,13 @@ KNXDevice.prototype = { var validValue = true; var hk_value = 0.0; - this.log("knx registering FLOAT " + addresses); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering FLOAT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); // make hk_value compliant to properties if (characteristic.props.minStep) { // quantize - hk_value = Math.round(val/characteristic.props.minStep)*characteristic.props.minStep; + hk_value = Math.round(val/characteristic.props.minStep)/(1/characteristic.props.minStep); } else { hk_value = val; } @@ -220,26 +220,26 @@ KNXDevice.prototype = { if (validValue) { characteristic.setValue(hk_value, undefined, 'fromKNXBus'); // 1 decimal for HomeKit } else { - this.log("Accessory "+ this.name +":" + characteristic.displayName+ ": Value %s out of bounds %s...%s ",hk_value, characteristic.props.minValue, characteristic.props.maxValue); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Value %s out of bounds %s...%s ",hk_value, characteristic.props.minValue, characteristic.props.maxValue); } }.bind(this)); }, //integer knxregister_int: function(addresses, characteristic) { - this.log("knx registering INT " + addresses); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering INT " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); if (val>=(characteristic.props.minValue || 0) && val<=(characteristic.props.maxValue || 255)) { characteristic.setValue(val, undefined, 'fromKNXBus'); } else { - this.log("Accessory "+ this.name +":" + characteristic.displayName+ ": Value %s out of bounds %s...%s ",hk_value, (characteristic.props.minValue || 0), (characteristic.props.maxValue || 255)); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Value %s out of bounds %s...%s ",hk_value, (characteristic.props.minValue || 0), (characteristic.props.maxValue || 255)); } }.bind(this)); }, knxregister_HVAC: function(addresses, characteristic) { - this.log("knx registering HVAC " + addresses); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering HVAC " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); var HAPvalue = 0; switch (val){ case 0: @@ -279,9 +279,9 @@ KNXDevice.prototype = { */ // undefined, has to match! knxregister: function(addresses, characteristic) { - this.log("knx registering " + addresses); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering " + addresses); knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); + this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); characteristic.setValue(val, undefined, 'fromKNXBus'); }.bind(this)); }, @@ -296,7 +296,7 @@ KNXDevice.prototype = { */ setBooleanState: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log(gaddress + " event ping pong, exit!"); +// this.log(gaddress + " event ping pong, exit!"); if (callback) { callback(); } @@ -305,14 +305,14 @@ KNXDevice.prototype = { if (value) { numericValue = 1; // need 0 or 1, not true or something } - this.log("Setting "+gaddress+" Boolean to %s", numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" Boolean to %s", numericValue); this.knxwrite(callback, gaddress,'DPT1',numericValue); } }, setBooleanReverseState: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log(gaddress + " event ping pong, exit!"); +// this.log(gaddress + " event ping pong, exit!"); if (callback) { callback(); } @@ -321,14 +321,14 @@ KNXDevice.prototype = { if (!value) { numericValue = 1; // need 0 or 1, not true or something } - this.log("Setting "+gaddress+" Boolean to %s", numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" Boolean to %s", numericValue); this.knxwrite(callback, gaddress,'DPT1',numericValue); } }, setPercentage: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log("event ping pong, exit!"); +// this.log(gaddress + "event ping pong, exit!"); if (callback) { callback(); } @@ -337,13 +337,13 @@ KNXDevice.prototype = { if (value) { numericValue = Math.round(255*value/100); // convert 1..100 to 1..255 for KNX bus } - this.log("Setting "+gaddress+" percentage to %s (%s)", value, numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" percentage to %s (%s)", value, numericValue); this.knxwrite(callback, gaddress,'DPT5',numericValue); } }, setInt: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log("event ping pong, exit!"); +// this.log(gaddress + "event ping pong, exit!"); if (callback) { callback(); } @@ -352,13 +352,13 @@ KNXDevice.prototype = { if (value && value>=0 && value<=255) { numericValue = value; // assure 1..255 for KNX bus } - this.log("Setting "+gaddress+" int to %s (%s)", value, numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" int to %s (%s)", value, numericValue); this.knxwrite(callback, gaddress,'DPT5',numericValue); } }, setFloat: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log(gaddress + " event ping pong, exit!"); +// this.log(gaddress + " event ping pong, exit!"); if (callback) { callback(); } @@ -367,13 +367,13 @@ KNXDevice.prototype = { if (value) { numericValue = value; // homekit expects precision of 1 decimal } - this.log("Setting "+gaddress+" Float to %s", numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" Float to %s", numericValue); this.knxwrite(callback, gaddress,'DPT9',numericValue); } }, setHVACState: function(value, callback, context, gaddress) { if (context === 'fromKNXBus') { - this.log(gaddress + " event ping pong, exit!"); +// this.log(gaddress + " event ping pong, exit!"); if (callback) { callback(); } @@ -396,7 +396,7 @@ KNXDevice.prototype = { KNXvalue = 1; } - this.log("Setting "+gaddress+" HVAC to %s", KNXvalue); + this.log("["+ this.name +"]:Setting "+gaddress+" HVAC to %s", KNXvalue); this.knxwrite(callback, gaddress,'DPT5',KNXvalue); } @@ -405,7 +405,7 @@ KNXDevice.prototype = { * */ identify: function(callback) { - this.log("Identify requested!"); + this.log("["+ this.name +"]:Identify requested!"); callback(); // success }, /** bindCharacteristic @@ -479,10 +479,10 @@ KNXDevice.prototype = { this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic); break; default: - this.log("[ERROR] unknown type passed"); + this.log("[ERROR] unknown type passed: ["+valueType+"]"); throw new Error("[ERROR] unknown type passed"); } - this.log("Issuing read requests on the KNX bus..."); + this.log("["+ this.name +"]:["+myCharacteristic.displayName+"]: Issuing read requests on the KNX bus..."); this.knxreadarray([config.Set].concat(config.Listen || [])); } return myCharacteristic; // for chaining or whatsoever @@ -512,30 +512,30 @@ KNXDevice.prototype = { var myService = new Service.ContactSensor(config.name,config.name); if (config.ContactSensorState) { - this.log("ContactSensor ContactSensorState characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor ContactSensorState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.ContactSensorState); } else if (config.ContactSensorStateContact1) { - this.log("ContactSensor ContactSensorStateContact1 characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor ContactSensorStateContact1 characteristic enabled"); this.bindCharacteristic(myService, Characteristic.ContactSensorState, "BoolReverse", config.ContactSensorStateContact1); } //optionals if (config.StatusActive) { - this.log("ContactSensor StatusActive characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor StatusActive characteristic enabled"); myService.addCharacteristic(Characteristic.StatusActive); this.bindCharacteristic(myService, Characteristic.StatusActive, "Bool", config.StatusActive); } if (config.StatusFault) { - this.log("ContactSensor StatusFault characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor StatusFault characteristic enabled"); myService.addCharacteristic(Characteristic.StatusFault); this.bindCharacteristic(myService, Characteristic.StatusFault, "Bool", config.StatusFault); } if (config.StatusTampered) { - this.log("ContactSensor StatusTampered characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor StatusTampered characteristic enabled"); myService.addCharacteristic(Characteristic.StatusTampered); this.bindCharacteristic(myService, Characteristic.StatusTampered, "Bool", config.StatusTampered); } if (config.StatusLowBattery) { - this.log("ContactSensor StatusLowBattery characteristic enabled"); + this.log("["+ this.name +"]:ContactSensor StatusLowBattery characteristic enabled"); myService.addCharacteristic(Characteristic.StatusLowBattery); this.bindCharacteristic(myService, Characteristic.StatusLowBattery, "Bool", config.StatusLowBattery); } @@ -573,27 +573,27 @@ KNXDevice.prototype = { var myService = new Service.GarageDoorOpener(config.name,config.name); if (config.CurrentDoorState) { - this.log("GarageDoorOpener CurrentDoorState characteristic enabled"); + this.log("["+ this.name +"]:GarageDoorOpener CurrentDoorState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentDoorState, "Int", config.CurrentDoorState); } if (config.TargetDoorState) { - this.log("GarageDoorOpener TargetDoorState characteristic enabled"); + this.log("["+ this.name +"]:GarageDoorOpener TargetDoorState characteristic enabled"); //myService.getCharacteristic(Characteristic.TargetDoorState).minimumValue=0; // //myService.getCharacteristic(Characteristic.TargetDoorState).maximumValue=4; // this.bindCharacteristic(myService, Characteristic.TargetDoorState, "Int", config.TargetDoorState); } if (config.ObstructionDetected) { - this.log("GarageDoorOpener ObstructionDetected characteristic enabled"); + this.log("["+ this.name +"]:GarageDoorOpener ObstructionDetected characteristic enabled"); this.bindCharacteristic(myService, Characteristic.ObstructionDetected, "Bool", config.ObstructionDetected); } //optionals if (config.LockCurrentState) { - this.log("GarageDoorOpener LockCurrentState characteristic enabled"); + this.log("["+ this.name +"]:GarageDoorOpener LockCurrentState characteristic enabled"); myService.addCharacteristic(Characteristic.LockCurrentState); this.bindCharacteristic(myService, Characteristic.LockCurrentState, "Int", config.LockCurrentState); } if (config.LockTargetState) { - this.log("GarageDoorOpener LockTargetState characteristic enabled"); + this.log("["+ this.name +"]:GarageDoorOpener LockTargetState characteristic enabled"); myService.addCharacteristic(Characteristic.LockTargetState); this.bindCharacteristic(myService, Characteristic.LockTargetState, "Bool", config.LockTargetState); } @@ -614,12 +614,12 @@ KNXDevice.prototype = { var myService = new Service.Lightbulb(config.name,config.name); // On (and Off) if (config.On) { - this.log("Lightbulb on/off characteristic enabled"); + this.log("["+ this.name +"]:Lightbulb on/off characteristic enabled"); this.bindCharacteristic(myService, Characteristic.On, "Bool", config.On); } // On characteristic // Brightness if available if (config.Brightness) { - this.log("Lightbulb Brightness characteristic enabled"); + this.log("["+ this.name +"]:Lightbulb Brightness characteristic enabled"); myService.addCharacteristic(Characteristic.Brightness); // it's an optional this.bindCharacteristic(myService, Characteristic.Brightness, "Percent", config.Brightness); } @@ -641,7 +641,7 @@ KNXDevice.prototype = { var myService = new Service.LightSensor(config.name,config.name); // CurrentTemperature) if (config.CurrentAmbientLightLevel) { - this.log("LightSensor CurrentAmbientLightLevel characteristic enabled"); + this.log("["+ this.name +"]:LightSensor CurrentAmbientLightLevel characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentAmbientLightLevel, "Float", config.CurrentAmbientLightLevel); } return myService; @@ -666,19 +666,19 @@ KNXDevice.prototype = { // LockCurrentState if (config.LockCurrentState) { // for normal contacts: Secured = 1 - this.log("LockMechanism LockCurrentState characteristic enabled"); + this.log("["+ this.name +"]:LockMechanism LockCurrentState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.LockCurrentState, "Bool", config.LockCurrentState); } else if (config.LockCurrentStateSecured0) { // for reverse contacts Secured = 0 - this.log("LockMechanism LockCurrentState characteristic enabled"); + this.log("["+ this.name +"]:LockMechanism LockCurrentState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.LockCurrentState, "BoolReverse", config.LockCurrentStateSecured0); } // LockTargetState if (config.LockTargetState) { - this.log("LockMechanism LockTargetState characteristic enabled"); + this.log("["+ this.name +"]:LockMechanism LockTargetState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.LockTargetState, "Bool", config.LockTargetState); } else if (config.LockTargetStateSecured0) { - this.log("LockMechanism LockTargetState characteristic enabled"); + this.log("["+ this.name +"]:LockMechanism LockTargetState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.LockTargetState, "BoolReverse", config.LockTargetStateSecured0); } @@ -701,27 +701,27 @@ KNXDevice.prototype = { var myService = new Service.MotionSensor(config.name,config.name); if (config.MotionDetected) { - this.log("MotionSensor MotionDetected characteristic enabled"); + this.log("["+ this.name +"]:MotionSensor MotionDetected characteristic enabled"); this.bindCharacteristic(myService, Characteristic.MotionDetected, "Bool", config.MotionDetected); } //optionals if (config.StatusActive) { - this.log("MotionSensor StatusActive characteristic enabled"); + this.log("["+ this.name +"]:MotionSensor StatusActive characteristic enabled"); myService.addCharacteristic(Characteristic.StatusActive); this.bindCharacteristic(myService, Characteristic.StatusActive, "Bool", config.StatusActive); } if (config.StatusFault) { - this.log("MotionSensor StatusFault characteristic enabled"); + this.log("["+ this.name +"]:MotionSensor StatusFault characteristic enabled"); myService.addCharacteristic(Characteristic.StatusFault); this.bindCharacteristic(myService, Characteristic.StatusFault, "Bool", config.StatusFault); } if (config.StatusTampered) { - this.log("MotionSensor StatusTampered characteristic enabled"); + this.log("["+ this.name +"]:MotionSensor StatusTampered characteristic enabled"); myService.addCharacteristic(Characteristic.StatusTampered); this.bindCharacteristic(myService, Characteristic.StatusTampered, "Bool", config.StatusTampered); } if (config.StatusLowBattery) { - this.log("MotionSensor StatusLowBattery characteristic enabled"); + this.log("["+ this.name +"]:MotionSensor StatusLowBattery characteristic enabled"); myService.addCharacteristic(Characteristic.StatusLowBattery); this.bindCharacteristic(myService, Characteristic.StatusLowBattery, "Bool", config.StatusLowBattery); } @@ -744,11 +744,11 @@ KNXDevice.prototype = { var myService = new Service.Outlet(config.name,config.name); // On (and Off) if (config.On) { - this.log("Outlet on/off characteristic enabled"); + this.log("["+ this.name +"]:Outlet on/off characteristic enabled"); this.bindCharacteristic(myService, Characteristic.On, "Bool", config.On); } // OutletInUse characteristic if (config.OutletInUse) { - this.log("Outlet on/off characteristic enabled"); + this.log("["+ this.name +"]:Outlet on/off characteristic enabled"); this.bindCharacteristic(myService, Characteristic.OutletInUse, "Bool", config.OutletInUse); } return myService; @@ -766,7 +766,7 @@ KNXDevice.prototype = { var myService = new Service.Switch(config.name,config.name); // On (and Off) if (config.On) { - this.log("Switch on/off characteristic enabled"); + this.log("["+ this.name +"]:Switch on/off characteristic enabled"); this.bindCharacteristic(myService, Characteristic.On, "Bool", config.On); } // On characteristic @@ -795,7 +795,7 @@ KNXDevice.prototype = { // CurrentTemperature) // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 if (config.CurrentTemperature) { - this.log("Thermostat CurrentTemperature characteristic enabled"); + this.log("["+ this.name +"]:Thermostat CurrentTemperature characteristic enabled"); myService.getCharacteristic(Characteristic.CurrentTemperature).setProps({ minValue: config.CurrentTemperature.minValue || -40, maxValue: config.CurrentTemperature.maxValue || 60 @@ -804,7 +804,7 @@ KNXDevice.prototype = { } // TargetTemperature if available if (config.TargetTemperature) { - this.log("Thermostat TargetTemperature characteristic enabled"); + this.log("["+ this.name +"]:Thermostat TargetTemperature characteristic enabled"); // default boundary too narrow for thermostats // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 myService.getCharacteristic(Characteristic.TargetTemperature).setProps({ @@ -816,12 +816,12 @@ KNXDevice.prototype = { } // HVAC if (config.CurrentHeatingCoolingState) { - this.log("Thermostat CurrentHeatingCoolingState characteristic enabled"); + this.log("["+ this.name +"]:Thermostat CurrentHeatingCoolingState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentHeatingCoolingState, "HVAC", config.CurrentHeatingCoolingState); } // HVAC if (config.TargetHeatingCoolingState) { - this.log("Thermostat TargetHeatingCoolingState characteristic enabled"); + this.log("["+ this.name +"]:Thermostat TargetHeatingCoolingState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.TargetHeatingCoolingState, "HVAC", config.TargetHeatingCoolingState); } return myService; @@ -841,7 +841,7 @@ KNXDevice.prototype = { // CurrentTemperature) // props update for https://github.com/KhaosT/HAP-NodeJS/commit/1d84d128d1513beedcafc24d2c07d98185563243#diff-cb84de3a1478a38b2cf8388d709f1c1cR108 if (config.CurrentTemperature) { - this.log("Thermostat CurrentTemperature characteristic enabled"); + this.log("["+ this.name +"]:TemperatureSensor CurrentTemperature characteristic enabled"); myService.getCharacteristic(Characteristic.CurrentTemperature).setProps({ minValue: config.CurrentTemperature.minValue || -40, maxValue: config.CurrentTemperature.maxValue || 60 @@ -878,15 +878,15 @@ KNXDevice.prototype = { var myService = new Service.Window(config.name,config.name); if (config.CurrentPosition) { - this.log("Window CurrentPosition characteristic enabled"); + this.log("["+ this.name +"]:Window CurrentPosition characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.CurrentPosition); } if (config.TargetPosition) { - this.log("Window TargetPosition characteristic enabled"); + this.log("["+ this.name +"]:Window TargetPosition characteristic enabled"); this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.TargetPosition); } if (config.PositionState) { - this.log("Window PositionState characteristic enabled"); + this.log("["+ this.name +"]:Window PositionState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.PositionState, "Float", config.PositionState); } return myService; @@ -913,15 +913,15 @@ KNXDevice.prototype = { var myService = new Service.WindowCovering(config.name,config.name); if (config.CurrentPosition) { - this.log("WindowCovering CurrentPosition characteristic enabled"); + this.log("["+ this.name +"]:WindowCovering CurrentPosition characteristic enabled"); this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.CurrentPosition); } if (config.TargetPosition) { - this.log("WindowCovering TargetPosition characteristic enabled"); + this.log("["+ this.name +"]:WindowCovering TargetPosition characteristic enabled"); this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.TargetPosition); } if (config.PositionState) { - this.log("WindowCovering PositionState characteristic enabled"); + this.log("["+ this.name +"]:WindowCovering PositionState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.PositionState, "Float", config.PositionState); } return myService; @@ -943,7 +943,7 @@ KNXDevice.prototype = { informationService .setCharacteristic(Characteristic.Manufacturer, "Opensource Community") .setCharacteristic(Characteristic.Model, "KNX Universal Device") - .setCharacteristic(Characteristic.SerialNumber, "Version 1.1.2"); + .setCharacteristic(Characteristic.SerialNumber, "Version 1.1.4"); accessoryServices.push(informationService); @@ -998,8 +998,8 @@ KNXDevice.prototype = { accessoryServices.push(this.getWindowCoveringService(configService)); break; default: - this.log("[ERROR] unknown 'type' property of '"+configService.type+"' for service "+ configService.name + " in config.json. KNX platform section fault "); - //throw new Error("[ERROR] unknown 'type' property for service "+ configService.name + " in config.json. KNX platform section fault "); + this.log("[ERROR] unknown 'type' property of ["+configService.type+"] for service ["+ configService.name + "] in config.json. KNX platform section fault "); + throw new Error("[ERROR] unknown 'type' property of ["+configService.type+"] for service '"+ configService.name + "' in config.json. KNX platform section fault "); } } // start listening for events on the bus (if not started yet - will prevent itself) diff --git a/platforms/KNX.md b/platforms/KNX.md index bab706d..0b4d4e9 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -47,7 +47,7 @@ You have to add services in the following syntax: { "type": "SERVICENAME", "description": "This is just for you to remember things", - "name": "We need a name for each service, though it usually shows only if multiple services are present in one accessory", + "name": "beer tap thermostat", "CHARACTERISTIC1": { "Set": "1/1/6", "Listen": [ @@ -68,6 +68,35 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres `"Listen":["1/2/3","1/2/4","1/2/5"]` is an array of addresses that are listened to additionally. To these addresses never values get written, but the on startup the service will issue *KNX read requests* to ALL addresses listed in `Set:` and in `Listen:` +For two characteristics there are additional minValue and maxValue attributes. These are CurrentTemperature and TargetTemperature, and are used in TemperatureSensor and Thermostat. + +So the charcteristic section may look like: + + ````json + { + "type": "Thermostat", + "description": "Sample thermostat", + "name": "We need a name for each service, though it usually shows only if multiple services are present in one accessory", + "CurrentTemperature": { + "Set": "1/1/6", + "Listen": [ + "1/1/63" + ], + minValue: -18, + maxValue: 30 + }, + "TargetTemperature": { + "Set": "1/1/62", + "Listen": [ + "1/1/64" + ], + minValue: -4, + maxValue: 12 + } + } +```` + + # Supported Services and their characteristics ## ContactSensor @@ -139,7 +168,7 @@ Two kinds of addresses are supported: `"Set":"1/2/3"` is a writable group addres - CurrentTemperature: DPT9.001 in °C [listen only] ## Thermostat -- CurrentTemperature: DPT9.001 in °C [listen only] +- CurrentTemperature: DPT9.001 in °C [listen only], -40 to 80°C if not overriden as shown above - TargetTemperature: DPT9.001, values 0..40°C only, all others are ignored - CurrentHeatingCoolingState: DPT20.102 HVAC, because of the incompatible mapping only off and heating (=auto) are shown, [listen only] - TargetHeatingCoolingState: DPT20.102 HVAC, as above From 1fce5c875439a9a61a9f1ff4f7c483aedba440e0 Mon Sep 17 00:00:00 2001 From: Jon Maddox Date: Thu, 1 Oct 2015 01:29:42 -0400 Subject: [PATCH 27/30] ignore hiddent Home Assistant devices --- platforms/HomeAssistant.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/platforms/HomeAssistant.js b/platforms/HomeAssistant.js index 5a23ab5..61d3bc2 100644 --- a/platforms/HomeAssistant.js +++ b/platforms/HomeAssistant.js @@ -152,15 +152,24 @@ HomeAssistantPlatform.prototype = { entity = data[i] entity_type = entity.entity_id.split('.')[0] + // ignore devices that are not in the list of supported types if (that.supportedTypes.indexOf(entity_type) == -1) { continue; } + // ignore hidden devices + if (entity.attributes && entity.attributes.hidden) { + continue; + } + var accessory = null if (entity_type == 'light') { accessory = new HomeAssistantLight(that.log, entity, that) }else if (entity_type == 'switch'){ + console.log(JSON.stringify(entity)) + console.log(""); + console.log(""); accessory = new HomeAssistantSwitch(that.log, entity, that) }else if (entity_type == 'scene'){ accessory = new HomeAssistantSwitch(that.log, entity, that, 'scene') From 45f40874efd315c0aa7ecb145c521f3a6ac5ef92 Mon Sep 17 00:00:00 2001 From: Mikulas Date: Thu, 1 Oct 2015 23:22:17 +0200 Subject: [PATCH 28/30] add lifx to sample config --- config-sample.json | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config-sample.json b/config-sample.json index 6f24554..7af74db 100644 --- a/config-sample.json +++ b/config-sample.json @@ -89,14 +89,19 @@ "delay": 30, "repeat": 3, "zones":["Kitchen Lamp","Bedroom Lamp","Living Room Lamp","Hallway Lamp"] - }, - { + }, + { "platform": "HomeAssistant", "name": "HomeAssistant", "host": "http://192.168.1.10:8123", "password": "XXXXX", "supported_types": ["light", "switch", "media_player", "scene"] - } + }, + { + "platform": "LIFx", + "name": "LIFx", + "access_token": "XXXXXXXX generate at https://cloud.lifx.com/settings" + } ], "accessories": [ From fd72307384a432ac84123b4267cc12b1b64abef5 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 2 Oct 2015 08:17:59 +0200 Subject: [PATCH 29/30] Fix hint in KNX-sample-config.json --- platforms/KNX-sample-config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platforms/KNX-sample-config.json b/platforms/KNX-sample-config.json index 86e070b..05b7e15 100644 --- a/platforms/KNX-sample-config.json +++ b/platforms/KNX-sample-config.json @@ -8,7 +8,7 @@ "description": "This is an example configuration file for KNX platform shim", "hint": "Always paste into jsonlint.com validation page before starting your homebridge, saves a lot of frustration", "hint2": "Replace all group addresses by current addresses of your installation, these are arbitrary examples!", - "hint3": "For valid services and their characteristics have a look at the knxdevice.md file in folder accessories!", + "hint3": "For valid services and their characteristics have a look at the KNX.md file in folder platforms!", "platforms": [ { "platform": "KNX", From 3031ba7e0fdcf78251aa0691219b2b71d01f8434 Mon Sep 17 00:00:00 2001 From: Snowdd1 Date: Fri, 2 Oct 2015 18:05:40 +0200 Subject: [PATCH 30/30] Refactoring of reversely used group addresses The use of 0/1 for binary objects depends on installation, a contact sensor can have contact=1 or open=1 The same applies to percentages: a window can be 100% closed or 100% open. For a more general usage of reversed values, a suffix ("R") can now be attached to all DPT1 and DPT5 group addresses. Please see updated KNX.md for examples and details. Note: outdated characteristic-workaround throw an exception at boot-up: - ContactSensorStateContact1 - LockCurrentStateSecured0 - LockTargetStateSecured0 Please see error message and KNX.md for reference. --- accessories/knxdevice.js | 162 +++++++++++++++++-------------- platforms/KNX-sample-config.json | 10 +- platforms/KNX.js | 17 ++-- platforms/KNX.md | 30 ++++-- 4 files changed, 127 insertions(+), 92 deletions(-) diff --git a/accessories/knxdevice.js b/accessories/knxdevice.js index b2967c2..4656522 100644 --- a/accessories/knxdevice.js +++ b/accessories/knxdevice.js @@ -14,6 +14,9 @@ New 2015-09-18: New 2015-09-19: - GarageDoorOpener Service - MotionSensor Service +New 2015-10-02: +- Check for valid group addresses +- new "R" flag allowed for Boolean addresses: 1/2/3R is the boolean not(1/2/3), i.e. 0 and 1 switched on read and write * */ var Service = require("HAP-NodeJS").Service; @@ -24,6 +27,8 @@ var knxd_startMonitor = require('../platforms/KNX.js').startMonitor; var milliTimeout = 300; // used to block responses while swiping +var colorOn = "\x1b[30;47m"; +var colorOff = "\x1b[0m"; function KNXDevice(log, config) { this.log = log; @@ -115,6 +120,7 @@ KNXDevice.prototype = { if (!groupAddress) { return null; } + this.log("[knxdevice:knxread] preparing knx request for "+groupAddress); var knxdConnection = new knxd.Connection(); // this.log("DEBUG in knxread: created empty connection, trying to connect socket to "+this.knxd_ip+":"+this.knxd_port); knxdConnection.socketRemote({ host: this.knxd_ip, port: this.knxd_port }, function() { @@ -130,7 +136,7 @@ KNXDevice.prototype = { if (err) { this.log("[ERROR] knxread:sendAPDU: " + err); } else { - this.log("knx request sent for "+groupAddress); + this.log("[knxdevice:knxread] knx request sent for "+groupAddress); } }.bind(this)); } @@ -143,12 +149,12 @@ KNXDevice.prototype = { // handle multiple addresses for (var i = 0; i < groupAddresses.length; i++) { if (groupAddresses[i]) { // do not bind empty addresses - this.knxread (groupAddresses[i]); + this.knxread (groupAddresses[i].match(/(\d*\/\d*\/\d*)/)[0]); // clean address } } } else { // it's only one - this.knxread (groupAddresses); + this.knxread (groupAddresses.match(/(\d*\/\d*\/\d*)/)[0]); // regex for cleaning address } }, @@ -158,38 +164,30 @@ KNXDevice.prototype = { // boolean: get 0 or 1 from the bus, write boolean knxregister_bool: function(addresses, characteristic) { this.log("knx registering BOOLEAN " + addresses); - knxd_registerGA(addresses, function(val, src, dest, type){ + knxd_registerGA(addresses, function(val, src, dest, type, reverse){ this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); // iterate(characteristic); - characteristic.setValue(val ? 1 : 0, undefined, 'fromKNXBus'); - }.bind(this)); - }, - knxregister_boolReverse: function(addresses, characteristic) { - this.log("knx registering BOOLEAN " + addresses); - knxd_registerGA(addresses, function(val, src, dest, type){ - this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); -// iterate(characteristic); - characteristic.setValue(val ? 0 : 1, undefined, 'fromKNXBus'); + + characteristic.setValue(val ? (reverse ? 0:1) : (reverse ? 1:0), undefined, 'fromKNXBus'); }.bind(this)); }, +// knxregister_boolReverse: function(addresses, characteristic) { +// this.log("knx registering BOOLEAN REVERSE " + addresses); +// knxd_registerGA(addresses, function(val, src, dest, type, reverse){ +// this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type + " for " + characteristic.displayName); +//// iterate(characteristic); +// characteristic.setValue(val ? 0 : 1, undefined, 'fromKNXBus'); +// }.bind(this)); +// }, // percentage: get 0..255 from the bus, write 0..100 to characteristic knxregister_percent: function(addresses, characteristic) { this.log("knx registering PERCENT " + addresses); - knxd_registerGA(addresses, function(val, src, dest, type){ + knxd_registerGA(addresses, function(val, src, dest, type, reverse){ this.log("[" +this.name + "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); if (type !== "DPT5") { this.log("[ERROR] Received value cannot be a percentage value"); } else { -// if (!characteristic.timeout) { -// if (characteristic.timeout < Date.now()) { - characteristic.setValue(Math.round(val/255*100), undefined, 'fromKNXBus'); -// } else { -// this.log("Blackout time"); -// } -// } else { -// characteristic.setValue(Math.round(val/255*100), undefined, 'fromKNXBus'); -// } // todo get the boolean logic right into one OR expresssion - + characteristic.setValue(Math.round(( reverse ? (255-val):val)/255*100), undefined, 'fromKNXBus'); } }.bind(this)); }, @@ -200,7 +198,7 @@ KNXDevice.prototype = { var validValue = true; var hk_value = 0.0; this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering FLOAT " + addresses); - knxd_registerGA(addresses, function(val, src, dest, type){ + knxd_registerGA(addresses, function(val, src, dest, type, reverse){ this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); // make hk_value compliant to properties if (characteristic.props.minStep) { @@ -227,10 +225,10 @@ KNXDevice.prototype = { //integer knxregister_int: function(addresses, characteristic) { this.log("["+ this.name +"]:[" + characteristic.displayName+ "]:knx registering INT " + addresses); - knxd_registerGA(addresses, function(val, src, dest, type){ + knxd_registerGA(addresses, function(val, src, dest, type, reverse){ this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Received value from bus:"+val+ " for " +dest+ " from "+src+" of type "+type+ " for " + characteristic.displayName); if (val>=(characteristic.props.minValue || 0) && val<=(characteristic.props.maxValue || 255)) { - characteristic.setValue(val, undefined, 'fromKNXBus'); + characteristic.setValue(reverse ? (255-val):val, undefined, 'fromKNXBus'); } else { this.log("["+ this.name +"]:[" + characteristic.displayName+ "]: Value %s out of bounds %s...%s ",hk_value, (characteristic.props.minValue || 0), (characteristic.props.maxValue || 255)); } @@ -294,39 +292,39 @@ KNXDevice.prototype = { * }.bind(this)); * */ - setBooleanState: function(value, callback, context, gaddress) { + setBooleanState: function(value, callback, context, gaddress, reverseflag) { if (context === 'fromKNXBus') { // this.log(gaddress + " event ping pong, exit!"); if (callback) { callback(); } } else { - var numericValue = 0; + var numericValue = reverseflag ? 1:0; if (value) { - numericValue = 1; // need 0 or 1, not true or something + numericValue = reverseflag ? 0:1; // need 0 or 1, not true or something } - this.log("["+ this.name +"]:Setting "+gaddress+" Boolean to %s", numericValue); + this.log("["+ this.name +"]:Setting "+gaddress+" " + reverseflag ? " (reverse)":""+ " Boolean to %s", numericValue); this.knxwrite(callback, gaddress,'DPT1',numericValue); } }, - setBooleanReverseState: function(value, callback, context, gaddress) { - if (context === 'fromKNXBus') { -// this.log(gaddress + " event ping pong, exit!"); - if (callback) { - callback(); - } - } else { - var numericValue = 0; - if (!value) { - numericValue = 1; // need 0 or 1, not true or something - } - this.log("["+ this.name +"]:Setting "+gaddress+" Boolean to %s", numericValue); - this.knxwrite(callback, gaddress,'DPT1',numericValue); - } - - }, - setPercentage: function(value, callback, context, gaddress) { +// setBooleanReverseState: function(value, callback, context, gaddress) { +// if (context === 'fromKNXBus') { +//// this.log(gaddress + " event ping pong, exit!"); +// if (callback) { +// callback(); +// } +// } else { +// var numericValue = 0; +// if (!value) { +// numericValue = 1; // need 0 or 1, not true or something +// } +// this.log("["+ this.name +"]:Setting "+gaddress+" Boolean to %s", numericValue); +// this.knxwrite(callback, gaddress,'DPT1',numericValue); +// } +// +// }, + setPercentage: function(value, callback, context, gaddress, reverseflag) { if (context === 'fromKNXBus') { // this.log(gaddress + "event ping pong, exit!"); if (callback) { @@ -334,8 +332,11 @@ KNXDevice.prototype = { } } else { var numericValue = 0; - if (value) { - numericValue = Math.round(255*value/100); // convert 1..100 to 1..255 for KNX bus + value = ( value>=0 ? (value<=100 ? value:100):0 ); //ensure range 0..100 + if (reverseflag) { + numericValue = 255 - Math.round(255*value/100); // convert 0..100 to 255..0 for KNX bus + } else { + numericValue = Math.round(255*value/100); // convert 0..100 to 0..255 for KNX bus } this.log("["+ this.name +"]:Setting "+gaddress+" percentage to %s (%s)", value, numericValue); this.knxwrite(callback, gaddress,'DPT5',numericValue); @@ -350,7 +351,7 @@ KNXDevice.prototype = { } else { var numericValue = 0; if (value && value>=0 && value<=255) { - numericValue = value; // assure 1..255 for KNX bus + numericValue = value; // assure 0..255 for KNX bus } this.log("["+ this.name +"]:Setting "+gaddress+" int to %s (%s)", value, numericValue); this.knxwrite(callback, gaddress,'DPT5',numericValue); @@ -411,27 +412,44 @@ KNXDevice.prototype = { /** bindCharacteristic * initializes callbacks for 'set' events (from HK) and for KNX bus reads (to HK) */ - bindCharacteristic: function(myService, characteristicType, valueType, config) { + bindCharacteristic: function(myService, characteristicType, valueType, config, defaultValue) { var myCharacteristic = myService.getCharacteristic(characteristicType); + var setGA = ""; + var setReverse = false; if (myCharacteristic === undefined) { throw new Error("unknown characteristics cannot be bound"); } + if (defaultValue) { + myCharacteristic.setValue(defaultValue); + } if (config.Set) { // can write + // extract address and Reverse flag + setGA = config.Set.match(/\d*\/\d*\/\d*/); + if (setGA===null) { + this.log(colorOn + "["+ this.name +"]:["+myCharacteristic.displayName+"] Error in group adress: ["+ config.Set +"] "+colorOff); + throw new Error("EINVGROUPADRESS - Invalid group address given"); + } else { + setGA=setGA[0]; // first element of returned array is the group address + } + + setReverse = config.Set.match(/\d*\/\d*\/\d*(R)/) ? true:false; + switch (valueType) { case "Bool": myCharacteristic.on('set', function(value, callback, context) { - this.setBooleanState(value, callback, context, config.Set); - }.bind(this)); - break; - case "BoolReverse": - myCharacteristic.on('set', function(value, callback, context) { - this.setBooleanReverseState(value, callback, context, config.Set); + this.setBooleanState(value, callback, context, setGA, setReverse); //NEW }.bind(this)); break; +// case "BoolReverse": +// this.log("["+ this.name +"]:["+myCharacteristic.displayName+"] \x1b[30;47m%s\x1b[0mWARNING in group adress: "+ config.Set +": Legacy BoolReverse used. Use " + config.Set +"R instead"); +// myCharacteristic.on('set', function(value, callback, context) { +// this.setBooleanReverseState(value, callback, context, config.Set); +// }.bind(this)); +// break; case "Percent": myCharacteristic.on('set', function(value, callback, context) { - this.setPercentage(value, callback, context, config.Set); + this.setPercentage(value, callback, context, setGA, setReverse); myCharacteristic.timeout = Date.now()+milliTimeout; }.bind(this)); break; @@ -451,7 +469,7 @@ KNXDevice.prototype = { }.bind(this)); break; default: { - this.log("[ERROR] unknown type passed"); + this.log(colorOn + "[ERROR] unknown type passed: [" + valueType+"]"+ colorOff); throw new Error("[ERROR] unknown type passed"); } } @@ -463,9 +481,9 @@ KNXDevice.prototype = { case "Bool": this.knxregister_bool([config.Set].concat(config.Listen || []), myCharacteristic); break; - case "BoolReverse": - this.knxregister_boolReverse([config.Set].concat(config.Listen || []), myCharacteristic); - break; +// case "BoolReverse": +// this.knxregister_boolReverse([config.Set].concat(config.Listen || []), myCharacteristic); +// break; case "Percent": this.knxregister_percent([config.Set].concat(config.Listen || []), myCharacteristic); break; @@ -479,8 +497,8 @@ KNXDevice.prototype = { this.knxregister_HVAC([config.Set].concat(config.Listen || []), myCharacteristic); break; default: - this.log("[ERROR] unknown type passed: ["+valueType+"]"); - throw new Error("[ERROR] unknown type passed"); + this.log(colorOn+ "[ERROR] unknown type passed: ["+valueType+"]"+colorOff); + throw new Error("[ERROR] unknown type passed"); } this.log("["+ this.name +"]:["+myCharacteristic.displayName+"]: Issuing read requests on the KNX bus..."); this.knxreadarray([config.Set].concat(config.Listen || [])); @@ -515,8 +533,8 @@ KNXDevice.prototype = { this.log("["+ this.name +"]:ContactSensor ContactSensorState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.ContactSensorState); } else if (config.ContactSensorStateContact1) { - this.log("["+ this.name +"]:ContactSensor ContactSensorStateContact1 characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.ContactSensorState, "BoolReverse", config.ContactSensorStateContact1); + this.log(colorOn+ "[ERROR] outdated type passed: [ContactSensorStateContact1]"+colorOff); + throw new Error("[ERROR] outdated type passed"); } //optionals if (config.StatusActive) { @@ -670,16 +688,16 @@ KNXDevice.prototype = { this.bindCharacteristic(myService, Characteristic.LockCurrentState, "Bool", config.LockCurrentState); } else if (config.LockCurrentStateSecured0) { // for reverse contacts Secured = 0 - this.log("["+ this.name +"]:LockMechanism LockCurrentState characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.LockCurrentState, "BoolReverse", config.LockCurrentStateSecured0); + this.log(colorOn+ "[ERROR] outdated type passed: [LockCurrentStateSecured0]"+colorOff); + throw new Error("[ERROR] outdated type passed"); } // LockTargetState if (config.LockTargetState) { this.log("["+ this.name +"]:LockMechanism LockTargetState characteristic enabled"); this.bindCharacteristic(myService, Characteristic.LockTargetState, "Bool", config.LockTargetState); } else if (config.LockTargetStateSecured0) { - this.log("["+ this.name +"]:LockMechanism LockTargetState characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.LockTargetState, "BoolReverse", config.LockTargetStateSecured0); + this.log(colorOn+ "[ERROR] outdated type passed: [LockTargetStateSecured0]"+colorOff); + throw new Error("[ERROR] outdated type passed"); } //iterate(myService); @@ -887,7 +905,7 @@ KNXDevice.prototype = { } if (config.PositionState) { this.log("["+ this.name +"]:Window PositionState characteristic enabled"); - this.bindCharacteristic(myService, Characteristic.PositionState, "Float", config.PositionState); + this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.PositionState); } return myService; }, diff --git a/platforms/KNX-sample-config.json b/platforms/KNX-sample-config.json index 05b7e15..eda2fe3 100644 --- a/platforms/KNX-sample-config.json +++ b/platforms/KNX-sample-config.json @@ -61,13 +61,13 @@ "services": [ { "type": "LockMechanism", - "description": "iOS8 Lock mechanism, Supports LockCurrentStateSecured0 OR LockCurrentState, LockTargetStateSecured0 OR LockTargetState, use depending if LOCKED is 0 or 1", + "description": "iOS8 Lock mechanism, Supports LockCurrentState, LockTargetState, append R to the addresses if LOCKED is 1", "name": "Office Window Lock", - "LockCurrentStateSecured0": { - "Listen": "5/3/15" + "LockCurrentState": { + "Listen": "5/3/15R" }, - "LockTargetStateSecured0": { - "Listen": "5/3/15" + "LockTargetState": { + "Listen": "5/3/16R" } } ] diff --git a/platforms/KNX.js b/platforms/KNX.js index 573b3b9..65f7a13 100644 --- a/platforms/KNX.js +++ b/platforms/KNX.js @@ -116,8 +116,8 @@ function groupsocketlisten(opts, callback) { } -var registerSingleGA = function registerSingleGA (groupAddress, callback) { - subscriptions.push({address: groupAddress, callback: callback }); +var registerSingleGA = function registerSingleGA (groupAddress, callback, reverse) { + subscriptions.push({address: groupAddress, callback: callback, reverse:reverse }); } /* @@ -143,7 +143,7 @@ var startMonitor = function startMonitor(opts) { // using { host: name-ip, port if (subscriptions[i].address === dest) { // found one, notify console.log('HIT: Write from '+src+' to '+dest+': '+val+' ['+type+']'); - subscriptions[i].callback(val, src, dest, type); + subscriptions[i].callback(val, src, dest, type, subscriptions[i].reverse); } } }); @@ -156,7 +156,7 @@ var startMonitor = function startMonitor(opts) { // using { host: name-ip, port if (subscriptions[i].address === dest) { // found one, notify // console.log('HIT: Response from '+src+' to '+dest+': '+val+' ['+type+']'); - subscriptions[i].callback(val, src, dest, type); + subscriptions[i].callback(val, src, dest, type, subscriptions[i].reverse); } } @@ -185,13 +185,16 @@ var registerGA = function (groupAddresses, callback) { if (groupAddresses.constructor.toString().indexOf("Array") > -1) { // handle multiple addresses for (var i = 0; i < groupAddresses.length; i++) { - if (groupAddresses[i]) { // do not bind empty addresses - registerSingleGA (groupAddresses[i], callback); + if (groupAddresses[i] && groupAddresses[i].match(/(\d*\/\d*\/\d*)/)) { // do not bind empty addresses or invalid addresses + // clean the addresses + registerSingleGA (groupAddresses[i].match(/(\d*\/\d*\/\d*)/)[0], callback,groupAddresses[i].match(/\d*\/\d*\/\d*(R)/) ? true:false ); } } } else { // it's only one - registerSingleGA (groupAddresses, callback); + if (groupAddresses.match(/(\d*\/\d*\/\d*)/)) { + registerSingleGA (groupAddresses.match(/(\d*\/\d*\/\d*)/)[0], callback, groupAddresses[i].match(/\d*\/\d*\/\d*(R)/) ? true:false); + } } // console.log("listeners now: " + subscriptions.length); }; diff --git a/platforms/KNX.md b/platforms/KNX.md index 0b4d4e9..3e649b9 100644 --- a/platforms/KNX.md +++ b/platforms/KNX.md @@ -97,11 +97,25 @@ So the charcteristic section may look like: ```` +## reversal of values for characteristics +In general, all DPT1 types can be reversed. If you need a 1 for "contact" of a contact senser, you can append an "R" to the group address. +Likewise, all percentages of DPT5 can be reversed, if you need a 100% (=255) for window closed, append an "R" to the group address. Do not forget the listening addresses! + ````json + { + "type": "ContactSensor", + "description": "Sample ContactSensor with 1 as contact (0 is Apple's default)", + "name": "WindowContact1", + "ContactSensorState": { + "Listen": [ + "1/1/100R" + ] + } + } +```` # Supported Services and their characteristics - ## ContactSensor -- ContactSensorState: DPT 1.002, 0 as contact **OR** -- ContactSensorStateContact1: DPT 1.002, 1 as contact +- ContactSensorState: DPT 1.002, 0 as contact +- ~~ContactSensorStateContact1: DPT 1.002, 1 as contact~~ - StatusActive: DPT 1.011, 1 as true - StatusFault: DPT 1.011, 1 as true @@ -142,10 +156,10 @@ So the charcteristic section may look like: - CurrentAmbientLightLevel: DPT 9.004, 0 to 100000 Lux ## LockMechanism (This is poorly mapped!) -- LockCurrentState: DPT 1, 1 as secured **OR (but not both:)** -- LockCurrentStateSecured0: DPT 1, 0 as secured -- LockTargetState: DPT 1, 1 as secured **OR** -- LockTargetStateSecured0: DPT 1, 0 as secured +- LockCurrentState: DPT 1, 1 as secured +- ~~LockCurrentStateSecured0: DPT 1, 0 as secured~~ +- LockTargetState: DPT 1, 1 as secured +- ~~LockTargetStateSecured0: DPT 1, 0 as secured~~ *ToDo here: correction of mappings, HomeKit reqires lock states UNSECURED=0, SECURED=1, JAMMED = 2, UNKNOWN=3* @@ -181,7 +195,7 @@ So the charcteristic section may look like: ## WindowCovering - CurrentPosition: DPT5 percentage - TargetPosition: DPT5 percentage -- PositionState: DPT5 value [listen only: 0 Closing, 1 Opening, 2 STopped] +- PositionState: DPT5 value [listen only: 0 Closing, 1 Opening, 2 Stopped] ### not yet supported - HoldPosition