Change MDI Icon and Color based on state

Hi all,

I’m using custom ui and i try to change the color and the icon of an entity based on its state.
I’ve tried the following code but it didn’t work:

    sensor.nas01_status:
      templates:
        icon: >
         if (state === 'good') return 'mdi:checkbox-marked-circle-outline';
         else return 'mdi:close-octagon';
        icon_color: >
         if (state === 'good') return 'rgb(67,167,47)';
         else return 'rgb(219,27,8)';

When I use an entity card to display the sensor I get the correct color and correct icon. When i change the
state to something else then good the color and the icon didnt change. When Im using a picture-glance card
I didnt even get the right color. Maybe someone of you can point me in a direction.

Thanks in Advance.

sensor.nas01_status:
  custom_ui_state_card: state-card-custom-ui
  templates:
    icon: if (state === 'good') return 'mdi:checkbox-marked-circle-outline'; else return 'mdi:close-octagon';
    icon_color: if (state === 'good') return 'rgb(67,167,47)'; else return 'rgb(219,27,8)';

Sent too soon. The above needs to be in customize.yaml with

  customize_glob:
    sensor.*:
      custom_ui_state_card: state-card-custom-ui

in your configuration.yaml

Cool, thank you that did the trick for mdi icons in entity cards. The bad news is that in glance picture cards it still didnt work:(

The View in Lovelace:
glance

But the entity view (when clicking on the icon) shows the correct color value:
entity

Hmm maybe its an issue with custom-ui.