I have a Sonoff TH16 flashed with Tasmota that is communicating with openHAB via MQTT. I have been able to configure the appropriate Generic MQTT Thing and added a channel for the temperature that uses a JSONPath Transform to extract the temperature as a string value from the Sonoff’s SENSOR topic. I am able to create an Item of type text and create a link to the channel to display the temperature value. My question is how do I create an Item via Main UI to display the temperature as a number?
I’ve read that many folks have historically preferred to create things via UI and items via a configuration file. I have also found their solution to my question as follows…
Things file:
Thing topic sonoff11 “Living Room Light” @ “Living Room” {
Channels:
Type number : temperature “Temperature” [ stateTopic=“tele/sonoff11/SENSOR”, transformationPattern=“JSONPATH:$.DS18B20.Temperature” ]
}
Items file:
Number LivingRoom_Light_Temp “Temperature [%.1f °F]” { channel=“mqtt:topic:pibroker:sonoff11:temperature” }
I know that it’s been reiterated that the preferred way to do things in openHAB 3 is via the UI. To be specific, where in the Main UI do I have the option of performing a number conversion (using Temperature [%.1f °F] or similar) from a string value received from a Thing channel when creating a new Item?
You can also add channels of number type. (It was a good idea to experiment with strings first, to see how stuff works out)
Channels of number type have a units parameter you can set, as shownin the docs. You may or may not need that depending on your payload.
Create the Channel as a Number:Temperature Channel. Link it to a Number:Temperature Item.
You’ve already done the hard part of parsing out the number value from the JSON. So if you use the right Channel type and Item Type it will all be done for you by default.
When you create the Item, create it as a Number:Temperature.
That addresses the XY Problem.
To answer your specific question though, set the State Description Item metadata and configure the Pattern with the same thing you would put between the [ ] in the label config.
Note that if you have a Text (i.e. String) Channel, you can’t link it to a Number Item and have to use a String Item. And if you have a String Item %.1f °F won’t work. f means floating point number so that sort of format will only work with a Number Item.
Thanks it worked perfectly. I had tried this previously and it didn’t work. I figured out that I previously configured the channel as a text type and there is no option to reconfigure a channel type (to number) once it is created without deleting it and recreating it. The absence of type settings in the (re)configuration screen is the bit that I was missing.