Tried to use state based icons in lovelace, but I cant get it to work

HI folks,

I have two cards,

one is only a “switch on when pressed” and goes off by itself, when consumption does reach a certain level. the lightning symbol in yellow and grey is perfect for it.

Ho ever right next to it I have a toggle button, that should not display the lightning symbol but a slider just like the table based switches.

I tried it with this

        state_icons:
          "off": "mdi:toggle-switch-off-outline"
          "on": "mdi:toggle-switch-outline"

and with this

square: false
columns: 2
type: grid
cards:
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: toggle
    entity: switch.steckdose_sm_printer
    name: Printer
    icon: >-
      '${if (states['switch.steckdose_sm_printer'].state === 'on')
      'mdi:toggle-switch-outline';else 'mdi:toggle-switch-off-outline'}'

both result in errors or no symbol at all, what am I doing wrong here?

THX

I assume the standard button card is not templatable. Use e.g. custom:button-card instead.

1 Like

I cant get button-card to work. my lovelace tells me there is no button-card available aside from the stock card.

I tried all I could find in here about what to put into the yaml to make it available.

hacs put in a url to hacsfiles with a hacstag on it.

I searched and found hints to put in this:


image

thats where it really is:

image

so by all means it should load, so what do I do wrong?

Most core lovelace cards are not templatable. Some custon cards like Custom Button Card, Card Templater, and Card Mod do allow templating.

Yes, thank you, I already installed custom:button-card from hacs, but it does not work, that was my follow up question…

Did you clear the browser cache?

strg+f5? yes

Then it could be a messed up HACS installation. Repeat the installation.

the hacs or the button card?

Reinstall custom:button-card.

1 Like

Thanks,

so I did a reinstall of the custom button-card, what i found was that HACS did indicate the button-card not being loaded in lovelace. this error in HACS is now gone

but still I get this:

i got it to work, i had to remove the " ’ " on type,

why would an empty card start with those " `` " when its not needed?

HA is so confusing sometimes.