Display state no longer working?

Hi,

I’m on 4.1.3 Release build and I’m flabbergasted about getting a state transformed.

I’m using the MQTT binding and receiving a large float which represents a temperature value in degrees. It has a lot of decimals, so I want to trunk that into 2 decimals. What I normally do is add metadata stateDescription and set a pattern like %.2f °C.

This however does nothing. It does not trunk it to two decimals.

When I use a label widget, the non trunked value is shown. And no value is shown when explicitly use the displayState like =items['mqtt_victron_temperature_ambient'].displayState

When I pull the item from the rest API, the non-trunked value is returned.

I’m a doing something wrong?

{
    "link": "http://<url>/rest/items/mqtt_victron_temperature_ambient",
    "state": "20.610000610351562 °C",
    "stateDescription": {
        "step": 1,
        "pattern": "%.1f °C",
        "readOnly": true,
        "options": [
            {
                "value": ""
            }
        ]
    },
    "unitSymbol": "°C",
    "commandDescription": {
        "commandOptions": [
            {
                "command": ""
            }
        ]
    },
    "metadata": {
        "unit": {
            "value": "°C"
        },
        "stateDescription": {
            "value": " ",
            "config": {
                "options": "",
                "pattern": "%.1f °C"
            }
        }
    },
    "editable": true,
    "type": "Number:Temperature",
    "name": "mqtt_victron_temperature_ambient",
    "label": "Victron - Temperature - Ambient",
    "tags": [],
    "groupNames": []
}

There might be a bug here and an issue has been filed. See oh-rollershutter-item with stateInCenter set doesn't respect State Description Pattern · Issue #2612 · openhab/openhab-webui · GitHub. That is for rollershutter Items but it might be relevant to what’s happening here.

However, first verify where you are looking at the state of the Item. The state description doesn’t actually change the state of the Item. Even with a pattern of %.1f the Item’s state will still be 20.610000610351562 so that’s what you’ll see in events.log, the REST API, and on the Settings → Items page.

That’s also what you’ll see in your widgets if you use the state as opposed to the displayState. Note that displayState only exists on the Item in the UI widgets when the state description pattern exists and is applied. So the fact that it’s not points to a problem with the state description being applied.

I would try restarting openHAB and force reloading the browser just to make sure there isn’t some issue with caching. If it’s still a problem, all I can recommend is to chime in on that issue above or open a new issue. Though it’s not clear that the problem is in fact on UI side. It might be on the core side.