Parse dec to char for sending via serial or alternative

Hello,
I was seraching quite a lot of ressources but could not get anythunbg to work in openhab.

Problem: I have a setpoint item for temperatures. I want to send for example the value 20 (it is a temperature value as number) via my serial binding.
As the serial binding is a String item, my “20” is send as hex “32 30” corresponding to “2” “0” in ASCII code.
It should be “14” as hex code via my serial code.

Question: what can I do to either
a.) convert my “20” decimal value to the ASCII code
b.) convert my “20” to hex and actually send hex instead of ASCII (so far I found /uxxxx, but I can not use a variable with this)

Does anybody have a tip for me?

Thank you.

Warm regards, cal

Have you tried using a Number Item?

I tested a number item, but strangely enough in this case nothing is sent via serial. Log states NULL, hence nothing to send. But I will try again.

Hi, send Command can only send strings. (as it seems).

cal

The action sendCommand can only send strings. But MyNuberItemName.sendCommand will take a number if MyNumberItemName supports DecimalType.

Dear Rich,

question: do oyu mean “cc2.sendCommand(70)”, where “cc2” is my item and “70” is my number? (cc2 binding is serial bus)

In this case, I will see on the log the command “70” as send indeed, but on serial bus the hex codes “37” “30”, which are the Hex codes of “7” and “0”.

Target: I would need to the the hex code “14” on my serial bus, which corresponds to “46” hex which stands for decimal “70”.

So far I did not find another solution as to parse first my “70” to the asci code and send the ascii code afterwards.

Yesterday evening, after horus of searching (as Java code is not really working in openhab), I found this, which si working for me now:

" var strVal = String::valueOf(Character::toChars(50))"

, where “50” is my value to be translated (just example). Now the decimal “50” is tranlated and i send the “strVal” via serial binding.

Still a bit complicated, so if there is another way, I am still interested.

Yes, if cc2 is a Number Item and you call cc2.sendCommand(70) it might send out the numerical value instead of the String. I don’t use this binding so I’m only making an educated guess.