Dynamic icon not working for String item

  • Platform information:

    • Hardware: Raspberry Pi
    • OS: Linux raspberrypi 5.4.83-v7l+
    • Java Runtime Environment: openjdk
    • version: “11.0.9.1” 2020-11-0
    • openHAB version: 3.0
  • Issue of the topic: always getting default icon

  • Please post configurations (if applicable):

    • Items configuration related to the issue

      • String FurnaceActivity “Furnace Status [%s]” (hw_ff_thermostat) [ “Status” ]
    • Rules code related to the issue - send command based on temnperature. The rules are working as I see the state in the UI.

      • sendCommand(FurnaceActivity, “heating”)
      • sendCommand(FurnaceActivity, "cooling
      • sendCommand(FurnaceActivity, “off”)
      • also tried: FurnaceActivity.sendCommand(“heating”) and FurnaceActivity.postUpdate(“heating”)
    • icons/classic

      • thermostat-cooling.png
      • thermostat-heating.png
      • thermostat-off.png
      • thermostat.png

No matter what I always see the default icon:
thermostat

Sitemaps? MainUI? HABPanel?

Sorry in the OH3 main UI it is not working.

I just checked my old sitemap and it seems to work there:

Red is heating and blue is cooling.

What’s the Item’s config? Specifically did you define a default list widget? If not you need to and choose “oh:thermostat” as the icon and toggle “Item icon depends on state” to ON (you may have to toggle Show Advanced to see the toggle).

It might be because you didn’t use code fences and the forum has hidden <youricon>,but nothing there says to use your icon set.

I am using a text file configuration:

//Thermostat
Group  hw_ff_thermostat "Thermostat"  <thermostat-off> (FF_Entryway) [ "HVAC" ]
Number hw_thermo_setpoint_num "Thermostat Setting [%.1f]"  <temperature>  (hw_ff_thermostat) [ "Setpoint", "Temperature" ]
Number hw_thermo_temp_num "Thermostat Temp [%.1f]"  <temperature>  (hw_ff_thermostat)  [ "Measurement", "Temperature" ]
String hw_thermo_mode "Thermostat Setting [%s]"  <temperature>  (hw_ff_thermostat) [ "Status" ]
String hw_thermo_comm "Thermostat Comm [%s]"  <temperature>  (hw_ff_thermostat) [ "Status" ]
String hw_thermo_vac "Thermostat Vac/Norm [%s]"  <temperature>  (hw_ff_thermostat) [ "Status" ]
String FurnaceActivity "Furnace Status [%s]"  <thermostat>  (hw_ff_thermostat) [ "Status" ]

How do I do that in a text configuration?

You’ll have to set the Item metadata on the Item. Probably the easiest way to do it will be to create a test Item, configure the metadata through the UI, and then look at the code tab to see the proper field names and formatting.

I don’t use items files any more and there is enough in OH 3 now that is controlled through metadata that I can’t even imagine trying to do it all in .items files. Each Item would be 20+ lines of code or more to do it all.

In reality, using the text file setting of <myicon> just results in an entry in the JSONDB version of the Item as
"category": "myicon"

Are we saying this has been repurposed or ignored in MainUI - but not in the other available UI and apps? Or must we now maintain two completely separate sets of Items properties for display in MainUI and for other UI?

I tried adding { iconUseState="true" } to the item but that did not work.

What I did to get to work was open the Settings -> Model find the item that from the text file and then press the Add Metadata button. As @rlkoshak suggested I added a Default List Item Widget. I selected Show Advanced and checked the Icon depends on state box and Saved.

Then it started working:

Yippy. Thanks All.

Would be nice to be able to define this in the items file.

Category is used by MainUI by default but doesn’t support dynamic icons. If you want dynamic icons or any customizations you have to override the default widgets in metadata.

Click on the code tab.

It’s item metadata. The namespace is listed in the title bar (e.g. listWidget).

The value goes next and then the config.

value: oh-toggle-item
config:
  icon: f7:lightbulb
  iconColor: '=(items.FrontRoomOutlet.state == "ON") ? "yellow" : "gray"'
  title: Front Room Lamp
  color: '=(items.FrontRoomOutlet.state == "ON") ? "yellow" : "gray"'

would translate to something like

listWidget="oh-toggle-item"[icon= "f7:lightbulb", iconColor=.. ']

A reference for all the widgets and properties is in work so for now you’ll want to configure it in the UI and translate back to the. items

Okay, it’s a regression. To have dynamic icons in both UI, uhh, families, we have two different settings to maintain.

EDIT - the more I think about this, the flakier it seems.
In the “olde world”, we would just choose “an icon”. If “the icon” was in reality a set of dynamic icons, it just worked.
We could choose the icon in sitemap, separating presentation from Item. (We could give the Item a default icon, but the presentation/sitemap took priority.)

Tacking an essential presentation feature back on to each individual Item seems retrograde to me.