Odd, I thought that Hue was an integer. Guess I’m wrong. That is the source of your problem. You cannot parse a floating point number string into an int.
The designer seems happy. I tried the above and got the same error then commented each block out one by one and still the same error. I guess that means it fails on all? See below:
rule HSBtoST
when
Item Deck_HSB changed
then
logInfo("HSB", "Deck_HSB.state " + Deck_HSB.state)
logInfo("HSB", "Deck_HSB.state as HSBType " + (Deck_HSB.state as HSBType))
//logInfo("HSB", "(Deck_HSB.state as HSBType).hue " + (Deck_HSB.state as HSBType).hue)
//logInfo("HSB", "(Deck_HSB.state as HSBType).hue.floatValue " + (Deck_HSB.state as HSBType).hue.floatValue)
end
if(Deck_HSB.state instanceof HSBType) logInfo("HSB", "It's an HSBType")
else logInfo("HSB", "It is not an HSBType, " + HSBType.state.getClass.toString)
2017-10-30 17:00:24.668 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': An error occured during the script execution: The name '<XFeatureCallImplCustom>.state' cannot be resolved to an item or type.
2017-10-30 17:15:47.323 [INFO ] [g.eclipse.smarthome.model.script.HSB] - It is not an HSBType, class org.eclipse.smarthome.core.library.types.StringType
I think I know what you are going to say next. My item should be a “color” item. Sorry, I had no idea it mattered.
Changed in items and got:
2017-10-30 17:17:02.475 [INFO ] [g.eclipse.smarthome.model.script.HSB] - It's an HSBType
this:
rule HSBtoST
when
Item Deck_HSB changed
then
//if(Deck_HSB.state instanceof HSBType) logInfo("HSB", "It's an HSBType")
//else logInfo("HSB", "It is not an HSBType, " + Deck_HSB.state.getClass.toString)
logInfo("HSB", "Deck_HSB.state " + Deck_HSB.state)
logInfo("HSB", "Deck_HSB.state as HSBType " + (Deck_HSB.state as HSBType))
logInfo("HSB", "(Deck_HSB.state as HSBType).hue " + (Deck_HSB.state as HSBType).hue)
logInfo("HSB", "(Deck_HSB.state as HSBType).hue.floatValue " + (Deck_HSB.state as HSBType).hue.floatValue)
end
It sure is Thanks very much for your patience, I wont make that mistake again! Without your help I would have been running around in circles forever as I had no idea that the item type was that important. Rookie mistake. I can now crack on with the rest of my rule, thanks again
rule HSBtoSTviaMQTT
when
Item Deck_HSB changed
then
//Get "HSB" values and separate
val hsbHue = (Deck_HSB.state as HSBType).hue.floatValue
val hsbSat = (Deck_HSB.state as HSBType).saturation.floatValue
val hsbBrt = (Deck_HSB.state as HSBType).brightness.floatValue
//Divide "Hue" to get the 0-100% value that ST accepts
var hDivided = hsbHue/3.65 as float
//Post divided "Hue" and untouched "Saturation" to ST "Color" topic)
var hs = (hDivided +"," +hsbSat)
postUpdate(Deck_HS, hs)
//Round "Brightness" and post to ST "Level" topic
var l = Math::round(hsbBrt.floatValue())
postUpdate(Deck_L, l)
end