Variable for item name within standard Main UI widgets

Out of easyness I’d like to access item names by a variable (e.g. var(item) or var(actionCommand)) within a STANDARD MainUI component to be used for other properties.
This makes it easier to copy/paste directly in yaml code


- component: oh-label-card
    action: command
    actionCommand: OFF
    actionItem: TestItem
    Item: TestItem
    label: Test
    background: '=(items[var(item)].state == [var(actionCommand)]) ? "blue" : "green"'

is this possible?

You used the wrong syntax and for me it’s not relay clear what you want to simplify here?

it is easier to maintain your pages if you add new items or if you replace item.

I do not mean variable in the way which is described in your link. have a look at how I try to access an item and the value of actionCommand by an ‘implicit’ variable in the last line of my example (background:)

sure it is wrong syntax, as it is just for explanation purpose. what is the correct syntax?

Your question was…

The link I quoted explains what types of variables are available in OH and how they have to be structured to access an item name which is stored in that variable. To be precise =items[vars.someVar].state

What I think you realy want to know, if it’s possible to access the value of a config parameter which answer is no as far as I can tell. And I personally does not see a benefit in doing so - but feel free to open an issue for that if you seeing something that I’m not aware of.

You can doing all of that with properties inside a custom widget of course.

correct. that’s why I wrote ‘implicit’ variable like triggeringItemName which is available to rules without the need of declaring them .

so short answer: no, it is not possible.

You can verify this by e.g. adding the following code to config.label (where TestItem is the openHAB item toy want to use in the widget:

label: =JSON.stringify(items[TestItem])

The label will display the entire contents of the JSON object returned by openHAB3, and it only contains 1 tuple, as in:


So unfortunately the item name is not available through a property of the item. Maybe this could be changed by filing a PR to the openHAB core developers.