I’m trying to do something, and I’m not sure in possible in openhab. I want to do something that is similar to the existing widget : battery status.
Basically, I want to display all my items representing a battery on a single page, and print their values to see at first glance if I have batteries that need changing. However, all my battery items are simply named ‘Battery’ and rather than changing all my labels, I wanted to display the parent group name.
To make it simple, I have:
Group bedroom “Bedroom Sensor” (batteries)
Item bedroom_battery “Battery” (bedroom)
Item bedroom_temperature “Temperature” (bedroom)
Group kitchen “Kitchen Sensor” (batteries)
Item kitchen_battery “Battery” (kitchen)
And my idea was to list all members of “batteries”, cast as GroupItem, find the battery item in its members, and then print group.label + " : " + item.state + " %"
I had to do something similar and couldn’t figure out how to get the group name so I ended up using metadata instead to do a “friendly name” that’s different from the label. My items goes by timestamp but the title part you can probably use as a start:
- description: Title of widget
- context: item
description: Group to list
timestamp: Nov 8, 2022, 4:48:36 PM
- component: oh-list
- component: oh-repeater
- component: oh-list-item
badge: '=((dayjs(loop.item.state).diff(dayjs().startOf("day"), "days")) == 0 ? "OK" : "Not Responding")'
badgeColor: '=((dayjs(loop.item.state).diff(dayjs().startOf("day"), "days")) == 0 ? "green" : "red")'
title: =loop.item.metadata.ExtendedInfo.config.friendlyName + " " + loop.item.label
and then on the items in the group, I have this custom metadata named ExtendedInfo - chosen just to keep it generic in case I needed to add more info later:
value: " "
friendlyName: Kitchen Motion Last Updated
As long as your chosen custom metadata name matches the “fetchMedatata” value in the widget, that’s what matters.
Edit: groupItem is a separate group that contains the items I want this widget to show for clarification
The Items you get in the browser that can be used in the widgets are not the same as the Items you work with in rules. In a regular widget, all you get is state and displayState. In the repeater widget you get a bit more like you can access Item metadata (like @tardismechanic demonstrates).