homebridge-delay-switch
Advanced tools
Comparing version 2.0.2 to 2.1.0
39
index.js
@@ -17,2 +17,3 @@ | ||
this.delay = config['delay']; | ||
this.disableSensor = config['disableSensor'] || false; | ||
this.timer; | ||
@@ -39,11 +40,16 @@ this.switchOn = false; | ||
.on('set', this.setOn.bind(this)); | ||
var services = [informationService, this.switchService] | ||
if (!this.disableSensor){ | ||
this.motionService = new Service.MotionSensor(this.name + ' Trigger'); | ||
this.motionService = new Service.MotionSensor(this.name + ' Trigger'); | ||
this.motionService | ||
.getCharacteristic(Characteristic.MotionDetected) | ||
.on('get', this.getMotion.bind(this)); | ||
services.push(this.motionService) | ||
} | ||
this.motionService | ||
.getCharacteristic(Characteristic.MotionDetected) | ||
.on('get', this.getMotion.bind(this)); | ||
return services; | ||
return [informationService, this.switchService, this.motionService]; | ||
} | ||
@@ -60,3 +66,3 @@ | ||
this.motionTriggered = false; | ||
this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(false); | ||
if (!this.disableSensor) this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(false); | ||
@@ -70,11 +76,16 @@ | ||
this.timer = setTimeout(function() { | ||
this.log('Time is Up! Triggering Motion Sensor'); | ||
this.motionTriggered = true; | ||
this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(true); | ||
this.log('Time is Up!'); | ||
this.switchService.getCharacteristic(Characteristic.On).updateValue(false); | ||
this.switchOn = false; | ||
setTimeout(function() { | ||
this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(false); | ||
this.motionTriggered = false; | ||
}.bind(this), 3000); | ||
if (!this.disableSensor) { | ||
this.motionTriggered = true; | ||
this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(true); | ||
this.log('Triggering Motion Sensor'); | ||
setTimeout(function() { | ||
this.motionService.getCharacteristic(Characteristic.MotionDetected).updateValue(false); | ||
this.motionTriggered = false; | ||
}.bind(this), 3000); | ||
} | ||
}.bind(this), this.delay); | ||
@@ -81,0 +92,0 @@ } |
{ | ||
"name": "homebridge-delay-switch", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Delay switches for Homebridge: https://github.com/nfarina/homebridge", | ||
@@ -5,0 +5,0 @@ "license": "ISC", |
@@ -19,2 +19,3 @@ | ||
"name": "DelaySwitch", | ||
"disableSensor": false, | ||
"delay": 5000 | ||
@@ -26,3 +27,7 @@ } | ||
## Why Adding Motion Sensor? | ||
A Motion sensor is created for each accessory in order to be able to cancel the timer and the attached automations. | ||
How it works? you can set the automation to be triggered from the motion sensor instead of the switch OFF command and therefore you can turn OFF the switch and prevent the motion sensor from being triggered or any attached automations. | ||
If you have no use of the sensor you can remove it by adding `"disableSensor": true` to your config. | ||
@@ -29,0 +34,0 @@ ## How it works |
6772
69
68