How to take advantage of item metadata widget configuration

I do not get the meaning of defining the widgets in the item metadata. Let’s take this as example:

String                  DebugItem               "A item to debug [%s]"                               <water>                    {widget="oh-card"[icon="oh:water"],listWidget="oh-label-item"[icon="oh:water"], cellWidget="oh-label-cell" [icon="oh:water"],title="My Water"}

with this we get the following:

Let’s say I want to edit the list item widget and set an icon.

If I add this item to a list card as label list item like this:

                    - component: oh-list-card
                      config: {}
                          - component: oh-label-item
                              item: DebugItem

The icon is not shown. My expectation was: every time this item is used in a list it is rendered as specified in the item metadata.
So how to use this in a widget? Or more generally: how does it correspond to the widget yaml?

Your expectation is not quite what is going on. The default widget metadata is only for specifying the name of the widget that the item uses in either a standalone or list context. There is no further configuration available through that particular metadata namespace.

When calling a widget it is not possible to send just any information to it, the widget’s only a small set or parameters that can be passed in during widget creation. All the widget metadata does is call the specified widget and if that widget has a parameter that is defined as an item it passes the name of the item to the widget.

If you want the widget fully customized you’ll have to build it yourself in the editor.

People are using parameters for the widgets though (e.g. [OH3] Add metadata to Items via configuration files).

Can someone please show a good example when and how to use this? Or explain the concept?

Apologies, I misunderstood your initial question. The actual answer is:

The “default” widgets for an item are not the widgets or widget settings that are used anytime this item is used anywhere; they are only the widgets that are used if the item is included in one of the UI autogenerated contexts.

So the Default Standalone Widget for an item is, for example, used in it’s item details page, but not if you just try to include that item in a custom page or widget. The default list item is used whenever that item appears in a group list or (if it’s part of your semantic model) in one of the cards on the locations, equipment, or properties tabs, but not if you are building a custom list as part of a widget.

If you are really going to use one particular configuration in many different custom pages and widgets, you can create an individual custom widget that includes all the configuration you want to be standard and a configurable item parameter (plus parameters for whatever else you might want to be able to configure) and then use that custom widget in other yaml definitions like this:

- component: widget:name_of_custom_widget
    item: SomeItemName

As I said in my previous (somewhat confused) response, however, if you are going to do this, any thing you want to be able to control about this widget you are including needs to be defined as a parameter, you would not have access to the config space of the components in name_of_custom_widget from the calling widget or page.

1 Like