From 5520639cff82de2c9e51a7b6b908421861c68182 Mon Sep 17 00:00:00 2001 From: Timo Schilling Date: Sat, 16 Jan 2021 23:20:51 +0100 Subject: [PATCH] add ability to disable individual sensors --- README.md | 16 ++++++++- accessories/sensors.js | 77 ++++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index b9d3358..c4bf187 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,19 @@ interface of a device, under *Settings -> Device info -> Device ID*. * `"colorMode"` - set to `"rgbw"` (default) to have HomeKit control all four channels of the device (R, G, B, and W), or to `"rgb"` to omit the W channel. +#### Shelly senssor configuration +*Applies to DoorWindow / DoorWindow2 / Flood / HT* +Indiciduale sensores of the devises can be disabled: +* `"state": false` (DoorWindow / DoorWindow2 only) +* `"illuminance": false` (DoorWindow / DoorWindow2 only) +* `"temperature": false` (DoorWindow2 / Flood / HT only) +* `"battery": false` +* `"flood": false` (Flood only) +* `"humidity": false` (HT only) + +*If you change one of this values, you maybe need to remove the senssor from the cache by removing it from `http://:8181`. + It will automaticly be readded after the sensor triggers a value change.* + ### Example configuration ```json "platforms": [ @@ -140,7 +153,8 @@ interface of a device, under *Settings -> Device info -> Device ID*. { "id": "A612F0", "username": "admin", "password": "pa$$word2" }, { "id": "6A78BB", "colorMode": "rgb" }, { "id": "AD2214", "name": "My Device" }, - { "id": "1D56AF", "type": "outlet" } + { "id": "1D56AF", "type": "outlet" }, + { "id": "81e421", "temperature": false} ], "admin": { "enabled": true, diff --git a/accessories/sensors.js b/accessories/sensors.js index a849fa4..4c113bc 100644 --- a/accessories/sensors.js +++ b/accessories/sensors.js @@ -30,32 +30,59 @@ module.exports = homebridge => { class ShellyDoorWindowAccessory extends ShellySensorAccessory { constructor(device, index, config, log) { - super(device, index, config, log, [ - new ContactSensorAbility('state'), - new LightSensorAbility('illuminance'), - new BatteryAbility('battery'), - ]) + super(device, index, config, log) + + if (config.state !== false) { + this.abilities.push(new ContactSensorAbility('state')) + } + + if (config.illuminance !== false) { + this.abilities.push(new LightSensorAbility('illuminance')) + } + + if (config.battery !== false) { + this.abilities.push(new BatteryAbility('battery')) + } } } class ShellyDoorWindow2Accessory extends ShellySensorAccessory { constructor(device, index, config, log) { - super(device, index, config, log, [ - new ContactSensorAbility('state'), - new LightSensorAbility('illuminance'), - new TemperatureSensorAbility('temperature'), - new BatteryAbility('battery') - ]) + super(device, index, config, log) + + if (config.state !== false) { + this.abilities.push(new ContactSensorAbility('state')) + } + + if (config.illuminance !== false) { + this.abilities.push(new LightSensorAbility('illuminance')) + } + + if (config.temperature !== false) { + this.abilities.push(new TemperatureSensorAbility('temperature')) + } + + if (config.battery !== false) { + this.abilities.push(new BatteryAbility('battery')) + } } } class ShellyFloodAccessory extends ShellySensorAccessory { constructor(device, index, config, log) { - super(device, index, config, log, [ - new LeakSensorAbility('flood'), - new TemperatureSensorAbility('temperature'), - new BatteryAbility('battery'), - ]) + super(device, index, config, log) + + if (config.flood !== false) { + this.abilities.push(new LeakSensorAbility('flood')) + } + + if (config.temperature !== false) { + this.abilities.push(new TemperatureSensorAbility('temperature')) + } + + if (config.battery !== false) { + this.abilities.push(new BatteryAbility('battery')) + } } } @@ -74,11 +101,19 @@ module.exports = homebridge => { class ShellyHTAccessory extends ShellySensorAccessory { constructor(device, index, config, log) { - super(device, index, config, log, [ - new TemperatureSensorAbility('temperature'), - new HumiditySensorAbility('humidity'), - new BatteryAbility('battery'), - ]) + super(device, index, config, log) + + if (config.temperature !== false) { + this.abilities.push(new TemperatureSensorAbility('temperature')) + } + + if (config.humidity !== false) { + this.abilities.push(new HumiditySensorAbility('humidity')) + } + + if (config.battery !== false) { + this.abilities.push(new BatteryAbility('battery')) + } } }