Skip to content

Commit 2be6e5f

Browse files
marstorpworkingmonk
authored andcommitted
PROB-1869 Zen thermostat connecting with no battery state (SmartThingsCommunity#2671)
* PROB-1869 Zen thermostat connecting with no battery state Changing algorithm for calculating battery % so it no longer need the check for upper/lower limit of the received voltage. * Update zen-thermostat.groovy
1 parent cc2cd98 commit 2be6e5f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

devicetypes/zenwithin/zen-thermostat.src/zen-thermostat.groovy

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def updated() {
153153
// make sure supporedModes are in sync
154154
sendEvent(name: "supportedThermostatModes", value: supportedModes, eventType: "ENTITY_UPDATE", displayed: false)
155155
// Make sure we poll all attributes from the device
156-
state.pollAdditionalData = state.pollAdditionalData - (24 * 60 * 60 * 1000)
156+
state.pollAdditionalData = state.pollAdditionalData ? state.pollAdditionalData - (24 * 60 * 60 * 1000) : null
157157
// initialize() needs to be called after device details has been updated() but as installed() also calls this method and
158158
// that LiveLogging shows updated is being called more than one time, try avoiding multiple config/poll be done us runIn ;o(
159159
runIn(3, "initialize", [overwrite: true])
@@ -419,14 +419,14 @@ def updateBatteryStatus(rawValue) {
419419
// customAttribute in order to change UI icon/label
420420
def eventMap = [name: "batteryIcon", value: "err_battery", displayed: false]
421421
def linkText = getLinkText(device)
422-
if (volts < 62 && volts != 0 && volts != 255) {
423-
def minVolts = 34 // voltage when device UI starts to die
424-
def maxVolts = 61 // 4 batteries at 1.5V should be 6.0V, however logs from users show 6,1 as well
425-
def pct = (volts - minVolts) / (maxVolts - minVolts)
426-
eventMap.value = Math.min(100, (int) pct * 100)
422+
if (volts != 255) {
423+
def minVolts = 34 // voltage when device UI starts to die, ie. when battery fails
424+
def maxVolts = 60 // 4 batteries at 1.5V (6.0V)
425+
def pct = (volts > minVolts) ? ((volts - minVolts) / (maxVolts - minVolts)) : 0
426+
eventMap.value = Math.min(100, (int)(pct * 100))
427427
// Update capability "Battery"
428428
sendEvent(name: "battery", value: eventMap.value, descriptionText: "${getLinkText(device)} battery was ${eventMap.value}%")
429-
eventMap.value = eventMap.value > 10 ? eventMap.value : "low_battery"
429+
eventMap.value = eventMap.value > 15 ? eventMap.value : "low_battery"
430430
}
431431
sendEvent(eventMap)
432432
} else {

0 commit comments

Comments
 (0)