OH3 - How to get Label text of item instead of name

In a widget, how can I get the Label text of the item instead of the item Name? For example in a component like this:

- component: Label
      config:
        text: =props.myItem

shows the item Name. What property gives the Label text. I’ve tried

=items[props.propItem].label
=props.propItem.label

also tried

getLabel()

Any solution?

You can’t get the label in the traditional way it’s defined. But I think you can set a label by setting the “State representation” metadata on the Item. Then you can use =items[props.propItem].displayState. Note, if you don’t have the metadata defined that will generate an error. So it might be good to use a ternary operation to check if that is defined and if not fall back to just show state.

I’ve used the Label field in the Item definition page to set a friendly name for my items. Is there then no way to access this from the widget?

Your recommendation then is to set a metadata value on the item? Am I understanding correctly?

Thanks!

No

Yes

1 Like

thanks… I was struggling to get the same.

As this is a very obvious need to get the item names in the UI, (we don’t want to do double entry of the name, just to feed the OH beast) I may see if I can prepare some PR to have this more easy available.

3 Likes

Exactly what I think. Why the f… there is no way to access the label of an item in a widget? :man_facepalming:

not sure if it helps (at least in some cases I guess) but oh-repeater and sourceType: itemsInGroup provides you with the item’s label name by loop.repeater-id.label

I need this too.

@marcel_verpaalen Have you created the PR?

nope… unfortunately this webUI programming is not so easy digest…

1 Like

And where is this ‘state representation’ set? because I cant see it as a option under setting metadata as you would alexa for example

The complexity of OH now has just gotten to the ridiculous level !

To be fair, half of your requests for help recently have nothing to do with OH 3. They are having to deal with stuff that has worked the same as it has since OH 2.0. Also, no one is required to use anything that’s new in OH 3. If OH 3 is too complicated, use it as if it were OH 2 and ignore the new stuff.

You can use my workaround here:

1 Like

Have there been any updates on this? I’m trying to get my list-widget working, but it just isn’t:

uid: windowstate_list
tags:
  - list
  - window
props:
  parameters:
    - context: item
      description: Window Item to display
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Jan 3, 2022, 11:39:57 PM
component: oh-list-item
config:
  icon: '=(items[props.item].state == "OPEN") ? "oh:window-open" : (items[props.item].state == "TILTED") ? "oh:window-ajar" : "oh:window-closed"'
  title: '=items[props.item].label'
  item: =props.item
  badgeColor: '=(items[props.item].state == "OPEN") ? "red" : (items[props.item].state == "TILTED") ? "orange" : (items[props.item].state == "CLOSED") ? "green" : "purple"'
  badge: '=(items[props.item].state == "OPEN") ? "OPEN" : (items[props.item].state == "TILTED") ? "TILTED" : (items[props.item].state == "CLOSED") ? "CLOSED" : "UNKNOWN"'


If I change the title to '=items[props.item].state' it shows:

If I change the title to =props.item it shows the name:

But no matter what I do, I can’t get it to show anything like the label or the groups the item is in or whatever.

Am I doing something wrong? I found this in the marketplace, and there title: =loop.item.label along with item: =loop.item.name seem to work just fine.

The label is only available in the repeater widget. Everywhere else all you get is state and stateDescription.

Is adding the ability to read the label outside of the repeater a planned feature?

I don’t know but I do know the developer has concerns about the performance of MainUI in that regard which is why it wasn’t implemented in the first place.