Construct Other Item Names from another

Hi,

Title is possibly a bit confusing but I wasn’t sure how to describe what i’m trying to achieve.

Basically I have a number of items. named as follows

MainItem
MainItem_RawData
MainItem_Lat
MainItem_long
ect…

Now what I want to do is write a function which can accept a string containing “MainItem” but then the function then gets the state of the MainItem_RawData and then posts an update to the MainItem_Lat and MainItem_Long. postupdate accepts a string so that bit is easy.

I’m not sure how I get the MainItem_RawData as it cannot seem to contruct the string for the item I want and subsequently get the state.

I hope this is not too confusing. I’m trying to avoid passing all the items into the function as I’ll max out the arguments.

Thanks,
Chris

Well, if openHAB actually had objects in its scripting, this kind of common use case would be easy.

Unfortunately, you have to hack it together. You can put all the pieces into a group and use the group as a collection with MainItem.members.filter and a lambda expression to select the member you want by name. The next level up is similar; put all the MainItems into a group and select by name, some property, or one of the pseudo-properties

Practical examples