Dynamic Basic Ui Icons in Sitemap. Only showing the default icon

Hello openHAB friends,

I am Using a Raspberry Pi 3+ with openhabian and today I was working for my devices an online rule, where the icon changes with the online and offline state. It was working fine, but the icons would not change. As Example the network icon.

When the device is offline, their showing in the sitemap the network-off icon. But it is the normal network icon. This is only working with a switch.

After I downloaded the network-on.svg and network-off.svg renamed it to network_on.svg/network_off.svg and put it in the costume icon folder, then it works.

Example not working, shows the default icon (network):

            Text item=Oneplus_5_Status icon="network-on" visibility=[Oneplus_5_Status=="Online"]
            Text item=Oneplus_5_Status icon="network-off" visibility=[Oneplus_5_Status!="Online"]

Example working with renamed icons:

            Text item=Oneplus_5_Status icon="network_on" visibility=[Oneplus_5_Status=="Online"]
            Text item=Oneplus_5_Status icon="network_off" visibility=[Oneplus_5_Status!="Online"]

But why can’t the sitemap show the different types of the icon when I use an icon="xxx"? Same is when I put the icon name behind an item with <icon>, shows the default icon too.

It’s kind of suggestion for improvement :wink:


The icon provider uses the hyphen “-” as a special character as part of its auto selection mechanism.
That means that you cannot use any “ordinary” icon filenames that include a hyphen. It’s a documented limitation of sitemaps.

To get the dynamic icon working in your case; you seem to have a string Item that can take on states “Online” and I guess “Offline”. You’d provide icons that match the states, so myicon-online.svg and myicon-offline.svg. Remembering of course that you must also provide the default version of the name, myicon.svg, as the documents say.

Take care that you have selected the right icon type in your UI default settings.

Most people use a Switch Item to represent “onlline” and “offline”, and in that case the icons will map to someicon-on.svg etc. They’ll also use a MAP to convert ON/OFF into some text.