From debc96c232f8304d90d15f8fb64f5b6071061079 Mon Sep 17 00:00:00 2001 From: Koenkk Date: Tue, 15 May 2018 18:06:16 +0200 Subject: [PATCH] Allow to set device specific occupancy_timeout. #27 --- lib/controller.js | 2 +- lib/converters/zigbee2mqtt.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/controller.js b/lib/controller.js index e6496db2c..49f1ca93a 100644 --- a/lib/controller.js +++ b/lib/controller.js @@ -131,7 +131,7 @@ class Controller { // for e.g. click switches where we need to count number of clicks and detect long presses. converters.forEach((converter) => { const publish = (payload) => this.mqttPublishDeviceState(device.ieeeAddr, payload, converter.disableCache !== true); - const payload = converter.convert(message, publish); + const payload = converter.convert(message, publish, settings.getDevice(device.ieeeAddr)); if (payload) { publish(payload); diff --git a/lib/converters/zigbee2mqtt.js b/lib/converters/zigbee2mqtt.js index 059fa6b4b..2fc2cecd5 100644 --- a/lib/converters/zigbee2mqtt.js +++ b/lib/converters/zigbee2mqtt.js @@ -176,9 +176,10 @@ const parsers = [ devices: ['RTCGQ01LM', 'RTCGQ11LM'], cid: 'msOccupancySensing', type: 'attReport', - convert: (msg, publish) => { + convert: (msg, publish, options) => { // The occupancy sensor only sends a message when motion detected. // Therefore we need to publish the no_motion detected by ourselves. + const timeout = options.occupancy_timeout ? options.occupancy_timeout : occupancyTimeout; const deviceID = msg.endpoints[0].device.ieeeAddr; // Stop existing timer because motion is detected and set a new one. @@ -190,7 +191,7 @@ const parsers = [ store[deviceID] = setTimeout(() => { publish({occupancy: false}) store[deviceID] = null; - }, occupancyTimeout * 1000); + }, timeout * 1000); return {occupancy: true}; } },