I bought some Monoprice RGB z-wave plus bulbs the other day on sale and they work great from the SmartThings app. They don’t work as well from the Google Home integration though so I started digging around to discover why.
What I found is that the app sets the colors with RGB using zwave.switchColorV3.switchColorSet and grabs these rgb values from the controlTile. On the other hand, the Google Home integration passes in a hue/saturation value. For red from the app the values are [255, 0, 0]. Google Home passes in [hue: 0, saturation: 100] which is also correct but here’s where it gets weird.
I have the following debug code added to the handler so it looks like this:
log.debug "presumably here: ${value.hue} and ${value.saturation}"
def hue = value.hue.floatValue() ?: device.currentValue("hue")
log.debug "check: ${hue} and ${hue.toString()} or ${hue.floatValue()} but value.hue is still ${value.hue}"
def saturation = value.saturation ?: device.currentValue("saturation")
log.debug "now here: ${hue} ${saturation}"
if(hue == null) hue = 13
if(saturation == null) saturation = 13
def rgb = huesatToRGB(hue, saturation)
log.debug "doesn't work: ${rgb[0]} ${rgb[1]} ${rgb[2]}"
result << zwave.switchColorV3.switchColorSet(red: rgb[0], green: rgb[1], blue: rgb[2], warmWhite:0, coldWhite:0)
And surprisingly here is the output:
9:57:23 AM: debug presumably here: 0 and 100
9:57:23 AM: debug check: 90.84968 and 90.84968 or 90.84968 but value.hue is still 0
9:57:23 AM: debug now here: 90.84968 100
I have messed around with the variable hue by calling hue.getClass().getName() (which SmartThings doesn’t allow) but it still told me that it was a BigDecimal. There is nothing in a BigDecimal that would print it at 100 but then toString or floatValue it to 90.84968 as far as I know.
Obviously, the 90.84968 is throwing off the function that converts the HSV to RGB but I can’t figure out what is going on with that hue variable. Any ideas?