OH3 UI - Number:Temperature not showing measurement unit

Hi, :slight_smile:

I stumbled over a problem with my Number:Temperature items which are assigned to the semantic model and shown in the main ui (category sensors).

Both items should display “°C” behind the value of the temperature but it is not happening for all items as I would have expected it.

One item is getting its state via MQTT and the other one from a Jeelink sensor.

Number:Temperature   XiaomiAqaraDHT01_Temperature   "Temperature"   <temperature>  (XiaomiAqaraDHT01)  ["Measurement","Temperature"]    {widgetOrder="0", channel="mqtt:topic:broker:xiaomiAqaraDht01:temperature"}

Number:Temperature   JeeLinkSensor01_Temperature    "Temperature"   <temperature>  (JeeLinkSensor01)   ["Measurement","Temperature"]    {widgetOrder="0", channel="jeelink:lacrosse:2:temperature"}

If I take a look at these items in the karaf console I get the following results:

openhab> openhab:items list JeeLinkSensor01_Temperature
JeeLinkSensor01_Temperature (Type=NumberItem, State=4.9 °C, Label=Temperature, Category=temperature, Tags=[Measurement, Temperature], Groups=[JeeLinkSensor01])

openhab> openhab:items list XiaomiAqaraDHT01_Temperature
XiaomiAqaraDHT01_Temperature (Type=NumberItem, State=21.11 °C, Label=Temperature, Category=temperature, Tags=[Measurement, Temperature], Groups=[XiaomiAqaraDHT01])

The item XiaomiAqaraDHT01_Temperature already seems to have the proper measurement unit but somehow it is not displayed in the ui.

From my understanding it should assign the measurement unit automatically if you use the item type Number:Temperature but unfortunately this doesn’t seem to work as it is intended to do (at least on my oh instance)

Is there anything else that needs to be done to ensure that the proper units are displayed?

Another thing I noticed is the representation of items with the type Number:Dimensionless (Humidity in the screenshot above).
Both items in the screenshot are configured the same way except of the thing channels (which are linked to MQTT/Jeelink things), the names of the items (kind of obvious :smile:) and the group names.

If I query these two items in the karaf console I get these results:

openhab> openhab:items list JeeLinkSensor01_Humidity
JeeLinkSensor01_Humidity (Type=NumberItem, State=65 %, Label=Humidity, Category=humidity, Tags=[Measurement, Humidity], Groups=[JeeLinkSensor01])

openhab> openhab:items list XiaomiAqaraDHT01_Humidity
XiaomiAqaraDHT01_Humidity (Type=NumberItem, State=44.53, Label=Humidity, Category=humidity, Tags=[Measurement, Humidity], Groups=[XiaomiAqaraDHT01])

The Jeelink item shows a % but not the MQTT one.

I changed the values of these items manually to check if it might have something to do with the decimal places but no luck so far.

The value that gets sent from the binding depends on the channel type.
The MQTTv2 binding does not have a number:temperature channel type.

You can use a plain Number type Item and display units using the Items [state presentation] setting.

Or, new for OH3, you can use a transformation profile to take the plain number from MQTT channel, append a units string, and pass to a Number:Temerature Item type.

1 Like

This definetly makes sense to me, however OH kind of seems to transform this Number item to a Number:Temperature item (because I tell OH to do so?) and the correct unit is applied to this item.

So since the correct “transformation” already seems to be applied(?) I would assume that the ui would only get the state of the Number:Temperature item and display it as the defined Number:Temperature item type (21.11 °C).

Does it work for you?

Unfortunately not. :grimacing: The number is displayed without the unit.

Unfortunately, this doesn’t seem to work either. The transformation is applied as defined in my tranformation file but the UI is still unwilling to display the “°C”.
I tested the transformation by changing between °C and °F and by applying a constant value to the item state. Both tests work fine.

Number:Temperature  XiaomiAqaraDHT01_Temperature  "Temperature"  <temperature>. (XiaomiAqaraDHT01)  ["Measurement","Temperature"]   {widgetOrder="0", channel="mqtt:topic:broker:xiaomiAqaraDht01:temperature" [profile="transform:JS", function="addTemperatureUnit.js"]}
// addTemperatureUnit.js
(function (i) {
  return i.toString() + " °C";

The item in the main ui:

Hi Chris
take a look at this https://community.openhab.org/t/oh3-units/109020/9
That worked for me.


It also works if you configure your mqtt channel in main UI.
click configure channel,

then show advanced,
scroll down to “Unit Of Measurement”

enter your unit and click “done”

You’ve not asked for any particular display format. Try
"Temperature [%.1f %unit%]"

1 Like

Thanks, this works like a charm. I added the unit to the thing channel and now the “°C” is displayed in the main ui. :grinning:

// thing channel
Type number : temperature  "Temperature" [ stateTopic="<pathToTopic>/xiaomi-aqara-dht-01", transformationPattern="JSONPATH:$.temperature", unit="°C"]
// item
Number:Temperature  XiaomiAqaraDHT01_Temperature  "Temperature"  <temperature>  (XiaomiAqaraDHT01)  ["Measurement","Temperature"]  {widgetOrder="0", channel="broker:xiaomiAqaraDht01:temperature"}

[%.1f %unit%] <- the secret documentation only found if you’re lucky with google