Have been trying to animate and spin an icon in a custom button card relating to the state of my car - charging, connected, level of charge. I can get the icon to change colour based on the charge level, but have had no success getting it to:
- blink if the charge level is below a specified point
- Spin if the charger is connected and charging
I am not sure whether my code is wrong, or whether these functions are not supported in this button. The code I have is below
Thanks in advance for any advice
entity: sensor.mike_s_tesla_range_sensor
icon: 'mdi:car-electric'
name: Tesla Range Sensor
show_state: true
styles:
card:
- border-radius: 10%
- '--paper-card-background-color': 'rgba(0, 0, 0, 0.4)'
- box-shadow: none
icon:
- color: |
[[[
if (entity.state >= 175) return 'green';
if (entity.state >= 125 && entity.state < 175) return 'yellow';
else return 'red';
]]]
- animation:
- - - if (entity.state <= 100) blink 2s ease infinite
- spin: |
[[[
if (states["binary_sensor.mike_s_tesla_charger_sensor"].state =
"Charging") return true
else return false
]]]
name:
- color: white
state:
- color: white
type: 'custom:button-card'