Jython, extract a unit from an item

Tags: #<Tag:0x00007f61660c2c08> #<Tag:0x00007f61660c2a00> #<Tag:0x00007f61660c2820>

Hello,

probably a simple matter, but I have not found a solution yet.
I would like to store the unit of an item in a variable and achieve this via a jython rule.

For example:

Number:Temperature		System_Temperature_CPU_num	"Temperatur CPU [%.1f %unit%]"		<temperature>

The result should be “°C”, stored in a variable. Thanks!

The unit would not be from the Item, but from the Item’s state. So, assuming the Item has a state that is a QuantityType…

items["System_Temperature_CPU_num"].unit

In the DSL…

System_Temperature_CPU_num.getStateAs(QuantityType).unit
1 Like

Sure, that’s exactly what I was looking for, thought it worked right over the item… once again, thank you very much!