Entity text/icon colour / color

So I’ve seen this gets asked every so often, now I’m checking where we are with lovelace given it is the default visualisation rendering engine.

Can I change the colour of an icon and/or text for an entity based on its state

examples include
a sensor being online|offline
a binary sensor being on|off
a person being home|away
a sensor being low/medium/high

etc

I’m aware that this might be possible with CustomUI, different icons for each state, entity button card, or a picture elements card - none of these are particularly simple though…

1 Like

I too would like to know this (> 1 year later).
I’m particularly interested in changing colour of person based on home (green) and away (red).

Thanks. Looking through other posts about custom-ui and I saw:

So, looks like I can do it with card-mod, which I already have installed.

if that works for you, good.

I’ve got this, using Custom-UI

sensor.rockrobo_netgear_tracker:
  friendly_name: Robo Vacuum
  icon: mdi:robot-vacuum
  templates:
    icon_color: if (state === 'Offline') return 'red'; else if (state === 'Online')
      return 'green'; else return 'blue';