Added ContactSensor (doors, windowx, ...)

This commit is contained in:
Foxi352 2017-05-29 20:50:22 +02:00
parent 70f8c9073d
commit aee98eeb6b
3 changed files with 135 additions and 35 deletions

View File

@ -11,6 +11,7 @@ This plugin currently supports the following services (and characteristics):
* Window Covering (current- / target position) * Window Covering (current- / target position)
* Motion sensor (motion detected) * Motion sensor (motion detected)
* Occupancy sensor (motion detected) * Occupancy sensor (motion detected)
* Contact Sensor (contact state)
## Requirements ## Requirements
* [SmartHomeNG](https://github.com/smarthomeNG/smarthome) * [SmartHomeNG](https://github.com/smarthomeNG/smarthome)
@ -52,10 +53,10 @@ Alpine Linux: (--no-cache example is for building a docker image)
## Configuration ## 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. 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": { "bridge": {
"name": "HomebridgeSH", "name": "HBDEV",
"username": "CC:22:3D:E3:CE:32", "username": "CC:22:3D:E3:DE:37",
"port": 51826, "port": 51826,
"pin": "031-45-154" "pin": "031-45-154"
}, },
@ -65,13 +66,42 @@ You have to create a config.json in .homebridge directory. You'll find that dire
"platform": "SmartHomeNG", "platform": "SmartHomeNG",
"name": "SmartHomeNG", "name": "SmartHomeNG",
"host": "myshngserver.mydomain", "host": "srvsmarthome.xxxx.lu",
"accessories": [ "accessories": [
{ {
"name": "Licht Büro", "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", "type": "Lightbulb",
"onoff": "EG.Buero.Licht" "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", "name": "Rolladen Büro",
"type": "WindowCovering", "type": "WindowCovering",
@ -79,9 +109,34 @@ You have to create a config.json in .homebridge directory. You'll find that dire
"currentposition": "EG.Buero.Rolladen.Position", "currentposition": "EG.Buero.Rolladen.Position",
"targetposition": "EG.Buero.Rolladen.Position", "targetposition": "EG.Buero.Rolladen.Position",
"inverted": true "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." "description": "This is my development config file."
}
}

View File

@ -163,6 +163,10 @@ SmartHomeNGAccessory.prototype = {
serial = this.config.onoff; serial = this.config.onoff;
break; break;
case 'window':
myServices.push(this.getWindowService(this.config));
break;
case 'windowcovering': case 'windowcovering':
myServices.push(this.getWindowCoveringService(this.config)); myServices.push(this.getWindowCoveringService(this.config));
break; break;
@ -177,6 +181,11 @@ SmartHomeNGAccessory.prototype = {
serial = this.config.motiondetected; serial = this.config.motiondetected;
break; 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 // If no supported type is found warn user and return empty services
default: default:
this.log("Ignoring '" + this.name + "' because device type '" + this.config.type + "' is not supported !"); this.log("Ignoring '" + this.name + "' because device type '" + this.config.type + "' is not supported !");
@ -234,7 +243,9 @@ SmartHomeNGAccessory.prototype = {
shngregister_percent: function(name, shngitem, characteristic, inverted) { shngregister_percent: function(name, shngitem, characteristic, inverted) {
this.log("[" + name + "] Registering callback for '" + shngitem + "'."); this.log("[" + name + "] Registering callback for '" + shngitem + "'.");
var callback = function (shngitem, value, inverted) { 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'); characteristic.setValue(inverted ? 100 - value : value, undefined, 'fromSHNG');
}.bind(this); }.bind(this);
monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted}); monitoring.push({name: name, characteristic: characteristic.displayName, item: shngitem, callback: callback, inverted: inverted});
@ -517,6 +528,27 @@ SmartHomeNGAccessory.prototype = {
return myService; 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 // Create WindowCovering service
getWindowCoveringService: function(config) { getWindowCoveringService: function(config) {
//this.log(config); //this.log(config);
@ -566,5 +598,18 @@ SmartHomeNGAccessory.prototype = {
return myService; 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;
},
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "homebridge-smarthomeng", "name": "homebridge-smarthomeng",
"version": "1.1.4", "version": "1.1.5",
"description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome", "description": "Platform plugin for SmartHomeNG: https://github.com/smarthomeNG/smarthome",
"license": "GPL", "license": "GPL",
"keywords": [ "keywords": [