Hi,
Newbie Home Assistant user here, just started using eco system a couple months ago and I love it; far better than just using HomeKit. I’m at the stage where I would like features not available on the stock install.
That said, I’m using Custom Button-Card, and can’t seem to get the icon color to change based on the state.
Screnshot below, icon is still grey, state shows as “Finished”, but icon won’t change to Green. Any help would be appreciated.
Thanks for the responses, truly appreciate this community.
Since my dishwasher is no longer in “Finished” state, I’m testing with the “Off” and “off” state, incorporating @jeffcrum’s suggestion; and it still does not want to work for me; screenshots below.
In one place you define grey, in another green… remove the “grey” line and define colors for other states.
It is better not to use the “states” option here since you will have to define same grey color for other several possible states. Instead, use JS template to define a color dependently on a state in “styles” option directly, see examples in docs.
I figured it out! All the suggested codes worked. I was just a dummy newb.
I did not know that what is displayed on “show_state” is not always the actual state value. Example, for LG Dishwashers State of “Off” has the Value of “power_off”.
I learned this by accident, after doing a custom button for motion sensors where State of “Clear” has the Value of “off”.
So to know the different state values, go to Developer Tools → States → look/filter for the entity → and look at Attributes column.
Hopefully this info helps future newbs.
For those curious, here is my custom button code for my dishwasher; it has icon changes and a bit of animation. The goal for this button is so I have easy to see visual cue on my wall mounted dashboards.
type: custom:button-card
entity: sensor.dishwasher_current_status
section_mode: true
icon: mdi:dishwasher
show_state: true
name: Dishwasher
# This is for extra animation
extra_styles: |
@keyframes pulse {
0% { transform: scale(1); opacity: 1; }
50% { transform: scale(1.1); opacity: 0.8; }
100% { transform: scale(1); opacity: 1; }
}
@keyframes shake {
0% { transform: rotate(0deg); }
25% { transform: rotate(5deg); }
50% { transform: rotate(0deg); }
75% { transform: rotate(-5deg); }
100% { transform: rotate(0deg); }
}
@keyframes rotating {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
state:
# For Finished state us "end"
- value: 'end'
color: green
icon: mdi:dishwasher-alert
styles:
icon:
- animation: pulse 2s ease-in-out infinite
# For Off state us "power_off"
- value: power_off
color: grey
icon: mdi:dishwasher-off
styles:
card:
- filter: opacity(50%)
# Below is for all other states
- operator: default
color: yellow
icon: mdi:dishwasher
styles:
icon:
- animation: shake 0.8s ease infinite
grid_options:
rows: 2
columns: 3