Sending back string (hex-value) to sendCommand(xxxx)

Hi,
I try to “play” with my RGB lamps.

Actuall I save the old color from the lamp, this is working:

...
var String OldColor
...
OldColor=RGB_Lamp_03_ColRGBWStr.state
logInfo(filename, "Old Color value: {}", OldColor)
...

Result (value from string) looks fine, like:

… [INFO ] [smarthome.model.script.special] Old Color value: ff1aaa44

After this I change the color with defined values like:

...
RGB_Lamp_03_ColRGBWStr.sendCommand("ccaaccaa")
...

Finally I will change the color back to the stored (saved) value from “OldColor” … but will not work

What is the correct syntax?

...
RGB_Lamp_03_ColRGBWStr.sendCommand(OldColor) 
...

Not working, eclipse-errors …

What are the errors?

See attachment, I think I can not give a string to the sendCommand in the way I try … (maybe need a convert, “stringtohex” or whatever :wink: )

What type is RGB_Lamp_03_ColRGBWStr? What binding is it attached to?

Type is string
Bindung behind is mqtt

“only” issue is that I can not use/send the variable, sendig a direct value to the lamp is working.

There is a whole lot going on here that is not obvious for a lot of users. And that’s one reason why the XY Problem is so pernicious.

For example, in this case RGB_Lamp_03_ColRGBWStr.state is not a String. Its a StringType which is a type of State that can be carried by an Item. So the problem isn’t that it’s a variable, it that we don’t have a good idea of what type that variable is. You are assigning that StringType to a variable that is typed to be a String. I’m actually a little surprised that you don’t get errors in your logs when you assign the state to OldColor. But it does appear to work but I’m going to guess it converts the type of OldColor to StringType. The reason why that’s a problem is StringType is not a Command, it’s only a State. Consequently you cannot use it to send a command to an Item.

But you can send a String as a command because OH will parse and convert it to the right type for you.

Try making it so you actually save the String and not StringType to the variable.

OldColor = RGB_Lamp_03_ColRGBWStr.state.toString

Thanks Rich,
realy hard to understand what type is used when, specially StringType is …

But your solution works,

OT:
saving from old power status (Type: Switch) was mutch easier and works directly :wink:

OldStatus=RGB_Lamp_03_Power.state

RGB_Lamp_03_Power.sendCommand(OldStatus)