From 7916a200284952d5f0bb92e84c455d48fae67f90 Mon Sep 17 00:00:00 2001 From: Kristopher Kubicki Date: Tue, 7 Apr 2015 22:14:58 -0500 Subject: [PATCH 1/3] Add conditional to fix light level on turn off --- Lightify_Bulb_v2.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lightify_Bulb_v2.groovy b/Lightify_Bulb_v2.groovy index d169c88..74eeb7e 100644 --- a/Lightify_Bulb_v2.groovy +++ b/Lightify_Bulb_v2.groovy @@ -147,7 +147,9 @@ def on() { def off() { log.debug "off()" sendEvent(name: "switch", value: "off") - + if(device.latestValue("level") < 99) { + sendEvent(name: "level", value: 100) + } "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}" } From bf9b3bc59a95301e4562efb1d742e05226f9904b Mon Sep 17 00:00:00 2001 From: Kristopher Kubicki Date: Tue, 7 Apr 2015 23:10:43 -0500 Subject: [PATCH 2/3] Fixes inability to dim below 7% --- Lightify_Bulb_v2.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lightify_Bulb_v2.groovy b/Lightify_Bulb_v2.groovy index 74eeb7e..8874738 100644 --- a/Lightify_Bulb_v2.groovy +++ b/Lightify_Bulb_v2.groovy @@ -176,7 +176,7 @@ def setLevel(value) { } sendEvent(name: "level", value: value) - def level = new BigInteger(Math.round(value * 255 / 100).toString()).toString(16) + def level = sprintf("%02d",Math.round(value * 255 / 100)) cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${level} 1500}" //log.debug cmds From bbf47c2a9820443f32621acc125b9d6ecc473415 Mon Sep 17 00:00:00 2001 From: Kristopher Kubicki Date: Tue, 14 Apr 2015 09:27:28 -0500 Subject: [PATCH 3/3] Added polling capability --- Lightify_Bulb_v2.groovy | 76 +++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/Lightify_Bulb_v2.groovy b/Lightify_Bulb_v2.groovy index 8874738..56cb6b0 100644 --- a/Lightify_Bulb_v2.groovy +++ b/Lightify_Bulb_v2.groovy @@ -22,6 +22,7 @@ metadata { capability "Refresh" capability "Switch" capability "Switch Level" + capability "Polling" command "setColorTemp" @@ -29,6 +30,8 @@ metadata { attribute "kelvin", "string" attribute "bulbTemp", "string" + attribute "unreachable", "number" + fingerprint profileId: "0104", inClusters: "0000,0003,0004,0005,0006,0008,0300,0B04,FC0F", outClusters: "0019" } @@ -80,6 +83,8 @@ def parse(String description) { log.trace description def msg = zigbee.parse(description) + sendEvent(name: 'unreachable', value: 0) + if (description?.startsWith("catchall:")) { log.trace msg @@ -101,8 +106,8 @@ def parse(String description) { } - if (description?.startsWith("read attr")) { - + if (description?.startsWith("read attr")) { + Map descMap = (description - "read attr - ").split(",").inject([:]) { map, param -> def nameAndValue = param.split(":") map += [(nameAndValue[0].trim()):nameAndValue[1].trim()] @@ -113,16 +118,12 @@ def parse(String description) { switch (descMap.cluster) { case "0008": - - log.debug description[-2..-1] def i = Math.round(convertHexToInt(descMap.value) / 256 * 100 ) sendEvent( name: "level", value: i ) - sendEvent( name: "switch.setLevel", value: i) //added to help subscribers - break + def result = sendEvent( name: "switch.setLevel", value: i) //added to help subscribers + return result - case "0300": - - log.debug descMap.value + case "0300": def i = Math.round( 1000000 / convertHexToInt(descMap.value)) def j = i def bTemp = getBulbTemp(j) @@ -147,15 +148,29 @@ def on() { def off() { log.debug "off()" sendEvent(name: "switch", value: "off") - if(device.latestValue("level") < 99) { - sendEvent(name: "level", value: 100) - } + if(device.latestValue("level") < 99) { + sendEvent(name: "level", value: 100) + } "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}" } def refresh() { + + def unreachable = device.latestValue("unreachable") + if(unreachable == null) { + sendEvent(name: 'unreachable', value: 1) + } + else { + sendEvent(name: 'unreachable', value: unreachable + 1) + } + + log.debug "UNREACHABLEREF: $unreachable "; + if(unreachable > 2) { + sendEvent(name: "switch", value: "off") + } + [ "st rattr 0x${device.deviceNetworkId} ${endpointId} 6 0", "delay 500", "st rattr 0x${device.deviceNetworkId} ${endpointId} 8 0", "delay 500", @@ -163,10 +178,28 @@ def refresh() { ] } +def poll() { + refresh() +} + + def setLevel(value) { log.trace "setLevel($value)" def cmds = [] + def unreachable = device.latestValue("unreachable") + if(unreachable == null) { + sendEvent(name: 'unreachable', value: 1) + } + else { + sendEvent(name: 'unreachable', value: unreachable + 1) + } + + log.debug "UNREACHABLELEV: $unreachable "; + if(unreachable > 2) { + sendEvent(name: "switch", value: "off") + } + if (value == 0) { sendEvent(name: "switch", value: "off") cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 6 0 {}" @@ -175,11 +208,13 @@ def setLevel(value) { sendEvent(name: "switch", value: "on") } + sendEvent(name: "level", value: value) def level = sprintf("%02d",Math.round(value * 255 / 100)) + if(value == 1) { level = "01" } cmds << "st cmd 0x${device.deviceNetworkId} ${endpointId} 8 4 {${level} 1500}" - //log.debug cmds + log.debug cmds cmds } @@ -187,7 +222,18 @@ def setColorTemp(value) { log.trace "setColorTemp($value)" - + def unreachable = device.latestValue("unreachable") + if(unreachable == null) { + sendEvent(name: 'unreachable', value: 1) + } + else { + sendEvent(name: 'unreachable', value: unreachable + 1) + } + + log.debug "UNREACHABLECT: $unreachable "; + if(unreachable > 2) { + sendEvent(name: "switch", value: "off") + } def degrees = Math.round(value) if (degrees < 2700) { degrees = 2700 } @@ -203,6 +249,8 @@ def setColorTemp(value) { sendEvent(name: "kelvin", value: degrees) sendEvent( name: "bulbTemp", value: bTemp) + + def levelC = swapEndianHex(hexSixteen(1000000/degrees)) log.trace levelC