Skip to content

Commit 702229d

Browse files
committed
GWWST-139 Inaccuracy in color temp due to unit conversion/rounding
Based on feedback, product would prefer if we fudged the numbers a bit so that K values match what is set by the user.
1 parent 71e2abe commit 702229d

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

devicetypes/smartthings/zigbee-rgbw-bulb.src/zigbee-rgbw-bulb.groovy

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def parse(String description) {
9494
if (event.name=="level" && event.value==0) {}
9595
else {
9696
if (event.name=="colorTemperature") {
97+
// Because of conversion to and from mireds we get some accuracy loss so in order for UI
98+
// elements to match commands, we'll just see if they're within a tolerance
99+
if (event.value <= state.lastValue * 1.05 && event.value >= state.lastValue * .95) {
100+
event.value = state.lastValue
101+
state.lastValue = null
102+
}
97103
setGenericName(event.value)
98104
}
99105
sendEvent(event)
@@ -174,6 +180,8 @@ def setColorTemperature(value) {
174180
def tempInMired = Math.round(1000000 / value)
175181
def finalHex = zigbee.swapEndianHex(zigbee.convertToHexString(tempInMired, 4))
176182

183+
state.lastLevel = value
184+
177185
zigbee.command(COLOR_CONTROL_CLUSTER, 0x0A, "$finalHex 0000") +
178186
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_COLOR_TEMPERATURE)
179187
}

devicetypes/smartthings/zigbee-white-color-temperature-bulb.src/zigbee-white-color-temperature-bulb.groovy

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ def parse(String description) {
9494
if (event.name=="level" && event.value==0) {}
9595
else {
9696
if (event.name=="colorTemperature") {
97+
// Because of conversion to and from mireds we get some accuracy loss so in order for UI
98+
// elements to match commands, we'll just see if they're within a tolerance
99+
if (event.value <= state.lastValue * 1.05 && event.value >= state.lastValue * .95) {
100+
event.value = state.lastValue
101+
state.lastValue = null
102+
}
97103
setGenericName(event.value)
98104
}
99105
sendEvent(event)
@@ -169,6 +175,7 @@ def setColorTemperature(value) {
169175
cmds << zigbee.command(COLOR_CONTROL_CLUSTER, MOVE_TO_COLOR_TEMPERATURE_COMMAND, "$finalHex 0000")
170176
}
171177
cmds << zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_COLOR_TEMPERATURE)
178+
state.lastLevel = value
172179
cmds
173180
}
174181

devicetypes/smartthings/zll-white-color-temperature-bulb-5000k.src/zll-white-color-temperature-bulb-5000k.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def parse(String description) {
7878
if (event) {
7979
if (event.name == "colorTemperature") {
8080
event.unit = "K"
81+
// Because of conversion to and from mireds we get some accuracy loss so in order for UI
82+
// elements to match commands, we'll just see if they're within a tolerance
83+
if (event.value <= state.lastValue * 1.05 && event.value >= state.lastValue * .95) {
84+
event.value = state.lastValue
85+
state.lastValue = null
86+
}
87+
setGenericName(event.value)
8188
}
8289
sendEvent(event)
8390
}
@@ -157,6 +164,8 @@ def setColorTemperature(value) {
157164
def tempInMired = Math.round(1000000 / value)
158165
def finalHex = zigbee.swapEndianHex(zigbee.convertToHexString(tempInMired, 4))
159166

167+
state.lastLevel = value
168+
160169
zigbee.command(COLOR_CONTROL_CLUSTER, MOVE_TO_COLOR_TEMPERATURE_COMMAND, "$finalHex 0000") +
161170
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_COLOR_TEMPERATURE)
162171
}

devicetypes/smartthings/zll-white-color-temperature-bulb.src/zll-white-color-temperature-bulb.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def parse(String description) {
7979
log.debug "description is $description"
8080
def event = zigbee.getEvent(description)
8181
if (event) {
82+
if (event.name=="colorTemperature") {
83+
// Because of conversion to and from mireds we get some accuracy loss so in order for UI
84+
// elements to match commands, we'll just see if they're within a tolerance
85+
if (event.value <= state.lastValue * 1.05 && event.value >= state.lastValue * .95) {
86+
event.value = state.lastValue
87+
state.lastValue = null
88+
}
89+
setGenericName(event.value)
90+
}
8291
sendEvent(event)
8392
}
8493
else {
@@ -153,6 +162,8 @@ def setColorTemperature(value) {
153162
def tempInMired = Math.round(1000000 / value)
154163
def finalHex = zigbee.swapEndianHex(zigbee.convertToHexString(tempInMired, 4))
155164

165+
state.lastLevel = value
166+
156167
zigbee.command(COLOR_CONTROL_CLUSTER, MOVE_TO_COLOR_TEMPERATURE_COMMAND, "$finalHex 0000") +
157168
zigbee.readAttribute(COLOR_CONTROL_CLUSTER, ATTRIBUTE_COLOR_TEMPERATURE)
158169
}

0 commit comments

Comments
 (0)