I've found several solutions to change a icon color in lovelace based on a entities state, but I can't get it to work on light entities and other entities that give certain icon colors by themselve.
Ideally, I would like to the lights, media_players, etc. icons behave like binary_sensors: a certain color for off state and a certain color for on state. I don't want to see a blue icon when my lights turn blue.
What works now is:
- entity: light.light_group_living_room
name: false
state_color: false
toggle: true
styles:
--paper-item-icon-color: '#ffc107'
icon: mdi:lightbulb
This will set the icon's color, but not dynamically. I believe I can't use jinji templating here to change the color based on the state. I've tried to replicate this 'solution' by using card_mod (so I can using templating to determine the color based on state), but haven't been able to figure it out yet.
Home Assistant docs point out to using '--state-light-on-color' but this doesn't seem to work.
Preferably, I would like to replicate the solution to the other 20 lovelace buttons, but I have no idea how to make the code small and re-usable (don't check specific entity-ids but use self() functions).
Anyone here to give me a start in the right direction?