From beddabb1ae75b817ad7a70506d1799a72bcec3a0 Mon Sep 17 00:00:00 2001 From: Keith G <33558908+veeceeoh@users.noreply.github.com> Date: Thu, 1 Nov 2018 13:25:06 -0700 Subject: [PATCH 1/2] [BETA] v0.7.2b Ready to test Changes * Added a state variable to store the current open / close state, to compare to incoming open / close messages and filter out any "false positive" repeat messages NOTE: If updating a device driver for an already paired sensor, the state variable must be manually initialized by going to the device view in your Hubitat hub's web page, and saving preferences for the sensor. --- .../xiaomi-door-window-sensor-hubitat.groovy | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy b/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy index 882f951..c5a1452 100644 --- a/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy +++ b/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy @@ -1,7 +1,7 @@ /** * Xiaomi "Original" & Aqara Door/Window Sensor * Device Driver for Hubitat Elevation hub - * Version 0.7.1 + * Version 0.7.2b * * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except @@ -100,17 +100,21 @@ def parse(String description) { // Parse open/close report private parseContact(closedOpen) { - def value = ["closed", "open"] - def desc = ["closed", "opened"] - def coreEvent = ["lastClosed", "lastOpened"] - displayDebugLog("Setting ${coreEvent[closedOpen]} to current date/time for webCoRE") - sendEvent(name: coreEvent[closedOpen], value: now(), descriptionText: "Updated ${coreEvent[closedOpen]} (webCoRE)") - return [ - name: 'contact', - value: value[closedOpen], - isStateChange: true, - descriptionText: "Contact was ${desc[closedOpen]}" - ] + if (state.closedOpen != closedOpen) { + def value = ["closed", "open"] + def desc = ["closed", "opened"] + def coreEvent = ["lastClosed", "lastOpened"] + displayDebugLog("Setting ${coreEvent[closedOpen]} to current date/time for webCoRE") + sendEvent(name: coreEvent[closedOpen], value: now(), descriptionText: "Updated ${coreEvent[closedOpen]} (webCoRE)") + state.closedOpen = closedOpen + return [ + name: 'contact', + value: value[closedOpen], + isStateChange: true, + descriptionText: "Contact was ${desc[closedOpen]}" + ] + } else + return [:] } // Convert raw 4 digit integer voltage value into percentage based on minVolts/maxVolts range @@ -198,4 +202,6 @@ def updated() { def init() { if (!device.currentState('batteryLastReplaced')?.value) resetBatteryReplacedDate(true) + if (!state.openClose) + state.openClose = 2 } From eb8aeb00575ce436979665c1fb8e45e27cd48749 Mon Sep 17 00:00:00 2001 From: Keith G <33558908+veeceeoh@users.noreply.github.com> Date: Fri, 2 Nov 2018 09:58:12 -0700 Subject: [PATCH 2/2] [BETA] v0.7.3b Ready to test Changes * added new feature: Message Timeout Delay, which allows a user set delay after any open/close event to ignore all open/close messages for a user-adjustable length of time, with a default of 0.5 seconds (500 milliseconds) NOTE: If updating this device driver for an already paired sensor, the Message Timeout Delay must be manually initialized by going to the device view in your Hubitat hub's web page, and saving preferences for the sensor. --- .../xiaomi-door-window-sensor-hubitat.groovy | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy b/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy index c5a1452..b68817c 100644 --- a/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy +++ b/devicedrivers/xiaomi-door-window-sensor-hubitat.src/xiaomi-door-window-sensor-hubitat.groovy @@ -1,7 +1,7 @@ /** * Xiaomi "Original" & Aqara Door/Window Sensor * Device Driver for Hubitat Elevation hub - * Version 0.7.2b + * Version 0.7.3b * * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except @@ -54,10 +54,12 @@ metadata { } preferences { + //Message timeout delay + input name: "messageTimeout", title: "Message Timeout Delay: After an open/close event, ignore all open/close messages for ___ seconds. Default = 0.5 seconds", description: "", type: "decimal" //Battery Voltage Range - input name: "voltsmin", title: "Min Volts (0% battery = ___ volts, range 2.0 to 2.7). Default = 2.5 Volts", description: "", type: "decimal", range: "2..2.7" - input name: "voltsmax", title: "Max Volts (100% battery = ___ volts, range 2.8 to 3.4). Default = 3.0 Volts", description: "", type: "decimal", range: "2.8..3.4" - //Logging Message Config + input name: "voltsmin", title: "Min Volts (0% battery = ___ volts, range 2.0 to 2.7). Default = 2.5 Volts", description: "", type: "decimal", range: "2..2.7" + input name: "voltsmax", title: "Max Volts (100% battery = ___ volts, range 2.8 to 3.4). Default = 3.0 Volts", description: "", type: "decimal", range: "2.8..3.4" + //Logging Message Config input name: "infoLogging", type: "bool", title: "Enable info message logging", description: "" input name: "debugLogging", type: "bool", title: "Enable debug message logging", description: "" } @@ -100,13 +102,15 @@ def parse(String description) { // Parse open/close report private parseContact(closedOpen) { - if (state.closedOpen != closedOpen) { + def timeoutDelayMS = messageTimeout ? messageTimeout * 1000 : 500 + if (((now() - state.lastClosedOpen) > timeoutDelayMS) && (state.closedOpen != closedOpen)) { def value = ["closed", "open"] def desc = ["closed", "opened"] def coreEvent = ["lastClosed", "lastOpened"] displayDebugLog("Setting ${coreEvent[closedOpen]} to current date/time for webCoRE") sendEvent(name: coreEvent[closedOpen], value: now(), descriptionText: "Updated ${coreEvent[closedOpen]} (webCoRE)") state.closedOpen = closedOpen + state.lastClosedOpen = now() return [ name: 'contact', value: value[closedOpen], @@ -204,4 +208,7 @@ def init() { resetBatteryReplacedDate(true) if (!state.openClose) state.openClose = 2 + if (!state.lastClosedOpen) { + state.lastClosedOpen = now() + } }