i got another short question: Is it possible to add an alternative title to an item at the metadata (custom namespace) to display it in a custom widget?
If this is possible, how can i access the metadata in the widget?
There is an example posted by Yannick showing accessing Item metadata from an oh-repeater widget but I can’t seem to find it right now. It used the metadata to choose a different icon for different types of Items if I remember correctly.
When the oh-repeater return items (from the itemsInGroup or itemsWithTags etc.) the object that you can access via the loop variable is the complete object returned by the api /items/{itemname} call. So, if you need to see how to access something via the loop object, just use the API Explorer to see what the return of that item looks like.
I have the ToggleControl custom namespace defined for several items. If I use the api explorer to show me one of those items with that namespace specified, the return payload looks like this:
In that JSON you can see the metadata namespace with my custom ToggleControl metadata in it. So, if I had this item as part of an oh-repeater (with, say, remoteItem as the repeater variable) then loop.remoteItem.metadata.ToggleControl.config["1.0"] would get the string Switch_OfficeFanLight_OnOff.
Thanks for this! This seems to be exactly what i need. Now i just stuck with adding the metadata correctly to the item.
I tried to add the namespace altTitle:
There is one extra piece that you have to add to the oh-repeater. You’ll note that to make the API call you had to specify the metadata namespace you wanted returned. The API cannot just return all metadata to with an item. So, for the repeater, you also have to specify this namespace using fetchMetadata so it can pas that along to the api call. For your example then you just have to add the one line:
Also, you don’t have to use “1.0” as a key for the metadata, that’s just what my example item uses as part of one of my automation systems because that corresponds to one of it’s potential states. You can use whatever you wish that make more sense (and also avoids the awkward ["1.0"] as part of the object call. For instance, if you just used: