Change automation entity icon based on state on or off

I have an automation which creates a custom color loop.
on my dashboard a glance card with an entity for that automation with the tap action to toggle the automation on or off.

This is the glance card entry which works fine

      - entity: automation.office_color_loop
        name: Office colorloop
        tap_action:
          action: call-service
          service: automation.toggle
          service_data: 
            entity_id: automation.office_color_loop

I am trying to change the picture in the glance card based upon the state on or off of the automation. I used the code below in customize.yaml but to no avail.

automation.office_color_loop:
  data_template:
    entity_picture: >
     {% if is_state('automation.office_color_loop', 'true') %}
       /local/img/colorloop.png            
     {% else %}
       /local/img/colorloop_off.png
     {% endif %}

any input is appreciated

The glance card doesn’t not natively support changing backgrounds dependent on an entity state. However you can use this:

thanks for the advice.
Are there any card types natively allowing changing entity icon?

The picture entity card lets you change the background image:

OK. So I installed card-modder: works great.
I am unclear however where I should configure the entity-picture now. As in my question above based upon the state of the entity.

image

Ah sorry I thought you wanted to change the card background.

Try this instead:

Thanks. I keep trying but no success. Config-template-card installed and works but code

  • type: ‘custom:config-template-card’
    entities:
    • automation.office_color_loop
      card:
      type: custom:hui-glance-card
      entities:
      • entity: automation.office_color_loop
        entity_picture: “${ states[‘automation.office_color_loop’].state === ‘on’ ? ‘/local/img/colorloop_off.png’ : ‘/local/img/colorloop.png’}”

does not yiels expected result. it uses default entity picture

image