Change icon and color on Entities card for one entity

Hello,

I have a Google Wifi sensor, and i want to change the icon if state == Online

I tryed this from my dashboard:

type: entities
entities:
  - entity: sensor.google_wifi_status
    secondary_info: none
    name: Status
    icon: |-
      {% if is_state('sensor.google_wifi_status', 'Online') %}
        mdi:wifi
      {% else %}
        mdi:cancel
      {% endif %}
    icon_color: |-
      {% if is_state('sensor.google_wifi_status', 'Online') %}
        green
      {% else %}
        red
      {% endif %}

But, this don’t work, and i try lot of things templating but i don’t know why i can’t use interpreted code inside this key.

Can you help me please ?

OK, i found.

Need to use template-entity-row to do what i want :smiley:
Thanks

type: entities
entities:
  - entity: sensor.google_wifi_status
    type: custom:template-entity-row
    secondary_info: none
    name: Status
    state: |-
      {% if is_state('sensor.google_wifi_status', 'Online') %}
        En ligne
      {% else %}
        Hors ligne
      {% endif %}
    icon: |-
      {% if is_state('sensor.google_wifi_status', 'Online') %}
        mdi:wifi
      {% else %}
        mdi:cancel
      {% endif %}
    color: |-
      {% if is_state('sensor.google_wifi_status', 'Online') %}
        green
      {% else %}
        red
      {% endif %}

I’ve been looking for a solution to OP’s question too, and am grateful for this explanation!

Now… I have lots of entities on many cards. Do I have to go and copy this formatting to every one of them separately? Is there no way to do it generically?

So, for example, I have an Entities card with a list of a dozen irrigation stations. I want any station that is currently active “on” to be highlighted a different color from the rest. So do I have to manually update each of the dozen entities to type:custom-entity-row and add the if/then/else to every one of them, one at a time?
Or is there any way to do it more programatically? Maybe someone knows of another card type (not Entities), that lets you give it one config to highlight the “on” entities in it? etc.

Also: what if I want to change the background (highlight) color of a row, rather than the icon color?
I can’t figure out the label to use.

Thanks to OP for this suggestion, it solved my problem. To streamline the repetitiveness of the formatting code I used a call to the custom:decluttering-card passing (in my case) the entity and name of entity as variables. Worked just fine even from within a custom:fold-entity-row.