[SOLVED] Change icon depending on string

Hello,
I have a string defined

String string_chargingcircuit "Charging circuit: [%s]"

and the string can be

ONLINE
OFFLINE

I have to icons

akku_laden_offline.svg
akku_laden_online.svg

how can i change the icon depending on the string??

You need to name your icons like this:

akku_laden-offline.svg
akku_laden-online.svg

You also need an icon named:

akku_laden.svg

And then add the icon to the item definition like this:

String MyItemName "MyItem Label" <akku_ladden> { channel="whatever" }
1 Like

Rename your icons xxx_xxx-offline.svg etc.
The hyphen is important.
You must also provide a default xxx_xxx.svg
Then add an icon target to your Item definition <xxx_xxx>

All of this is in the docs for dynamic icons.

String string_chargingcircuit "Charging circuit: [%s]" <charging>

icon name

charging-offline.svg
charging-online.svg

sitemap

Text item=string_susvchargingcircuit

string is loaded via

var string_localsusvchargingcircuit =  executeCommandLine("/bin/sh@@-c@@(grep 'Charging circuit' /etc/openhab2/services/susv.status | cut -d' ' -f4)", 5000)
string_susvchargingcircuit.postUpdate(string_localsusvchargingcircuit)

but it is not working

Did you stop OH and clean the cache after making the changes mentioned above?

You have ignored two of us telling you that you must have a default icon version. It really will stop it working.

The Item name in your sitemap is not the same as the Item you have shown us.

same question but with temperature

how to define the icon names ?
i have tested with different icon names, but nothing seems to work correctly.

temperature.svg
temperature-cold.svg
temperature-hot.svg
temperature-5.svg
temperature-10.svg

i always get the same temperature icon.
image
image

also here, its vice versa
image

Your first task is to find out what states your Item is taking up. Random hyphen extensions will not work.

Your next task is to choose a name for your icon family that is not one of the built in icon names - names such as temperature will not work. It will always serve icons from the default set before looking for your custom icons.
https://www.openhab.org/docs/configuration/iconsets/classic/

i understand, but the default set comes with 3 different “temperature” icons, which are not working as intended, or am i wrong ? (when do they trigger?)
my alternative custom temperature icon comes with a different name.
And i am not smarter then before now. thanks anyway

from the openhab docu:
image
image

Then name your icons differently:

temperatur.svg
temperatur-cold.svg
temperatur-hot.svg
temperatur-5.svg
temperatur-10.svg

For example

Yes.
temperature.svg , temperature_hot.svg , temperature_cold.svg
None of those are dynamic icons and will not respond to state changes.
(The hyphen is the magic part. Different from underscore.)
To select any one as a fixed icon, you would use its name.

The existence of temperature.svg in the standard icon set prevents you from using any custom or dynamic icon family with that same name. temperature-10.svg etc. simply will never work. temperatur-10.svg or mytempicon-hot.svg and suchlike will be fine.
With the usual proviso that you must provide the “base” or default hyphenless version of any family of icons even if you never expect to see it. It will not work if you don’t.

See battery for an example - hover over the icon for the filename
https://docs.openhab.org/v2.1/addons/iconsets/classic/readme.html