[SOLVED] Trouble sending Colorpicker value as HSB via MQTT to SmartThings

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.

logInfo("HSB", "numSplit.get(0) == \"" + numSplit.get(0) + "\"")

Well, that’s not a helpful error. :expressionless:

Interlace log statements after each line to see which line it is failing on. Does Designer mark any of them as having an error?

57

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:

2017-10-30 15:04:57.295 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:04:57.526 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:06:09.708 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:10.102 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:28.926 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:06:29.011 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:06:42.951 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:54.983 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:56.115 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:56.150 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:56.176 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:56.188 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:06:56.193 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:07:30.647 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:07:30.721 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:07:55.879 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType
2017-10-30 15:08:15.934 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:08:16.007 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'decklights.rules'
2017-10-30 15:08:22.901 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType

I also tried adding a log statement just after the “then” and got the following:

2017-10-30 15:16:53.666 [INFO ] [g.eclipse.smarthome.model.script.HSB] - Deck_HSB-Changed Deck_HSB (Type=StringItem, State=31.675118,68.568493,98.900170, Label=null, Category=null)

Does any of that info help?

Make the first line of the rule a logInfo to log out the state of Deck_HSB.

rule HSBtoST
when
	Item Deck_HSB changed
	
then
	logInfo("HSB", "Deck_HSB.state " + Deck_HSB.state)
	
	val hsbHue = (Deck_HSB.state as HSBType).hue.floatValue
	logInfo("HSB", "H " + hsbHue)
	
    val hsbSat = (Deck_HSB.state as HSBType).saturation.floatValue
    logInfo("HSB", "S " + hsbSat)
    
    val hsbBrt = (Deck_HSB.state as HSBType).brightness.floatValue
	logInfo("HSB", "B " + hsbBrt)
end
2017-10-30 16:18:45.172 [INFO ] [g.eclipse.smarthome.model.script.HSB] - Deck_HSB.state 140.406082,88.486251,98.900170
2017-10-30 16:18:45.177 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType

OK let’s break it down.

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)
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

It does not appear to like the second line.

2017-10-30 16:46:00.867 [INFO ] [g.eclipse.smarthome.model.script.HSB] - Deck_HSB.state 127.614204,84.502699,98.900170
2017-10-30 16:46:00.874 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'HSBtoST': org.eclipse.smarthome.core.library.types.HSBType

This does not make much sense.

What gets printed with

if(Deck_HSB.state instanceof HSBType) logInfo("HSB", "It's an HSBType")
else logInfo("HSB", "It is not an HSBType, " + HSBType.state.getClass.toString)

57

13

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.

Stupid typo.

Deck_HSB.state.getClass.toSTring
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

:roll_eyes: 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

Now outputs:

2017-10-30 17:20:21.871 [INFO ] [g.eclipse.smarthome.model.script.HSB] - Deck_HSB.state 258.578680,89.064509,98.900169
2017-10-30 17:20:21.879 [INFO ] [g.eclipse.smarthome.model.script.HSB] - Deck_HSB.state as HSBType 258.578680,89.064509,98.900169
2017-10-30 17:20:21.890 [INFO ] [g.eclipse.smarthome.model.script.HSB] - (Deck_HSB.state as HSBType).hue 258.578680
2017-10-30 17:20:21.902 [INFO ] [g.eclipse.smarthome.model.script.HSB] - (Deck_HSB.state as HSBType).hue.floatValue 258.57867

Yes, the Item type REALLY matters. Looks like it is working now.

1 Like

It sure is :slightly_smiling_face: 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 :beers:

It now works. :smile:

For completeness this is what I did:

.items

Color Deck_HSB

String Deck_HS { mqtt=">[broker:smartthings/Decks/color:state:*:default],
				       <[broker:smartthings/Decks/color:state:*:default]"}

String Deck_L  { mqtt=">[broker:smartthings/Decks/level:state:*:default],
				       <[broker:smartthings/Decks/level:state:*:default]"}

.rules

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