I'm doing something wrong, not even AI can solve it - using the Items label as the name in a UI widget

I’m using 5.0.2 and this is my code, which fails to display the items ‘label’ for my Dimmer and Switch lights.

Can someone suggest a modification please? I’m pulling my hair out.

Thank you

uid: Dimmer
tags: []
props:
  parameters:
    - context: item
      description: An item to control
      label: Dimmer Item
      name: dimmeritem
      required: true
      type: TEXT
timestamp: Jan 1, 2026, 12:45:00 PM
component: f7-card
config:
  class:
    - padding
  noShadow: false
  style:
    border-radius: 12px
    box-shadow: var(--f7-card-expandable-box-shadow)
    height: 6.2em
slots:
  default:
    - component: Label
      config:
        # Wattage logic
        text: "=(items[props.dimmeritem].state === 'OFF' || items[props.dimmeritem].state === '0') ? '0.0 W' : (props.dimmeritem.includes('Ensuite')) ? (items.EnsuiteLEDNum1.displayState || items.EnsuiteLEDNum1.state) : (items[props.dimmeritem.replace('Dim1', 'Num1')]) ? Number.parseFloat(items[props.dimmeritem.replace('Dim1', 'Num1')].state).toFixed(1) + ' W' : '--- W'"
        style:
          position: absolute
          top: 0.7em
          right: 1em
          font-size: 12px
          font-weight: 700
          color: "=(items[props.dimmeritem].state === 'OFF' || items[props.dimmeritem].state === '0') ? 'grey' : 'white'"
    - component: Label
      config:
        # OH5 Documentation Method: The @ prefix fetches the LABEL directly by name
        # We use brackets to ensure the parser treats it as a dynamic lookup
        text: ="@" + props.dimmeritem
        style:
          color: white
          font-size: 15px
          line-height: 30px
          overflow: hidden
          position: absolute
          text-overflow: ellipsis
          top: 0.5em
          left: 1em
          white-space: nowrap
          width: calc(100% - 120px)
    - component: oh-toggle
      config:
        color: green
        item: =props.dimmeritem
        style:
          left: calc(100% - 110px)
          position: absolute
          top: 1.2em
    - component: f7-row
      slots:
        default:
          - component: f7-col
            slots:
              default:
                - component: f7-icon
                  config:
                    f7: rays
                    style:
                      color: grey
                      font-size: 12px
                      left: 1.2em
                      line-height: 15px
                      position: absolute
                      top: 3.2em
          - component: f7-col
            slots:
              default:
                - component: Label
                  config:
                    text: =items[props.dimmeritem].displayState || items[props.dimmeritem].state
                    style:
                      color: grey
                      font-size: 12px
                      left: 3em
                      line-height: 15px
                      overflow: hidden
                      position: absolute
                      text-overflow: ellipsis
                      top: 3.2em
                      white-space: nowrap
    - component: oh-slider
      config:
        color: green
        item: =props.dimmeritem
        label: false
        max: 100
        min: 0
        noShadow: true
        outline: false
        scale: false
        style:
          left: 1.2em
          position: absolute
          top: 4.8em
          width: calc(100% - 2.5em)

Not seeing a issue using your code on my openhab install
All I had to do to see the label was change it from white to black.

config:
        text: ="@" + props.dimmeritem
        style:
          color: Black
          font-size: 15px
          line-height: 30px
          overflow: hidden
          position: absolute
          text-overflow: ellipsis
          top: 0.5em
          left: 1em
          white-space: nowrap
          width: calc(100% - 120px)

btw your wattage label also shows but it is white color also and shows as grey when the bulb is off.

Thanks Justin, I’ve no idea whats going on . Ill fix the wattage, thank you!

That will be:

items[props.dimmeritem].label

Just for a better readability:
You can replace this

by:

text: =@props.dimmeritem

Accessing the label of a dynamically defined item is still a difficult thing to do in widgets. There are workarounds, but they are not really worth it. In a case where you have a widget with a single item property, it is almost always easier, to just add a second text parameter to allow you to add the label manually as part of the widget config. Considering that the most likely use case for most widgets includes a one time adding and configuration of the widget to a page or two, it is a much better use of time to just type in the label that once than trying to dynamically get the item label in the widget code (it’s also a better UX design because getting the label will require an API call, and every one of those you add to a page slows the page load another few ms).

Did you actually see this in the documentation somewhere or is this AI hallucination? To my knowledge this is not and has never been true for widget expressions.

I don’t think this will work either. The object returned by items.itemName still does not contain the label of the item.

Thanks for pointing this out. I forgot it is only working within an oh-repeater.

What do you mean second text parameter? And yes, AI is writing this. Zero chance I could write it.

Honestly, I bet you could do a better job. I guarantee you could do a better job with a little bit of trial and error and one or two forum questions. The fact that some models have improved enough to generate widget yaml that doesn’t crash is impressive. On the other hand, they are all still a long way from getting something as specific as OH widget configuration correct (this isn’t me picking on LLM’s; the simple truth is that the data volume just isn’t there for the statistics to work yet).

The text color issues @justaoldman pointed out are a great example of the AI failing here. It doesn’t know enough about the whole widget system to understand that setting a static white text color is a really bad idea in this f7 based UI. (For the record, just use var(--f7-text-color) instead of white.)

Your widget includes a single parameter right now:

props:
  parameters:
    - context: item
      description: An item to control
      label: Dimmer Item
      name: dimmeritem
      required: true
      type: TEXT

and there are several places that the widget expressions include props.dimmeritem to indicate the name of the item you have selected.

You can add another configuration parameter to be able to include a widget label:

props:
  parameters:
    - context: item
      description: An item to control
      label: Dimmer Item
      name: dimmeritem
      required: true
      type: TEXT
    - description: The widget label
      label: Label
      name: label
      required: true
      type: TEXT

Then where you want the label to appear you just use the widget expression =props.label.

Yes, and as also stated the item label value is not available if you opened widget editor and replaced this line

text: ="@" + props.dimmeritem

with

text: =(items[props.dimmeritem])

your widget would show you all the available items you have for that item.
so using my example widget from above it would show you this for that labels value.


as you can see there is no choice for a items label value as an option to select.
if you added
text: =(items[props.dimmeritem]).type
you would see this as the label

and so on for each of the exposed possible choices your selected item exposes.
notice there is no option for

"label:(*your labels value*)"

so, it is not exposed thus it cannot be referenced within the widget easily.
you can add the props as stated above and statically set the widget to match the items label value but not dynamically pull it as you wanted.
I also apologize for not being clearer in my first response to you I had totally forgotten I set my item label value same as my item name for ease of testing on my lab install.

Thanks guys, ive made the widget changes suggested by Justin and then in the UI page just hard coded the name. That does the job enough for me! I have zero desire to learn how to code this stuff so AI iteration is good enough :slight_smile: Thanks for your help, appreciated