Hi,
I try to write a widget that shows all items of a thing via the oh-repeater:
But some of the items do not have a category, thus there is no icon shown:
For the others it is working pretty cool .
I tried to assign a customized category and saved an icon with the same name in the icon folder (svg+png). But this is not working.
Does anyone know how to link an icon file to a customized category? (I searched for this topic but did not find any working solution up to now.)
Many thanks in advance!
No ideas for this topic? I continue to try to find a solution, but so far to no avail.
JustinG
(JustinG)
December 21, 2023, 2:02pm
3
What is the exact folder that you put the icon in? The docs are quite specific about where the custom icon files need to be placed:
If you have the icon files in the correct directory then this should work with no additional steps.
Wolf-2022
(Wolf)
December 21, 2023, 11:49pm
4
I am using OpenHab 4.0.3 on a Synology docker. I placed the icons here:
(I am already using dynamic customized items for widgets -e.g. roller shutters-, but not for custom categories.)
JustinG
(JustinG)
December 22, 2023, 3:58am
5
Yep, so thatās all correct. What you are trying to do definitely works; I do it myself.
Do you see the icon popup when you enter the category in the model editing page?
Also, I would suggest that you check the API explorer to make sure that the items API actually returns the value you are expecting for category
:
"name": "Speaker_SonosRoam",
"label": "Sonos Roam",
"category": "sonosroamflat",
No, I donāt see the icon popup.
The files for the category in the mentioned directory:
And here what the API explorer says:
Oh man, I found my mistake: the capital letters. I changed them to lowercase and it works .
Nevertheless many thanks!!
One additional question: is there any possibility for different icons in relation to the value of the item (like for QualityOfService)?
JustinG
(JustinG)
December 22, 2023, 7:00pm
9
Yes, a little further down in the doc linked above there is a section on how to create custom dynamic icons.
Short-short version: add -statevalue
to the base icon name (all lowercase still).
Wolf-2022
(Wolf)
December 25, 2023, 7:53am
10
Itās working under settings/items:
But in the widget it is shown like this:
That is the code of the test widget:
uid: Test_Code
tags: []
props:
parameters:
- default: Header text
description: Header text shown on top the widget
label: Header
name: header
required: false
type: TEXT
- context: item
default: ShellyPlus2PM_001
description: related item to displayed data
label: Item
name: item
required: true
type: TEXT
parameterGroups: []
timestamp: Dec 25, 2023, 8:34:52 AM
component: f7-card
config:
title: '= (props.header != "Header text") ? props.header : props.item'
slots:
default:
- component: oh-list
config:
title: Alle Daten
slots:
default:
- component: oh-repeater
config:
for: item
groupItem: = props.item
sourceType: itemsInGroup
fragment: true
slots:
default:
- component: oh-list-item
config:
icon: = loop.item.category
iconUseState: true
title: =loop.item.label + ":"
badge: =items[loop.item.name].displayState || items[loop.item.name].state
And to complete all information , here are the corresponding file names:
In the widget it is only showing the ābaseā icon, both for standard and for custom icons!?
JustinG
(JustinG)
December 25, 2023, 2:38pm
11
There is no item actually configured with your list item. Just because the component is being rendered as the child of a repeater doesnāt mean there is any automatic addition of the repeater array to the componentās configuration, so, it has no way of knowing which item is supposed to be used to get the state which should used to modify the icon.
You also need to add:
item: =loop.item.name
Wolf-2022
(Wolf)
December 26, 2023, 9:23pm
12
Great, many thanks & Merry XMas !