After upgrading from openhab 4.1 to 4.3 not showing units

Hi everybody,
I just upgraded my openhab from 4.1 to 4.3 (latest docker image). I seems to work everything :), but in openhab 4.3 the units are not showing anymore in the default cards. Futhermore the values shown as int and not as decimal values.
For example:

In the Settings → Items page the units are shown and the values are shown as decimal value.

What do I have to do so that the items are shown with the correct unit and as decimal value in the cards (e.g default humidity card)?
In most cases I created the things and items from config file.

If you need futher information, let me know.

Thank you very much :slight_smile:

Whate the state description patterns for these items?

Hi @rlkoshak,
currently I’ve no state description pattern used (till 4.1 it wasn’t necessary).

I didn’t know that it’s necessary now but if you have them it’s the first place to look

What about the Item labels?

Item could get some state description metadata internally from the binding, even when you have not defined it explicitly on item.

I saw similar problems (not with units, but with numbers without decimals) when using MQTT binding and GenericMQTTThing. After one update (don’t remember which one) the numbers previously displayed with one decimal became integers.

Try to use API Explorer from developer tools and see what /getItems/{itemName} returns for your Item.

In my case I also don’t have any State Description metadata, but it still have some from the Thing’s channel:

{
  "link": "https://openhab.host/rest/items/ShellyCerpadloSpotreba_",
  "state": "106745.363000 Wh",
  "stateDescription": {
    "step": 1,
    "pattern": "%.0f %unit%",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "Wh",
  "metadata": {
    "unit": {
      "value": "Wh"
    }
  },
  "editable": true,
  "type": "Number:Energy",
  "name": "ShellyCerpadloSpotreba_",
...

So I solved it by adding my own state description metadata to Items I needed to display with decimal values.

Although I still wonder why mqtt binding provides such state description without decimals as default.

It seems that the pattern has changed from “%s %unit%” (openhab4.1) to %.0f" (openhab4.3).

Return of the rest api from openhab4.1:

{
  "link": "https://openhab:8443/rest/items/dressroom_multisensor_hum",
  "state": "44.24 %",
  "stateDescription": {
    "step": 1,
    "pattern": "%s %unit%",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "%",
  "metadata": {
    "unit": {
      "value": "%"
    },
    "semantics": {
      "value": "Point_Measurement",
      "config": {
        "relatesTo": "Property_Humidity",
        "hasLocation": "gDressroom"
      }
    },
    "HUEEMU": {
      "value": "155"
    }
  },
  "editable": false,
  "type": "Number:Dimensionless",
  "name": "dressroom_multisensor_hum",
  "label": "Ankleide Luftfeuchtigkeit",
  "category": "rain",
  "tags": [
    "Measurement",
    "Humidity"
  ],
  "groupNames": [
    "gDressroom"
  ]
}

and from openhab4.3:

{
  "link": "https://openhab:8443/rest/items/dressroom_multisensor_hum",
  "state": "43.08 %",
  "stateDescription": {
    "step": 1,
    "pattern": "%.0f",
    "readOnly": true,
    "options": []
  },
  "unitSymbol": "%",
  "metadata": {
    "unit": {
      "value": "%"
    },
    "semantics": {
      "value": "Point_Measurement",
      "config": {
        "relatesTo": "Property_Humidity",
        "hasLocation": "gDressroom"
      }
    },
    "HUEEMU": {
      "value": "155"
    }
  },
  "editable": false,
  "type": "Number:Dimensionless",
  "name": "dressroom_multisensor_hum",
  "label": "Ankleide Luftfeuchtigkeit",
  "category": "rain",
  "tags": [
    "Measurement",
    "Humidity"
  ],
  "groupNames": [
    "gDressroom"
  ]
}

Is there a way to change the pattern back to the old value (gloabl) so that I don’t have to change all my items?

The item is linked to what channel of what binding? The state description could come from this binding.
If you provide binding and channel, we could check if something was changed in this binding…

Oh sorry, missed that information: my example Item is linked to a generic mqtt thing. Thing configuration:

UID: mqtt:topic:home:aqara_multisensor_ankleide
label: MQTT - Aqara Multisensor - Ankleide
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:home
channels:
  - id: battery
    channelTypeUID: mqtt:number
    label: Battery
    description: null
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/aqara_multisensor_ankleide/battery
  - id: temperature
    channelTypeUID: mqtt:number
    label: Temperature
    description: null
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/aqara_multisensor_ankleide/temperature
  - id: humidity
    channelTypeUID: mqtt:number
    label: Humidity
    description: null
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/aqara_multisensor_ankleide/humidity
  - id: pressure
    channelTypeUID: mqtt:number
    label: Pressure
    description: null
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/aqara_multisensor_ankleide/pressure

I believe that @Mherwege was involved in a change regarding unit/pattern for MQTT binding.

Yes, here is the change: [MQTT] Fix state description by mherwege · Pull Request #16866 · openhab/openhab-addons · GitHub

This behaviour of the MQTT binding to use %s as state description pattern for numbers as well caused issues with QuantityTypes. In some cases, the unit would be shown twice.

I believe the current behaviour is consistent with the overall standard for bindings and core. The default has also been set to be in line with what is used from other bindings when there is nothing set in the binding state description pattern. You are able to override this.

In you specific case, the issue is you did not set a unit for your channels on the channel definition. OH cannot know what the unit of the value is you are receiving. Therefore, it interprets it as a plain number, therefore state description pattern will default to %.0f from the channel. If you set a unit on the channel (%), it should default to %.0f %unit%. Or you can set a state description pattern on the item.