Change icon based on item state using a String

Hello

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.

Thanks

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

https://docs.openhab.org/addons/transformations.html

Or use a String Item and create custom dynamic icons.

https://docs.openhab.org/configuration/items.html#icons-dynamic

if i have it as a switch as below

Switch   F2_Fire       "Fire Alarm [%s] "            <Fire>         (gAlarm)          {mqtt="<[mqttoh2:/Alarm/fire/fire:state:MAP(test.map)],
<[mqttoh2:/Alarm/fire/fire:command:ON:1.00],<[mqttoh2:/Alarm/fire/fire:command:OFF:0.00]"}

then my map has to be

1=ON
0=OFF

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

fire%20alarm

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.

thanks

I think what you want is this.

Switch   F2_Fire       "Fire Alarm [MAP(test2.map)] "            <Fire>         (gAlarm)          {mqtt="<[mqttoh2:/Alarm/fire/fire:state:MAP(test.map)],
<[mqttoh2:/Alarm/fire/fire:command:ON:1.00],<[mqttoh2:/Alarm/fire/fire:command:OFF:0.00]"}

test2.map

ON=FIRE DETECTED
OFF=CLEAR
1 Like

Thank you, have got it working

Yeah sorry I forgot its [MAP(test2.map):%s]