Lambda and rules Type issue

I’m having trouble with lambda functions and Types. The following gives errors about the not being able to invoke constructor (on java.lang.String). I had a similar problem before with the Hue dimmer date which I had to convert to a string and parse back as a date.

Am I missing something fundamental? I’ve spent hours trying variations with all sorts of errors, but all about issues converting the type, some about assigning nul.

val Functions$Function3 colorBrightness = [
Color inColor,
HSBType passColor,
PercentType inBrightness |

oldColor=new HSBType(passColor as HSBType)
logInfo ("Lambda", "inColor [{}] string [{}] old [{}] set Brightness: [{}]", inColor, oldColor,  inBrightness)

Are you seeing this error in Designer or the logs?

You are missing a closing ] but I’ll assume that is a typo.

I think logInfo returns void so it cannot be the last line of a lambda. The last line of a lambda is what that lambda returns. Try just adding a true as the last line.

I don’t know how smart the {} notation is in converting Objects to String. Try appending a .toString to all the objects you are logging out in the logInfo statement.

You shouldn’t need to cast passColor to HSBType as it is passed into the lambda as HSBType.

Sorry I forgot about this thread. I had a look back at my code and here is what is working for reference. There are a couple of changes, first was declaring the variable in the lambda rather than using a global one. The other is breaking up the item into it’s parts.

val Functions$Function3 colorBrightness = [
Color inColor,
HSBType passColor,
PercentType inBrightness |
logInfo ("Lambda", "Lambda in color [{}] and brightness [{}]", inColor, inBrightness)

var HSBType lambdaColor=new HSBType(passColor.hue, passColor.saturation, inBrightness) 

logInfo ("Lambda", "in color [{}] and out [{}] brightness: [{}]", passColor,  lambdaColor, inBrightness)

sendCommand(inColor, lambdaColor)
return lambdaColor
]