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.
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 Thanks for your help, appreciated