Use state_attr in custom:button-card

Hi,
I 'm new here.
I try to change the rotation speed of the fan icon in a custom button card.
But my if_else is not working.

- animation: |-
         [[[  
           if ({{state_attr('fan.woning_fan', 'percentage')}} == 100) return 'rotating 1s linear infinite';
           if ({{state_attr('fan.woning_fan', 'percentage')}} == 50) return 'rotating 2s linear infinite';
           else return 'rotating 5s linear infinite'; 
         ]]]

What i’m doing not right ?

Welcome :slight_smile: The syntax is wrong:

- animation: |-
    [[[  
      if (states['fan.woning_fan'].attributes.percentage == 100) return 'rotating 1s linear infinite';
      if (states['fan.woning_fan'].attributes.percentage == 50) return 'rotating 2s linear infinite';
      else return 'rotating 5s linear infinite'; 
    ]]]

It uses javascript [[[ ]]] and needs to be formated accordingly.

1 Like

Thank you for the fast answer
it works fine

1 Like