homebridge-dafang-mqtt-republish
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -57,2 +57,9 @@ { | ||
"description": "MQTT topic that homebridge-camera-ffmpeg is subscribed to." | ||
}, | ||
"cooldown": { | ||
"title": "Cooldown (Seconds)", | ||
"type": "integer", | ||
"placeholder": 0, | ||
"minimum": 0, | ||
"description": "Set to 0 to disable." | ||
} | ||
@@ -59,0 +66,0 @@ } |
40
index.js
@@ -11,2 +11,9 @@ const mqtt = require('mqtt'); | ||
this.cameras = {}; | ||
this.config.cameras.forEach(camera => { | ||
this.cameras[camera.name] = {}; | ||
this.cameras[camera.name].motion = false; | ||
this.cameras[camera.name].timer = null; | ||
}); | ||
if (api) { | ||
@@ -34,7 +41,32 @@ this.api = api; | ||
if (msg == 'ON') { | ||
this.log.debug('Publishing MQTT Message - ' + camera.homebridge_topic + ': ' + camera.name); | ||
client.publish(camera.homebridge_topic, camera.name); | ||
this.cameras[camera.name].motion = true; | ||
if (!this.cameras[camera.name].timer) { | ||
this.log.debug('Publishing MQTT Message - ' + camera.homebridge_topic + ': ' + camera.name); | ||
client.publish(camera.homebridge_topic, camera.name); | ||
} else { | ||
this.log.debug('Motion set received, but cooldown running: ' + camera.name); | ||
} | ||
if (camera.cooldown > 0) { | ||
if (this.cameras[camera.name].timer) { | ||
this.log.debug('Cancelling existing cooldown timer: ' + camera.name); | ||
clearTimeout(this.cameras[camera.name].timer); | ||
} | ||
this.log.debug('Cooldown enabled, starting timer: ' + camera.name); | ||
this.cameras[camera.name].timer = setTimeout(function() { | ||
this.log.debug('Cooldown finished, motion detected = ' + this.cameras[camera.name].motion + ': ' + camera.name); | ||
if (!this.cameras[camera.name].motion) { | ||
this.log.debug('Publishing MQTT Message - ' + camera.homebridge_topic + '/reset: ' + camera.name); | ||
client.publish(camera.homebridge_topic + '/reset', camera.name); | ||
} | ||
this.cameras[camera.name].timer = null; | ||
}.bind(this), camera.cooldown * 1000); | ||
} | ||
} else if (msg == 'OFF') { | ||
this.log.debug('Publishing MQTT Message - ' + camera.homebridge_topic + '/reset: ' + camera.name); | ||
client.publish(camera.homebridge_topic + '/reset', camera.name); | ||
this.cameras[camera.name].motion = false; | ||
if (!this.cameras[camera.name].timer) { | ||
this.log.debug('Publishing MQTT Message - ' + camera.homebridge_topic + '/reset: ' + camera.name); | ||
client.publish(camera.homebridge_topic + '/reset', camera.name); | ||
} else { | ||
this.log.debug('Motion clear received, but cooldown running: ' + camera.name); | ||
} | ||
} | ||
@@ -41,0 +73,0 @@ } |
{ | ||
"displayName": "Homebridge Dafang MQTT Republish", | ||
"name": "homebridge-dafang-mqtt-republish", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Republishes MQTT Motion Messages from Dafang Hacks into a Format homebridge-camera-ffmpeg Understands", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -42,1 +42,2 @@ # homebridge-dafang-mqtt-republish | ||
| \|- homebridge_topic | MQTT topic that homebridge-camera-ffmpeg is subscribed to. | Yes | | ||
| \|- cooldown | Cooldown in seconds. Set to 0 to disable. | No | |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9820
139
43