I am sure that it has to work somehow. Unfortunately, I don’t have the necessary experience with OH to find a solution quickly.
If it is really my system, I will probably solve it through NgIf. But 10 ngif for an icon is not very “nice”.
I would like to make my widget available to others, I think they are not that bad in terms of design
For Beginners like me are some Templates very helpful and i really like to share if i have something that someone can use
So I gave up and now I have my quick and dirty solution working. Unfortunately not elegant but at least it works. If someone still has a proposal, I would still be very interested, since this solution cannot be in the spirit of the inventor
Finally I have the solution!
For everyone who is still looking for the “correct” solution for dynamic icons, I would like to leave the solution here.
Think that’s the elegant and correct way to implement it.
Unfortunately, I am not the hero in programming and maybe that’s logical for many, but nobody pointed out to me that the state attribute was used to directly select the icon dynamically.
With this line you can use your own dynamic icons in the HABPanel.
<widget-icon iconset="'custom-icon'" icon="'youriconname'" size="25" state="itemValue(config.your_item)"/>
// Your Icon Name without the -Value. So if you`ll use a Icon like battery-0 until battery-100 you have just to write icon='"battery'"
This reduces the code enormously and there is no need for the IF loops.
In many widgets that can be downloaded from the gallery, this is also solved with if loops, which would not be necessary.
Apparently the [state] variant does not seem familiar to many.
I would close my question and thank everyone who tried to help me.
Hi,
Is it possible to use dynamic icons with decimal values? I need it to reflect LiFePO4 cell voltage. (e.g cell.svg, cell-2.50.svg, cell-3.20.svg… etc.) Would be great if possible to do without converting these values to %%