Hello dear community,
I am using openHAB 4.2.1 on my Raspberry Pi 5 and wanted to try out a widget in the widget designer with a repeater for the first time. Unfortunately, without success.
loop is a general object that contains several different sub-objects so you cannot just use items[loop] you have to use items[loop.someLoopVariable]. But, how do you know what someLoopVariable actually is?
Your repeater is missing a critical property which sets the name of the loop variable: for.
So the correct combination looks something like this:
The third error is that items['Some Item Name'].label will not return anything. The items object is not a complete representation of an Item (that much data transfer for every use of items in the UI would cause a very slow and buggy interface). The items object only provides the State of the Item (as a string) and a few other often useful pieces of information such as the type of the Item and the State of the Item as a number (if it is a number type Item).
Thank you for the clear explanation. It worked immediately. Can you also tell me what is the best way to display a label or defined text for each item in the array?
The repeater has two source options that directly query the API for full information about Items:
So, you can use either the itemsInGroup or itemsWithTags source types to get an array of the complete information about those Items. Of course, this means putting the Items you want in a group or giving them all some consistent tag first.
In this case, once you have that true item array then loop.myLoopVariable.label will, in fact, contain the actual label of the item.
Beware: your array will also include an Item State (loop.myLoopVariable.state), but this is NOT a dynamic value. It is the value of the State at the time the repeater makes the API call and it will not change unless you refresh the repeater and it makes a new API call. You still must use the items object to get a value that will change in real time with the State of the Item (items[loop.myLoopVariable.name].state).