And the error in the openhab.log?
Are you using ESH Designer? One nice thing it has, especially when you are first learning, is <ctrl><space>
to offer valid ways to complete the statement you’ve started typing. So if you typed Deck_HSB.<ctrl><space>
it will give you all the methods available on State.
So I’m going to split this into two parts. First how to figure out what is wrong with the code you have, the other a better way to do it.
First, whenever you have such problems logging is your friend. Log each numSplit.get before you try to parse it. when you do log it, wrap it in quotes so you can see if there is any white space or other non-parsable characters which would prevent parseInt from successfully parsing the values.
I think the hue part is always an integer so I don’t think the problem is because of a decimal point. But if there is a decimal point you can’t use Integer, you have to use Float.
As an aside, since you know that numSplit.get(0) represents the hue, it is far better to name that variable “hue” rather than “first” which really is not very informative. It is much easier for you, future you, and others to understand code when you use meaningful variable names.
And now for the better way.
On the other thread where you brought up parts of this issue, back when we thought you needed to convert the HSB to HSL I posted the following code:
val hsbHue = (MyColorItem.state as HSBType).hue.floatValue
val hsbSat = (MyColorItem.state as HSBType).saturation.floatValue
val hsbBrt = (MyColorItem.state as HSBType).brightness.floatValue
val hue = hsbHue
val sat = hsbSat * hsbBrt/( (if((2-hsbSat)*hsbBrt < 1) hsbHue else 2-hsbHue) )
val lightness = hsbBrt / 2.0
As you can see, you don’t need to parse the .state.toString at all. You can get at the raw primitive value for each directly.
By default, when you call .state you get back a generic State object. But you know because you read the docs that a ColorItem carries an HSBType which is a subclass of State. So you can cast that generic State object to an HSBType which gives you more methods to access the data stored in the State.
To discover what those methods are you need to visit the ESH Javadocs, look at the code itself, or you can do what I do and use ESH Designer and just type <ctrl><space>
. Soon the VSCode plugin will support this I think too.
I applaud your willingness to learn how to do this stuff and that you are not just asking us to do it for you. But don’t spin your wheels too long on your own. We are happy to help! 