How to change Icon color depending on state

I’ve configured a group with lights as follows.
image

Now I want to display a light icon and the number of lights that are turned on in a widget. The icon should change color: “off” when no light is on, and yellow when a light is on.

image

component: oh-label-card
config:
  action: group
  actionGroupPopupItem: Gruppe_Licht
  icon: oh:lightbulb
  iconColor: "=(items.Gruppe_Licht.state > 0 ) ? 'yellow' : 'grey'"
  iconUseState: true
  item: Gruppe_Licht
  noBorder: false
  title: Licht

How can I achieve this with the “oh:light” icon?

You are mixing two different approaches.
If you set iconUseState = true you need to use dynamic oh:icons such as oh:slider which changes its look each 10% the icon state changes.
If you want to change the color of an item in general you cannot use oh:icons and need to use f7 or material icons?

Yes, you’re right.
But how can I use the dynamic oh:icons in this case?

I don’t find the light icons on F7 or the material icons as nice as the oh:icon.

component: oh-label-card
config:
  action: group
  actionGroupPopupItem: Gruppe_Licht
  icon: oh:lightbulb
  iconUseState: true
  item: Gruppe_Licht
  noBorder: false
  title: Licht

try it

icon: =#'Gruppe_Licht' == 0 ?'oh:light-off':'oh:light-on'

Your widget config is now correct. The only issue is that there is a difference between oh:lightbulb and oh:light. The lightbulb icon is not dynamic, but the light icon is. So, you just need to use:

icon: oh:light

image
This does not work. Maybe the problem is that the group item is of type number and not of type switch?!

icon: =#'Gruppe_Licht' == 0 ?'oh:light-off':'oh:light-on'

Unfortunately this doesn’t work either.

Yes, sorry I missed that initially. The iconUseState does work with a number, but in that case the number is the brightness of the light icon from 0 - 100 (in steps of 10) so if you just turn one or two lights on you will not see any change in the icon. To have the icon change from just on to off based on the number state of the group, you will need to use the formula provided by @Tschetan.

This formula is correct for newest versions of OH. What version of OH are you using? If you are on an older version you may need to use:

icon: =items.Gruppe_Licht.numericState == 0 ?'oh:light-off':'oh:light-on'

or

icon: =Number.parseInt(items.Gruppe_Licht.state) == 0 ?'oh:light-off':'oh:light-on'

or

icon: =items.Gruppe_Licht.state == '0' ?'oh:light-off':'oh:light-on'

instead.

Thanks, @JustinG - this works! And to @Tschetan, too!

I’m using openHAB 4.3.4.