Need some guidance, custom metadata and using with expressions in widgets

Good afternoon.

I am working on a widget that will display the state of items that will be in a group (a Notifier widget)
The widget will be an oh-list and use a repeater to parse the states of items in a group.

Here is the setup:

  • the item group is called notify_group
  • an example item: notify_Roborock_Dock_State
  • the state for the notify_Roborock_Dock_State which I would use as a false: No error

What I am attempting to do is create a custom metadata that contains an icon name and the state of the item that is considerted to be ‘false’, meaning there are no issues.
The example item is also an item i created that uses the ‘Dock Status’ string channel for the Xaomi binding. If there is a ‘true’ evaluation i will display the state, for example 'Error fresh water tank’.

The custom metadata I have added the the above item is called ‘notifier’ and is as follows:

value: " "
config:
  icon: robot
  falseState: No error

Here is a snippet of the code that I am attempting to use to evaluate, but I definately need some guidance. I have been reading as many posts as I can find, but am not having any luck as I am trying to piece together a bit of information from several posts so my evaluation statement may be completely incorrect. The snip is also based on widget yaml from another post which I am trying to update for my goal.

The line for the badgeColor is where I am attempting to use some expression parsing for the metdata. I realise the iconColor and badge lines will not work properly as they are written.

          - component: oh-repeater
            config:
              for: item
              sourceType: itemsInGroup
              groupItem: =props.item
              fetchMetadata: notifier
            slots:
              default:
                - component: oh-list-item
                  config:
                    title: =loop.item.label + " " + loop.item.state
                    icon: f7:ant
                    iconColor: '=loop.item.state == "ON" ? "green" : "red"'
                    badgeColor: '=loop.item.state == loop.item.metadata.notifier.value.config.falseState ? "green" : "red"'
                    badge: '=loop.item.state == "false" ? "OK" : "ERROR"'

A thought as well, can the evaluation be stored in a variable which could be used on the iconColor, badgeColor and badge statements instead of evaluating the metadata multiple times for the same information?

Hope this information has enough details for what I am trying to achieve!

Thanks for your help
Craig

I’m not super great at expressions so there might be more wrong than this, but your path to the metadata is wrong.

YAML is hierarchical. Stuff that’s at the same level of indentation are siblings (i.e. at the same level in the hierarchy). That means value and config are at the same level. config is not a child of value.

So to access the config you’d use loop.item.metadata.notifier.config.falseState.

Now I cannot say if it should be “config” or “configuration” (I hope it’s the former) or if there are other problems, but the above is definitely at least one problem.

Thanks Rich.

I’ve updated the expression and it is pointing correctly. I’ve been staring at this for the longest time and had a feeling something looked wrong but didn’t clue in.

I added another line and it displays the content of falseState as ‘No error’.

footer: '=loop.item.metadata.notifier.config.falseState'

Craig

It is evaluating and working, thank you so much @rlkoshak !

I have added another item to the group and it is working.

Thanks
Craig