How do I format/change displayed label for a number item?

I have some number items from the Fronius inverter, for example:

Number    Solar_AC_Power         "AC Power"         {channel="fronius:powerinverter:mybridge:myinverter:inverterdatachannelpac"}

The item contains the power amount in Watt, e.g. 1200
When displaying it in a sitemap like so:

		Text item=Solar_AC_Power label="Solar Power [%.2f W]"

It would display it as “1200.00 W”

How can I display it as “1.20 kW” ?

A method using JavaScript transforms:

Or you could convert your Number item to one which has a unit of measurement (UoM):


I’ve just tried the second method, and it works very nicely:

items

nTemperature1 is the raw value from the binding, nTemperature2 is the same value, but the Item is now specifically a Temperature number, with an initial unit of °C.

Number nTemperature1 { channel="mqtt:topic:msSpareRoom:temperature" }
Number:Temperature nTemperature2 "[%.2f °C]" { channel="mqtt:topic:msSpareRoom:temperature" }

Sitemap

nTemperature1 is shown as it’s raw value. nTemperature2 has been converted to °F just by explicitly stating the required unit in the label.

Text item=nTemperature1 label="Raw value [%s]" icon="temperature"
Text item=nTemperature2 label="With UoM [%s °F]" icon="temperature"

image


So I guess for your specific situation, you could change your Item definition:

Number:Power Solar_AC_Power  "AC Power [%.2f W]"  {channel="fronius:powerinverter:mybridge:myinverter:inverterdatachannelpac"}

Then in the sitemap:

Text item=Solar_AC_Power label="Solar Power [%.2f kW]"

Note, however, that if you use the state of Item Solar_AC_Power in a rule you will have to modify the rule to take account of the fact that it now comes with the unit embedded within. Or use a second Item just for displaying on the sitemap…

1 Like

Thank you! I’ve learned something new. Indeed the UoM method worked beautifully.