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.
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?
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:
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: