State presentation [%d] in item label possible in MainUI?

In OH2 there are state presentation available to add state values of an item to its label, like

"Temperature [%d °C]"

Is there anything similiar available in OH3?

Yes
Go to Setting —> Items
pick your item
pick Add Metadata
pick State Description
then enter your state description in Pattern

No, sorry. This is not what I meant

Go on …

hmm. I thought I could not be more precise than to give an example:

Andrews suggestion is to replace the state. I am asking for for the state within the item’s label

Do you intend to use for example a text field in a widget? Then you can just use an expression. Nor sure if that is what you mean?

text: = "BATT is " + (items.ShellyUNI_VoltageADC_Battery_Level.state) + " at " +
              (items.ShellyUNIshellyunie8db84d6b3e510163199230_VoltageADC.state)
                + " " + (items.ShellyUNI_VoltageADC_Percentage.state) + "% " +
                (items.ShellyUNIshellyunie8db84d6b3e510163199230_Temperature.state)

I have quite a few items of type ON/OFF (switch item) which are transformed by hysteresis profile from a number channel.
Example: state of a thing channel holds temperature, e.g. 60°C
I link a switch item to that number channel which is
ON when temperature is > 80°C and is
OFF when temperature is < 80°C.
the LABEL of the item is e.g.

 "Error - Overheating"

sure, I could link a second item to that channel which holds the actual temperature and combine both item states in either rules or widgets.

However, if I were able to provide the current temperature inside the LABEL of the switch item

Error - Overheating 83°C

then there is no need to have 2 items per channel

Well, you didn’t get that in a display in OH2 either.
The part in [ brackets ] is a state description - the siremap based UI’s would use to format the display of the Item state. Typically on the right hand side of BasicUI. The label text - without any state or [format] - would appear on the left hand side of the display.
It is not, never been, possible to display some other Item’s state in either of those places just by using a state description.

People do sometimes use a rule to edit the Item label, added text could of course be derived from any Item’s state. That’s unchanged from OH2 to OH3.

myItem.label = "bananas"
myItem.label = "bananas " + otherItem.state.toString

Beware, there are no guarantees any UI will promptly refresh any change of label.

it was an attempt to provide an easier description of my question. omit the comparison with OH2.

my question is just if the item label is capable of holding the value - probably not…
a more detailed description of the background of my question I provided a second before your post.

interesting approach. will try that.

EDIT: no. does not make things better. will still require to have two items

There’s no way around that. Even though they’re using the same channel, one of your items is a switch and the other is a number. You can’t have a single item that’s both.

Yes, of course. You want two bits of information. You can present both of them in one UI widget.

If you absolutely must have one Item, go at it the other way round. Have your temperature Item, and a rule that examines the state and decides to set the label to “Temperature” or Temperature ALARM". Or write a widget that displays red text if state > xx, etc.

No, that was not my suggestion. My suggestion was to add a State Description in the item’s metadata.

in OH3 item’s label… in the UI?
I use

=items.MyItem.state

in the label and it works

thanks again Andrew. Unfortunately, it does not solve my problem.
As described above the item is being transformed into ON/OFF.
That’s why I was asking for something like injecting the channel state into the ITEM LABEL

There is nothing, will be nothing, to accomplish that. channel state updates go into Item states.
From there, you can do many things … like updating any random Item’s label.
What’s the problem here, is someone charging you per Item?

there is no problem. Andrew was so kind as to answering again on my comment. I just do not wanted to be impolite by not reacting to his response.

But you seem to have problem with me

What about using =items.MyItem.state as well as =items.MyItem.displayState

I use something similar for presence. The .state is ON/OFF but .displayState is IN/OUT via the the following State Description Meta Data:

MAP(presence.map):%s

File contents:

ON=IN
on=IN
OFF=OUT
off=OUT
CLOSED=IN
closed=IN
OPEN=OUT
open=OUT
-=-
undefined=-
uninitialized=-
NULL=-

So items.GPSMarkatHome.state gives ON/OFF
and items.GPSMarkatHome.displayState gives IN/OUT

He has an Item with state ON/OFF. No amount of transformation can recover the “60°C” used previously to set the Item, from a state like ON.

However it’s not such a bad idea the other way around …
Put the 60°C in your Item state.
Use a SCALE transformation in Item presentation metadata to create a threshold, transforming 60°C to OFF or “okay”, 90°C to ON or “Alarm”.
Now plain state is 60°C and displayState “okay”, available in MainuI widget.

1 Like

try this in a dsl rule:
trigger e.g. myItem state has changed

myItem.label = String::format("any text "+myItem.state.toString())
myItem.postUpdate(myItem.state)

// this renames myItem label to “any text myItemstate”