Need help with temperature conversion in item meta data stateDescription

  • Platform information:
    • Hardware: x64
    • OS: Debian 11
    • Java Runtime Environment:
    • openHAB version: 3.1.0
  • Issue of the topic: struggling to get temperture conversion to work using transformation pattern

I have a temperature sensor publishing data to a MQTT broker. The sensor measures in °C. I get the sensor data into OH using an MQTT binding and in my Thing/channel I set units of measurement as °C. I have changed my region to try both SI and Imperial but nothing changes.

The problem is that I would like to display my temperture on the site map as °F. I know how to do this with a JS sript (profiles) but I was under the impression that I could instead use a transformation pattern in my item. In the UI and editing my item, I add “stateDescription” metadata and in the pattern field “%.1f °F”. When I hit save, I will briefly (1 measurement) see my data get transformed to °F (correct number and format) but then the value goes back to the °C value (raw Celsius value, but correct number format).

Is it possible to do a temperature conversion at the item through stateDescription?
Can I do a temperature conversion at the channel using “Incoming Value Transformation”?


Start here

Thanks, that went pretty deep. So some unexpected behavior. I was able to address the issue by:

  1. changed the MQTT type from number to string.
  2. adding a JS transformation in the MQTT channel - Incoming value transformation:
  3. writing some code for the addC.js file that appends a °C to the incoming data
(function(i) {

    return (i+"°C");

  1. keeping the transformation to °F at the item stateDescription:
    %.1f °F