mirror of
https://github.com/mtan93/homebridge.git
synced 2026-04-02 22:04:20 +01:00
Added CarbonMonoxide and CarbonDioxide support
- Added CarbonMonoxide and CarbonDioxide sensor support - Added onValues option to all binary sensors - Added uuid_base parameter to all HomeSeer accessories
This commit is contained in:
@@ -17,6 +17,13 @@
|
|||||||
// - Added Battery support
|
// - Added Battery support
|
||||||
// - Added low battery support for all sensors
|
// - Added low battery support for all sensors
|
||||||
// - Added HomeSeer event support (using HomeKit switches...)
|
// - Added HomeSeer event support (using HomeKit switches...)
|
||||||
|
// V0.7 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/13
|
||||||
|
// - You can add multiple HomeKit devices for the same HomeSeer device reference
|
||||||
|
// - Added CarbonMonoxide sensor
|
||||||
|
// - Added CarbonDioxide sensor
|
||||||
|
// - Added onValues option to all binary sensors
|
||||||
|
// V0.8 - Jean-Michel Joudrier (stipus at stipus dot com) - 2015/10/14
|
||||||
|
// - Added uuid_base parameter to all accessories
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Remember to add platform to config.json.
|
// Remember to add platform to config.json.
|
||||||
@@ -35,7 +42,8 @@
|
|||||||
// {
|
// {
|
||||||
// "eventGroup":"My Group", // Required - The HomeSeer event group
|
// "eventGroup":"My Group", // Required - The HomeSeer event group
|
||||||
// "eventName":"My Event", // Required - The HomeSeer event name
|
// "eventName":"My Event", // Required - The HomeSeer event name
|
||||||
// "name":"Test" // Optional - HomeSeer event name is the default
|
// "name":"Test", // Optional - HomeSeer event name is the default
|
||||||
|
// "uuid_base":"SomeUniqueId" // Optional - HomeKit identifier will be derived from this parameter instead of the name
|
||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
//
|
//
|
||||||
@@ -46,7 +54,8 @@
|
|||||||
// "name":"My Light", // Optional - HomeSeer device name is the default
|
// "name":"My Light", // Optional - HomeSeer device name is the default
|
||||||
// "offValue":"0", // Optional - 0 is the default
|
// "offValue":"0", // Optional - 0 is the default
|
||||||
// "onValue":"100", // Optional - 100 is the default
|
// "onValue":"100", // Optional - 100 is the default
|
||||||
// "can_dim":true // Optional - true is the default - false for a non dimmable lightbulb
|
// "can_dim":true, // Optional - true is the default - false for a non dimmable lightbulb
|
||||||
|
// "uuid_base":"SomeUniqueId2" // Optional - HomeKit identifier will be derived from this parameter instead of the name
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// "ref":9 // This is a dimmable Lightbulb by default
|
// "ref":9 // This is a dimmable Lightbulb by default
|
||||||
@@ -64,6 +73,22 @@
|
|||||||
// "batteryThreshold":15 // Optional - If sensor battery level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
// "batteryThreshold":15 // Optional - If sensor battery level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
|
// "ref":34, // Required - HomeSeer Device Reference for your sensor
|
||||||
|
// "type":"SmokeSensor", // Required for a smoke sensor
|
||||||
|
// "name":"Kichen smoke detector", // Optional - HomeSeer device name is the default
|
||||||
|
// "batteryRef":35, // Optional - HomeSeer device reference for the sensor battery level
|
||||||
|
// "batteryThreshold":15, // Optional - If sensor battery level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
||||||
|
// "onValues":[1,1.255] // Optional - List of all HomeSeer values triggering a "ON" sensor state - Default is any value different than 0
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "ref":34, // Required - HomeSeer Device Reference for your sensor (Here it's the same device as the SmokeSensor above)
|
||||||
|
// "type":"CarbonMonoxideSensor", // Required for a carbon monoxide sensor
|
||||||
|
// "name":"Kichen CO detector", // Optional - HomeSeer device name is the default
|
||||||
|
// "batteryRef":35, // Optional - HomeSeer device reference for the sensor battery level
|
||||||
|
// "batteryThreshold":15, // Optional - If sensor battery level is below this value, the HomeKit LowBattery characteristic is set to 1. Default is 10
|
||||||
|
// "onValues":[2,2.255] // Optional - List of all HomeSeer values triggering a "ON" sensor state - Default is any value different than 0
|
||||||
|
// },
|
||||||
|
// {
|
||||||
// "ref":113, // Required - HomeSeer Device Reference of the Current Temperature Device
|
// "ref":113, // Required - HomeSeer Device Reference of the Current Temperature Device
|
||||||
// "type":"Thermostat", // Required for a Thermostat
|
// "type":"Thermostat", // Required for a Thermostat
|
||||||
// "name":"Température Salon", // Optional - HomeSeer device name is the default
|
// "name":"Température Salon", // Optional - HomeSeer device name is the default
|
||||||
@@ -76,10 +101,10 @@
|
|||||||
// "stateCoolValues":[2], // Required - List of the HomeSeer device values for a HomeKit state=COOL
|
// "stateCoolValues":[2], // Required - List of the HomeSeer device values for a HomeKit state=COOL
|
||||||
// "stateAutoValues":[3], // Required - List of the HomeSeer device values for a HomeKit state=AUTO
|
// "stateAutoValues":[3], // Required - List of the HomeSeer device values for a HomeKit state=AUTO
|
||||||
// "controlRef":168, // Required - HomeSeer device reference for your thermostat mode control (It can be the same as stateRef for some thermostats)
|
// "controlRef":168, // Required - HomeSeer device reference for your thermostat mode control (It can be the same as stateRef for some thermostats)
|
||||||
// "controlOffValue":0, // Required - Value for OFF
|
// "controlOffValue":0, // Required - HomeSeer device control value for OFF
|
||||||
// "controlHeatValue":1, // Required - Value for HEAT
|
// "controlHeatValue":1, // Required - HomeSeer device control value for HEAT
|
||||||
// "controlCoolValue":2, // Required - Value for COOL
|
// "controlCoolValue":2, // Required - HomeSeer device control value for COOL
|
||||||
// "controlAutoValue":3, // Required - Value for AUTO
|
// "controlAutoValue":3, // Required - HomeSeer device control value for AUTO
|
||||||
// "coolingThresholdRef":169, // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat cooling threshold
|
// "coolingThresholdRef":169, // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat cooling threshold
|
||||||
// "heatingThresholdRef":170 // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat heating threshold
|
// "heatingThresholdRef":170 // Optional - Not-implemented-yet - HomeSeer device reference for your thermostat heating threshold
|
||||||
// },
|
// },
|
||||||
@@ -95,20 +120,22 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// SUPORTED TYPES:
|
// SUPORTED TYPES:
|
||||||
// - Lightbulb (can_dim, onValue, offValue options)
|
// - Lightbulb (can_dim, onValue, offValue options)
|
||||||
// - Fan (onValue, offValue options)
|
// - Fan (onValue, offValue options)
|
||||||
// - Switch (onValue, offValue options)
|
// - Switch (onValue, offValue options)
|
||||||
// - Outlet (onValue, offValue options)
|
// - Outlet (onValue, offValue options)
|
||||||
// - Thermostat (temperatureUnit, setPoint, state, control options)
|
// - Thermostat (temperatureUnit, setPoint, state, control options)
|
||||||
// - TemperatureSensor (temperatureUnit=C|F)
|
// - TemperatureSensor (temperatureUnit=C|F)
|
||||||
// - ContactSensor (0=no contact, 1=contact - batteryRef, batteryThreshold option)
|
// - HumiditySensor (HomeSeer device value in % - batteryRef, batteryThreshold options)
|
||||||
// - MotionSensor (0=no motion, 1=motion - batteryRef, batteryThreshold option)
|
// - LightSensor (HomeSeer device value in Lux - batteryRef, batteryThreshold options)
|
||||||
// - LeakSensor (0=no leak, 1=leak - batteryRef, batteryThreshold option)
|
// - ContactSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
// - LightSensor (HomeSeer device value in Lux - batteryRef, batteryThreshold option)
|
// - MotionSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
// - HumiditySensor (HomeSeer device value in % - batteryRef, batteryThreshold option)
|
// - LeakSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
// - OccupancySensor (0=no occupancy, 1=occupancy - batteryRef, batteryThreshold option)
|
// - OccupancySensor (onValues, batteryRef, batteryThreshold options)
|
||||||
// - SmokeSensor (0=no smoke, 1=smoke - batteryRef, batteryThreshold option)
|
// - SmokeSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
// - Battery (batteryThreshold option)
|
// - CarbonMonoxideSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
|
// - CarbonDioxideSensor (onValues, batteryRef, batteryThreshold options)
|
||||||
|
// - Battery (batteryThreshold option)
|
||||||
// - Door
|
// - Door
|
||||||
|
|
||||||
|
|
||||||
@@ -163,9 +190,14 @@ HomeSeerPlatform.prototype = {
|
|||||||
else {
|
else {
|
||||||
this.log('HomeSeer status function succeeded!');
|
this.log('HomeSeer status function succeeded!');
|
||||||
var response = JSON.parse( body );
|
var response = JSON.parse( body );
|
||||||
for( var i=0; i<response.Devices.length; i++ ) {
|
for( var i=0; i<this.config.accessories.length; i++ ) {
|
||||||
var accessory = new HomeSeerAccessory( that.log, that.config, response.Devices[i] );
|
for( var j=0; j<response.Devices.length; j++ ) {
|
||||||
foundAccessories.push( accessory );
|
if( this.config.accessories[i].ref == response.Devices[j].ref ) {
|
||||||
|
var accessory = new HomeSeerAccessory( that.log, that.config, this.config.accessories[i], response.Devices[j] );
|
||||||
|
foundAccessories.push( accessory );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
callback( foundAccessories );
|
callback( foundAccessories );
|
||||||
}
|
}
|
||||||
@@ -173,29 +205,25 @@ HomeSeerPlatform.prototype = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function HomeSeerAccessory(log, platformConfig, status ) {
|
function HomeSeerAccessory(log, platformConfig, accessoryConfig, status ) {
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
this.config = accessoryConfig;
|
||||||
this.ref = status.ref;
|
this.ref = status.ref;
|
||||||
this.name = status.name
|
this.name = status.name
|
||||||
this.model = status.device_type_string;
|
this.model = status.device_type_string;
|
||||||
this.onValue = "100";
|
this.onValue = 100;
|
||||||
this.offValue = "0";
|
this.offValue = 0;
|
||||||
|
|
||||||
this.access_url = platformConfig["host"] + "/JSON?";
|
this.access_url = platformConfig["host"] + "/JSON?";
|
||||||
this.control_url = this.access_url + "request=controldevicebyvalue&ref=" + this.ref + "&value=";
|
this.control_url = this.access_url + "request=controldevicebyvalue&ref=" + this.ref + "&value=";
|
||||||
this.status_url = this.access_url + "request=getstatus&ref=" + this.ref;
|
this.status_url = this.access_url + "request=getstatus&ref=" + this.ref;
|
||||||
|
|
||||||
for( var i=0; i<platformConfig.accessories.length; i++ ) {
|
|
||||||
if( platformConfig.accessories[i].ref == this.ref )
|
|
||||||
{
|
|
||||||
this.config = platformConfig.accessories[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if( this.config.name )
|
if( this.config.name )
|
||||||
this.name = this.config.name;
|
this.name = this.config.name;
|
||||||
|
|
||||||
|
if( this.config.uuid_base )
|
||||||
|
this.uuid_base = this.config.uuid_base;
|
||||||
|
|
||||||
if( this.config.onValue )
|
if( this.config.onValue )
|
||||||
this.onValue = this.config.onValue;
|
this.onValue = this.config.onValue;
|
||||||
|
|
||||||
@@ -254,6 +282,35 @@ HomeSeerAccessory.prototype = {
|
|||||||
}.bind(this));
|
}.bind(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getBinarySensorState: function(callback) {
|
||||||
|
var url = this.status_url;
|
||||||
|
|
||||||
|
httpRequest(url, 'GET', function(error, response, body) {
|
||||||
|
if (error) {
|
||||||
|
this.log('HomeSeer get binary sensor state function failed: %s', error.message);
|
||||||
|
callback( error, 0 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var status = JSON.parse( body );
|
||||||
|
var value = status.Devices[0].value;
|
||||||
|
|
||||||
|
this.log('HomeSeer get binary sensor state function succeeded: value=' + value );
|
||||||
|
if( this.config.onValues ) {
|
||||||
|
if( this.config.onValues.indexOf(value) != -1 )
|
||||||
|
callback( null, 1 );
|
||||||
|
else
|
||||||
|
callback( null, 0 );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( value != 0 )
|
||||||
|
callback( null, 1 );
|
||||||
|
else
|
||||||
|
callback( null, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind(this));
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
setValue: function(level, callback) {
|
setValue: function(level, callback) {
|
||||||
var url = this.control_url + level;
|
var url = this.control_url + level;
|
||||||
@@ -534,11 +591,37 @@ HomeSeerAccessory.prototype = {
|
|||||||
services.push( temperatureSensorService );
|
services.push( temperatureSensorService );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "CarbonMonoxideSensor": {
|
||||||
|
var carbonMonoxideSensorService = new Service.CarbonMonoxideSensor();
|
||||||
|
carbonMonoxideSensorService
|
||||||
|
.getCharacteristic(Characteristic.CarbonMonoxideDetected)
|
||||||
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
|
if( this.config.batteryRef ) {
|
||||||
|
carbonMonoxideSensorService
|
||||||
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
|
.on('get', this.getLowBatteryStatus.bind(this));
|
||||||
|
}
|
||||||
|
services.push( carbonMonoxideSensorService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "CarbonDioxideSensor": {
|
||||||
|
var carbonDioxideSensorService = new Service.CarbonDioxideSensor();
|
||||||
|
carbonDioxideSensorService
|
||||||
|
.getCharacteristic(Characteristic.CarbonDioxideDetected)
|
||||||
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
|
if( this.config.batteryRef ) {
|
||||||
|
carbonDioxideSensorService
|
||||||
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
|
.on('get', this.getLowBatteryStatus.bind(this));
|
||||||
|
}
|
||||||
|
services.push( carbonDioxideSensorService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "ContactSensor": {
|
case "ContactSensor": {
|
||||||
var contactSensorService = new Service.ContactSensor();
|
var contactSensorService = new Service.ContactSensor();
|
||||||
contactSensorService
|
contactSensorService
|
||||||
.getCharacteristic(Characteristic.ContactSensorState)
|
.getCharacteristic(Characteristic.ContactSensorState)
|
||||||
.on('get', this.getPowerState.bind(this));
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
if( this.config.batteryRef ) {
|
if( this.config.batteryRef ) {
|
||||||
contactSensorService
|
contactSensorService
|
||||||
.addCharacteristic(new Characteristic.StatusLowBattery())
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
@@ -551,7 +634,7 @@ HomeSeerAccessory.prototype = {
|
|||||||
var motionSensorService = new Service.MotionSensor();
|
var motionSensorService = new Service.MotionSensor();
|
||||||
motionSensorService
|
motionSensorService
|
||||||
.getCharacteristic(Characteristic.MotionDetected)
|
.getCharacteristic(Characteristic.MotionDetected)
|
||||||
.on('get', this.getPowerState.bind(this));
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
if( this.config.batteryRef ) {
|
if( this.config.batteryRef ) {
|
||||||
motionSensorService
|
motionSensorService
|
||||||
.addCharacteristic(new Characteristic.StatusLowBattery())
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
@@ -564,7 +647,7 @@ HomeSeerAccessory.prototype = {
|
|||||||
var leakSensorService = new Service.LeakSensor();
|
var leakSensorService = new Service.LeakSensor();
|
||||||
leakSensorService
|
leakSensorService
|
||||||
.getCharacteristic(Characteristic.LeakDetected)
|
.getCharacteristic(Characteristic.LeakDetected)
|
||||||
.on('get', this.getPowerState.bind(this));
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
if( this.config.batteryRef ) {
|
if( this.config.batteryRef ) {
|
||||||
leakSensorService
|
leakSensorService
|
||||||
.addCharacteristic(new Characteristic.StatusLowBattery())
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
@@ -573,6 +656,32 @@ HomeSeerAccessory.prototype = {
|
|||||||
services.push( leakSensorService );
|
services.push( leakSensorService );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "OccupancySensor": {
|
||||||
|
var occupancySensorService = new Service.OccupancySensor();
|
||||||
|
occupancySensorService
|
||||||
|
.getCharacteristic(Characteristic.OccupancyDetected)
|
||||||
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
|
if( this.config.batteryRef ) {
|
||||||
|
occupancySensorService
|
||||||
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
|
.on('get', this.getLowBatteryStatus.bind(this));
|
||||||
|
}
|
||||||
|
services.push( occupancySensorService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "SmokeSensor": {
|
||||||
|
var smokeSensorService = new Service.SmokeSensor();
|
||||||
|
smokeSensorService
|
||||||
|
.getCharacteristic(Characteristic.SmokeDetected)
|
||||||
|
.on('get', this.getBinarySensorState.bind(this));
|
||||||
|
if( this.config.batteryRef ) {
|
||||||
|
temperatureSensorService
|
||||||
|
.addCharacteristic(new Characteristic.StatusLowBattery())
|
||||||
|
.on('get', this.getLowBatteryStatus.bind(this));
|
||||||
|
}
|
||||||
|
services.push( smokeSensorService );
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "LightSensor": {
|
case "LightSensor": {
|
||||||
var lightSensorService = new Service.LightSensor();
|
var lightSensorService = new Service.LightSensor();
|
||||||
lightSensorService
|
lightSensorService
|
||||||
@@ -599,32 +708,6 @@ HomeSeerAccessory.prototype = {
|
|||||||
services.push( humiditySensorService );
|
services.push( humiditySensorService );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "OccupancySensor": {
|
|
||||||
var occupancySensorService = new Service.OccupancySensor();
|
|
||||||
occupancySensorService
|
|
||||||
.getCharacteristic(Characteristic.OccupancyDetected)
|
|
||||||
.on('get', this.getPowerState.bind(this));
|
|
||||||
if( this.config.batteryRef ) {
|
|
||||||
occupancySensorService
|
|
||||||
.addCharacteristic(new Characteristic.StatusLowBattery())
|
|
||||||
.on('get', this.getLowBatteryStatus.bind(this));
|
|
||||||
}
|
|
||||||
services.push( occupancySensorService );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "SmokeSensor": {
|
|
||||||
var smokeSensorService = new Service.SmokeSensor();
|
|
||||||
smokeSensorService
|
|
||||||
.getCharacteristic(Characteristic.SmokeDetected)
|
|
||||||
.on('get', this.getPowerState.bind(this));
|
|
||||||
if( this.config.batteryRef ) {
|
|
||||||
temperatureSensorService
|
|
||||||
.addCharacteristic(new Characteristic.StatusLowBattery())
|
|
||||||
.on('get', this.getLowBatteryStatus.bind(this));
|
|
||||||
}
|
|
||||||
services.push( smokeSensorService );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "Door": {
|
case "Door": {
|
||||||
var doorService = new Service.Door();
|
var doorService = new Service.Door();
|
||||||
doorService
|
doorService
|
||||||
@@ -708,6 +791,9 @@ function HomeSeerEvent(log, platformConfig, eventConfig ) {
|
|||||||
|
|
||||||
if( this.config.name )
|
if( this.config.name )
|
||||||
this.name = this.config.name;
|
this.name = this.config.name;
|
||||||
|
|
||||||
|
if( this.config.uuid_base )
|
||||||
|
this.uuid_base = this.config.uuid_base;
|
||||||
}
|
}
|
||||||
|
|
||||||
HomeSeerEvent.prototype = {
|
HomeSeerEvent.prototype = {
|
||||||
|
|||||||
Reference in New Issue
Block a user