Change icon based on item state using a String


Is it possible to change the icon (e.g light bulb) based on the state when using a with a item String i can do this when i set a item as a switch?

i currently have a ESP8266 set up to read the sate of a smoke alarm. and sends back either 1 or 0 depending on if the alarm i activated. if i set the item as a switch the icon charges depending on the state however it will on show ON or OFF in the BasicUI and i would prefer it to have say CLEAR OR FIRE DETECTED i can do this setting the item as a string but can achieve both at the same time. when setting the item as a string the icon wont change. can i get the best of both woulds or not?

i am using a map to change the 1 or 0 sent by the ESP to openhab to CLEAR OR FIRE DETECTED.


Yes, keep the Item as a Switch and use the map in the Item’s label.

Or use a String Item and create custom dynamic icons.

if i have it as a switch as below

Switch   F2_Fire       "Fire Alarm [%s] "            <Fire>         (gAlarm)          {mqtt="<[mqttoh2:/Alarm/fire/fire:state:MAP(],

then my map has to be


for it to work but i would like to change the ON/OFF to CLEAR OR FIRE DETECTED but when i do this openhab stops show the right State


can you tell me where am i going wrong please

You need two maps. One that you use on the binding like you are now and another you use in the label. See the transformations link provided above.

hi thank you for your help, i understand the idea of what needs to be done. just cant get it to work with what i have, i just dont think i have the skills to but it in to practice at the moment i think i will need to return to this when i understand what i am doing a little more.


I think what you want is this.

Switch   F2_Fire       "Fire Alarm [MAP(] "            <Fire>         (gAlarm)          {mqtt="<[mqttoh2:/Alarm/fire/fire:state:MAP(],

1 Like

Thank you, have got it working

Yeah sorry I forgot its [MAP(]