diff --git a/README.md b/README.md index c7a0982..612d415 100755 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ This plugin currently supports the following services (and characteristics): * Window Covering (current- / target position) * Motion sensor (motion detected) * Occupancy sensor (motion detected) +* Contact Sensor (contact state) ## Requirements * [SmartHomeNG](https://github.com/smarthomeNG/smarthome) @@ -52,36 +53,90 @@ Alpine Linux: (--no-cache example is for building a docker image) ## Configuration You have to create a config.json in .homebridge directory. You'll find that directory in your home folder. This is an example config file which just uses this plugin and some example SmartHomeNG items. - { - "bridge": { - "name": "HomebridgeSH", - "username": "CC:22:3D:E3:CE:32", - "port": 51826, - "pin": "031-45-154" - }, - - "platforms": [ - { - "platform": "SmartHomeNG", - - "name": "SmartHomeNG", - "host": "myshngserver.mydomain", - "accessories": [ - { - "name": "Licht Büro", - "type": "Lightbulb", - "onoff": "EG.Buero.Licht" - }, - { - "name": "Rolladen Büro", - "type": "WindowCovering", - "updown": "EG.Buero.Rolladen.AufAb", - "currentposition": "EG.Buero.Rolladen.Position", - "targetposition": "EG.Buero.Rolladen.Position", - "inverted": true - } - ] - } - ], - "description": "This is my development config file." - } +{ + "bridge": { + "name": "HBDEV", + "username": "CC:22:3D:E3:DE:37", + "port": 51826, + "pin": "031-45-154" + }, + + "platforms": [ + { + "platform": "SmartHomeNG", + + "name": "SmartHomeNG", + "host": "srvsmarthome.xxxx.lu", + "accessories": [ + { + "name": "Temperatur Stube", + "type": "TemperatureSensor", + "currenttemperature": "EG.Stube.Temperatur" + }, + { + "name": "Heizung Bad", + "type": "Thermostat", + "currenttemperature": "OG.Bad.Temperatur", + "targettemperature": "OG.Bad.Temperatur.Sollwert", + "targettemperatureminimum": 18, + "targettemperaturemaximum": 25 + }, + { + "name": "Ventilator Bad", + "type": "Fan", + "onoff": "OG.Bad.Ventilator" + }, + { + "name": "Bürolicht", + "type": "Lightbulb", + "onoff": "EG.Buero.Licht" + }, + { + "name": "Stubenlicht", + "type": "Lightbulb", + "onoff": "EG.Stube.Licht" + }, + { + "name": "Schlafzimmerlicht", + "type": "Lightbulb", + "onoff": "OG.SZSS.Licht", + "brightness": "OG.SZSS.Licht.dimmen" + }, + { + "name": "Rolladen Büro", + "type": "WindowCovering", + "updown": "EG.Buero.Rolladen.AufAb", + "currentposition": "EG.Buero.Rolladen.Position", + "targetposition": "EG.Buero.Rolladen.Position", + "inverted": true + }, + { + "name": "Bewegungsmelder Küche", + "type": "MotionSensor", + "motionstate": "EG.Kueche.Praesenz" + }, + { + "name": "Terassentür Küche", + "type": "ContactSensor", + "contactsensorstate": "EG.Kueche.Tuer", + "inverted": true + }, + { + "name": "Fenster Esszimmer", + "type": "ContactSensor", + "contactsensorstate": "EG.Esszimmer.Fenster", + "inverted": true + }, + { + "name": "Präsenzsmelder Esszimmer", + "type": "OccupancySensor", + "motiondetected": "EG.Esszimmer.Praesenz" + } + + ] + } + ], + + "description": "This is my development config file." + +} diff --git a/index.js b/index.js index 8ed2153..0a0ab34 100755 --- a/index.js +++ b/index.js @@ -163,6 +163,10 @@ SmartHomeNGAccessory.prototype = { serial = this.config.onoff; break; + case 'window': + myServices.push(this.getWindowService(this.config)); + break; + case 'windowcovering': myServices.push(this.getWindowCoveringService(this.config)); break; @@ -176,6 +180,11 @@ SmartHomeNGAccessory.prototype = { myServices.push(this.getMotionSensorService(this.config)); serial = this.config.motiondetected; break; + + case 'contactsensor': + myServices.push(this.getContactSensorService(this.config)); + serial = this.config.contactsensorstate; + break; // If no supported type is found warn user and return empty services default: @@ -234,7 +243,9 @@ SmartHomeNGAccessory.prototype = { shngregister_percent: function(name, shngitem, characteristic, inverted) { this.log("[" + name + "] Registering callback for '" + shngitem + "'."); var callback = function (shngitem, value, inverted) { - //this.log("[" + this.name + "] callback for " + characteristic.displayName); + this.log("[" + this.name + "] callback for " + characteristic.displayName + " with value " + value); + if (value == true) value = 100; + else if (value == false) value = 0; characteristic.setValue(inverted ? 100 - value : value, undefined, 'fromSHNG'); }.bind(this); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted}); @@ -517,6 +528,27 @@ SmartHomeNGAccessory.prototype = { return myService; }, + // Create Window service + getWindowService: function(config) { + //this.log(config); + var myService = new Service.Window(config.name,config.name); + var inverted = false; + if (config.inverted) { + inverted = true; + } + if (config.currentposition) { + this.log("["+ this.name +"] Window CurrentPosition characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.CurrentPosition, "Percent", config.currentposition, inverted); + } + if (config.targetposition) { + this.log("["+ this.name +"] Window TargetPosition characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.TargetPosition, "Percent", config.targetposition, inverted); + } + this.log("["+ this.name +"] Window PositionState characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.PositionState, "Int", config.positionstate, inverted, Characteristic.PositionState.STOPPED); + return myService; + }, + // Create WindowCovering service getWindowCoveringService: function(config) { //this.log(config); @@ -566,5 +598,18 @@ SmartHomeNGAccessory.prototype = { return myService; }, + // Create ContactSensor service + getContactSensorService: function(config) { + var myService = new Service.ContactSensor(config.name,config.name); + var inverted = false; + if (config.inverted) { + inverted = true; + } + if (config.contactsensorstate) { + this.log("["+ this.name +"] ContactSensor ContactSensorState characteristic enabled"); + this.bindCharacteristic(myService, Characteristic.ContactSensorState, "Bool", config.contactsensorstate, inverted); + } + return myService; + }, } diff --git a/package.json b/package.json index 7d069ad..0ed2184 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-smarthomeng", - "version": "1.1.4", + "version": "1.1.5", "description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome", "license": "GPL", "keywords": [