From 5e787dd0e33499d45dbbe6599aa792e3cc5a697b Mon Sep 17 00:00:00 2001 From: Luke Ness Date: Mon, 19 Jun 2017 11:59:13 -0500 Subject: [PATCH 1/4] BatteryGet has a format method not property --- devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy b/devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy index 9c0d62b..61426e0 100644 --- a/devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy +++ b/devicetypes/smartthings/zwave-siren.src/zwave-siren.groovy @@ -72,7 +72,7 @@ def createEvents(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) { def poll() { if (secondsPast(state.lastbatt, 36*60*60)) { - return zwave.batteryV1.batteryGet().format + return zwave.batteryV1.batteryGet().format() } else { return null } From f96ae94d12d6e8401e0ae0d41c0528cf4a7a3ec6 Mon Sep 17 00:00:00 2001 From: "piyush.c" Date: Wed, 19 Jul 2017 14:18:32 +0530 Subject: [PATCH 2/4] [DHF-14][DHF-15] Health Check Aeon Key Fob and Aeon Minimote --- devicetypes/smartthings/aeon-key-fob.src/aeon-key-fob.groovy | 4 ++-- .../smartthings/aeon-minimote.src/aeon-minimote.groovy | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/devicetypes/smartthings/aeon-key-fob.src/aeon-key-fob.groovy b/devicetypes/smartthings/aeon-key-fob.src/aeon-key-fob.groovy index 097479e..7bcdfd5 100644 --- a/devicetypes/smartthings/aeon-key-fob.src/aeon-key-fob.groovy +++ b/devicetypes/smartthings/aeon-key-fob.src/aeon-key-fob.groovy @@ -133,8 +133,8 @@ def updated() { } def initialize() { - // Arrival sensors only goes OFFLINE when Hub is off - sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false) + // Device only goes OFFLINE when Hub is off + sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zwave", scheme:"untracked"]), displayed: false) def zwMap = getZwaveInfo() def buttons = 4 // Default for Key Fob diff --git a/devicetypes/smartthings/aeon-minimote.src/aeon-minimote.groovy b/devicetypes/smartthings/aeon-minimote.src/aeon-minimote.groovy index c2fbfc3..4f8aa85 100644 --- a/devicetypes/smartthings/aeon-minimote.src/aeon-minimote.groovy +++ b/devicetypes/smartthings/aeon-minimote.src/aeon-minimote.groovy @@ -111,7 +111,6 @@ def configure() { return cmds } - def installed() { initialize() } @@ -121,7 +120,7 @@ def updated() { } def initialize() { - // Arrival sensors only goes OFFLINE when Hub is off - sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zigbee", scheme:"untracked"]), displayed: false) + // Device only goes OFFLINE when Hub is off + sendEvent(name: "DeviceWatch-Enroll", value: JsonOutput.toJson([protocol: "zwave", scheme:"untracked"]), displayed: false) sendEvent(name: "numberOfButtons", value: 4) } From f1a8d58c4006924e31090f331893a98978d064fd Mon Sep 17 00:00:00 2001 From: Donald Kirker Date: Tue, 11 Jul 2017 20:27:29 -0700 Subject: [PATCH 3/4] ICP-1267 Call lock state check code from installed() with precise timing to threduce chance that hub has gone back to pjoin mode thus blocking Z-Wave. --- .../zwave-lock.src/zwave-lock.groovy | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/devicetypes/smartthings/zwave-lock.src/zwave-lock.groovy b/devicetypes/smartthings/zwave-lock.src/zwave-lock.groovy index bbd9ac8..cd65d49 100644 --- a/devicetypes/smartthings/zwave-lock.src/zwave-lock.groovy +++ b/devicetypes/smartthings/zwave-lock.src/zwave-lock.groovy @@ -88,19 +88,21 @@ import physicalgraph.zwave.commands.usercodev1.* def installed() { // Device-Watch pings if no device events received for 1 hour (checkInterval) sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID]) + + try { + if (!state.init) { + state.init = true + // Wait long enough for behind-the-scenes z-wave magic to finish, but be quick enough before hub goes back into inclusion and blocks us + response(["delay 2000"] + secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()], 2200)) + } + } catch (e) { + log.warn "installed() threw $e" + } } def updated() { // Device-Watch pings if no device events received for 1 hour (checkInterval) sendEvent(name: "checkInterval", value: 1 * 60 * 60, displayed: false, data: [protocol: "zwave", hubHardwareId: device.hub.hardwareID]) - try { - if (!state.init) { - state.init = true - response(secureSequence([zwave.doorLockV1.doorLockOperationGet(), zwave.batteryV1.batteryGet()])) - } - } catch (e) { - log.warn "updated() threw $e" - } } def parse(String description) { From c86d61a8626f24682228c0c085806a7b98c22a80 Mon Sep 17 00:00:00 2001 From: Zach Varberg Date: Wed, 26 Jul 2017 14:14:21 -0500 Subject: [PATCH 4/4] Smooth battery values for smartsense devices Since we have been receiving a lot of reports and complaints about the battery readings on the smartsense devices that received battery updates (multi and motion), we are adding this code to smooth out the readings so it doesn't constantly oscillate between two values. The basic logic is, only create an event if we have two readings in a row that are the same, or a reading is more than 100 millivolts off of the current battery percentage. --- .../smartsense-motion-sensor.groovy | 26 +++++++++++++++---- .../smartsense-multi-sensor.groovy | 26 +++++++++++++++---- 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy index c00e65e..7eb8118 100644 --- a/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy +++ b/devicetypes/smartthings/smartsense-motion-sensor.src/smartsense-motion-sensor.groovy @@ -173,11 +173,27 @@ private Map getBatteryResult(rawValue) { } else { def minVolts = 2.4 def maxVolts = 2.7 - def pct = (volts - minVolts) / (maxVolts - minVolts) - def roundedPct = Math.round(pct * 100) - if (roundedPct <= 0) - roundedPct = 1 - result.value = Math.min(100, roundedPct) + // Get the current battery percentage as a multiplier 0 - 1 + def curValVolts = Integer.parseInt(device.currentState("battery")?.value ?: "100") / 100.0 + // Find the corresponding voltage from our range + curValVolts = curValVolts * (maxVolts - minVolts) + minVolts + // Round to the nearest 10th of a volt + curValVolts = Math.round(10 * curValVolts) / 10.0 + // Only update the battery reading if we don't have a last reading, + // OR we have received the same reading twice in a row + // OR we don't currently have a battery reading + // OR the value we just received is at least 2 steps off from the last reported value + if(state?.lastVolts == null || state?.lastVolts == volts || device.currentState("battery")?.value == null || Math.abs(curValVolts - volts) > 0.1) { + def pct = (volts - minVolts) / (maxVolts - minVolts) + def roundedPct = Math.round(pct * 100) + if (roundedPct <= 0) + roundedPct = 1 + result.value = Math.min(100, roundedPct) + } else { + // Don't update as we want to smooth the battery values + result = null + } + state.lastVolts = volts } } diff --git a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy index a8d436e..38331df 100644 --- a/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy +++ b/devicetypes/smartthings/smartsense-multi-sensor.src/smartsense-multi-sensor.groovy @@ -275,11 +275,27 @@ private Map getBatteryResult(rawValue) { } else { def minVolts = 2.1 def maxVolts = 2.7 - def pct = (volts - minVolts) / (maxVolts - minVolts) - def roundedPct = Math.round(pct * 100) - if (roundedPct <= 0) - roundedPct = 1 - result.value = Math.min(100, roundedPct) + // Get the current battery percentage as a multiplier 0 - 1 + def curValVolts = Integer.parseInt(device.currentState("battery")?.value ?: "100") / 100.0 + // Find the corresponding voltage from our range + curValVolts = curValVolts * (maxVolts - minVolts) + minVolts + // Round to the nearest 10th of a volt + curValVolts = Math.round(10 * curValVolts) / 10.0 + // Only update the battery reading if we don't have a last reading, + // OR we have received the same reading twice in a row + // OR we don't currently have a battery reading + // OR the value we just received is at least 2 steps off from the last reported value + if(state?.lastVolts == null || state?.lastVolts == volts || device.currentState("battery")?.value == null || Math.abs(curValVolts - volts) > 0.1) { + def pct = (volts - minVolts) / (maxVolts - minVolts) + def roundedPct = Math.round(pct * 100) + if (roundedPct <= 0) + roundedPct = 1 + result.value = Math.min(100, roundedPct) + } else { + // Don't update as we want to smooth the battery values + result = null + } + state.lastVolts = volts } }