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)
* Motion sensor (motion detected)
* Occupancy sensor (motion detected)
* Contact Sensor (contact state)
## Requirements
* [SmartHomeNG](https://github.com/smarthomeNG/smarthome)
@ -52,10 +53,10 @@ 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",
"name": "HBDEV",
"username": "CC:22:3D:E3:DE:37",
"port": 51826,
"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",
"name": "SmartHomeNG",
"host": "myshngserver.mydomain",
"host": "srvsmarthome.xxxx.lu",
"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",
"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",
@ -79,9 +109,34 @@ You have to create a config.json in .homebridge directory. You'll find that dire
"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."
}
}

View File

@ -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;
@ -177,6 +181,11 @@ SmartHomeNGAccessory.prototype = {
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:
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) {
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;
},
}

View File

@ -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": [