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

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"


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