Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability to disable individual sensors #250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ 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)
* `"motion": false` (Motion only)

*If you change one of this values, you maybe need to remove the senssor from the cache by removing it from `http://<homebridge host>:8181`.
It will automaticly be readded after the sensor triggers a value change.*

### Example configuration
```json
"platforms": [
Expand All @@ -145,7 +159,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,
Expand Down
115 changes: 85 additions & 30 deletions accessories/sensors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,75 @@ module.exports = homebridge => {

class ShellyDoorWindowAccessory extends ShellySensorAccessory {
constructor(device, index, config, log) {
super(device, index, config, log, [
new ContactSensorAbility('state'),
new LightSensorAbility('illuminance'),
new MotionSensorAbility('vibration'),
new TiltSensorAbility('tilt'),
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.vibration !== false) {
this.abilities.push(new LightSensorAbility('vibration'))
}

if (config.tilt !== false) {
this.abilities.push(new LightSensorAbility('tilt'))
}

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 MotionSensorAbility('vibration'),
new TiltSensorAbility('tilt'),
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.vibration !== false) {
this.abilities.push(new LightSensorAbility('vibration'))
}

if (config.tilt !== false) {
this.abilities.push(new LightSensorAbility('tilt'))
}

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'))
}
}
}

Expand All @@ -79,11 +118,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', false, null, -1),
])
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'), false, null, -1)
}
}
}

Expand Down Expand Up @@ -149,11 +196,19 @@ module.exports = homebridge => {

class ShellyMotionAccessory extends ShellySensorAccessory {
constructor(device, index, config, log) {
super(device, index, config, log, [
new MotionSensorAbility('motion'),
new LightSensorAbility('illuminance'),
new BatteryAbility('battery'),
])
super(device, index, config, log)

if (config.motion !== false) {
this.abilities.push(new MotionSensorAbility('motion'))
}

if (config.illuminance !== false) {
this.abilities.push(new LightSensorAbility('illuminance'))
}

if (config.battery !== false) {
this.abilities.push(new BatteryAbility('battery'))
}
}
}

Expand Down