Mushroom Template card change card with a counter

Hello all,
I am trying to become lazier and have an integration to follow the number of dishwasher tabs at home AND to change the colors and possibly the icon when I will be soon short.

So I create my counter, named “counter.dishwasher_tabs”.

I also created an automation, that decrementes it after every run of my dishwasher. Both work.

And now I am trying to create a mushroom template card to follow this value… and something is wrong in my code.

type: custom:mushroom-template-card
        primary: Dishwasher tabs
        secondary: '{{states.counter.dishwasher_tabs.state}} tabs'
        icon: mdi:dishwasher
        icon_color: >-
          {% set tab= state('states.counter.dishwasher_tabs.state')}
          {% if tab > 7}
            green
          {% else %}
            red
          {% endif %}

To complete, I can see the correct number of tabs displayed in the “secondary” but my code to change the color is wrong, and I cannot see the problem. I tried to adapt it from other template card, but they were using sensors or things like that.

Please can you help me?

Hello @SavanFlou,

You missed several things in your code and the set tab variable is not right define, that’s why is not working right.

This code should work fine:

type: custom:mushroom-template-card
primary: Dishwasher tabs
icon: mdi:dishwasher
icon_color: |-
  {% set tab = states('counter.dishwasher_tabs') | float %}
  {% if tab > 7 %}
  green 
  {% else %}
  red
  {% endif %}
secondary: "{{states.counter.dishwasher_tabs.state}} tabs"

Some recomendations to take into account:
1- Counter helper is giving you a value that you must to convert as float.
2- Don’t forget to close the variables and the if properly.
3- I recommend you to use states(“entity_id”) to get the status of an entity instead of states.entity_id.state. You can find more information in Templating - Home Assistant

I hope this is helpful for you.
Regards.

Thank you very much for all those explanations.
“Unfortunately”, I discovered Bubble Card and changed all my presentation with it so…
But I will try to keep your advice in mind when I will create new stylings.