Now, I want to get this value and update my colorpicker. Thus, I created this rule:
rule "WLED MQTT Red Received"
when
Item WLED_PGarageColorRed changed
then
var newColor = "false"
var HSBType hsbValue = WLED_PGarageColor.state as HSBType
var int redValue = (Math::round(hsbValue.red.intValue * 2.55)).intValue
var int greenValue = (Math::round(hsbValue.green.intValue * 2.55)).intValue
var int blueValue = (Math::round(hsbValue.blue.intValue * 2.55)).intValue
if (WLED_PGarageColorRed.state != redValue.toString){
var double redReceived = WLED_PGarageColorRed.state
var redReceivedInt = (redReceived / 2.55)
newColor = "true"
logInfo("WLED","Red2: " + redReceived)
}
if (WLED_PGarageColorGreen.state != greenValue.toString){
newColor = "true"
}
if (WLED_PGarageColorBlue.state != blueValue.toString){
newColor = "true"
}
val rgbCol = "" + redValue + "" + greenValue + "" + blueValue
if (newColor == "true" )
{
logInfo("WLED", "Color changed from API")
//WLED_PGarageColor.postUpdate(rgbCol)
}
end
Now, when I run the job to update the value, I get the error
An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.DoubleExtensions.operator_divide(double,double) on instance: null
But if I log the value of redReceived , there is a value so why it’s saying there’s an null?
Thank you
edit
For more info, I just tried doing var int redReceived = (Integer::parseInt(WLED_PGarageColorRed.state as Double))
This output me Rule 'WLED MQTT Red Received': Could not cast 76 to java.lang.Double; line 51, column 44, length 36
I tried as Decimal, didn’t solved. I tried just parsing, says cannot convert null … Rule 'WLED MQTT Red Received': An error occurred during the script execution: Could not invoke method: java.lang.Integer.parseInt(java.lang.String) on instance: null
I cannot use the colorpicker as his. The color picker send RGB data while WLED MQTT use #HEX value. Thus, a way to simplify this is to use API call instead. This then send me an xml as an answer that I need to parse, and then I need to put this data into the colorpicker. And that’s what I’m trying to do.
yeah, I read that. I was more trying to understand what error I have right now, why I cannot simply cast a string to int/double or anything, why it says it’s null when it’s clearly not…
Yeah I tried it and it’s really a mess, and for me unreliable. I send command with it like on/off and it’s not always toggling. Using my own mqtt bindind and api call solved my problems. Just too bad simple string to int doesn’t work and I don’t get why I’m getting the error message I posted.
If you are interested in helping the situation you could make a more detailed post of what did not work with the binding and how long ago you last tried. I would suspect you have a wifi connection issue if it was unreliable and that would be why you get better results with mqtt which is designed for unstable connections. To diagnose enter this URL using the ip of wled and look for the RSSI signal strength.