BigDecimal "log.debug" Correct but toString/floatValue Incorrect (probabaly a groovy nuance)

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?

I guess I should have added some more debug output. It turns out groovy’s “Elvis operator” is not supported? I replaced:

def hue = value.hue ?: device.currentValue(“hue”)


def hue = value.hue != null ? value.hue : device.currentValue(“hue”)

Now it works. Unfortunately, it only fixed half of my problems. If anybody else stumbles across this post because they are wondering why their generic Z-Wave “RGBW Light” won’t work it’s because the integration to Google Assistant is broken. This change fixes some of the problems but for the rest of the problems this function just plain doesn’t get the right hue/saturation levels.

For example, for red it gets hue: 0 and saturation: 100. For pink it should get something close to hue: 0 and saturation: 50. Variable, obviously, but instead it gets hue: 97 and saturation: 25. This is, unfortunately, NOT pink so there is nothing the device handler can do to fix it.

Just thought I’d share a lessons learned.

i use similiar code to adjust temps or humidity that is off and round one passed the decimal…

BigDecimal offset = settings.TempOffsetCh1
            def startval = convertDegrees(tempScale,encapsulatedCommand) 
            def thetemp = startval as BigDecimal
            BigDecimal adjval = (thetemp + offset)
            def dispval =  String.format("%5.1f", adjval)
            def finalval = dispval as BigDecimal