#custom:button-card state animation

1 messages · Page 1 of 1 (latest)

icy kite
#

For the life of me, I cant get the state animation to work, even when following the docs to the letter. https://github.com/custom-cards/button-card?tab=readme-ov-file#configuration-with-states

I'm wrapping the custom:button-card inside a conditional card:

        - type: conditional
          conditions:
            - entity: light.livingroom_ceiling_fan
              state_not: unavailable
          card:
            type: custom:button-card
            entity: light.livingroom_ceiling_fan
            name: Ceiling Fan
            template: fan-button
            icon: mdi:fan
            aspect_ratio: 1/1.1
            hold_action:
              action: more-info

As for the animation, the docs say to do this:

        - type: conditional
          conditions:
            - entity: light.livingroom_ceiling_fan
              state_not: unavailable
          card:
            type: custom:button-card
            entity: light.livingroom_ceiling_fan
            name: Ceiling Fan
            template: fan-button
            icon: mdi:fan
            aspect_ratio: 1/1.1
            hold_action:
              action: more-info
            state:
              - value: 'on'
                styles:
                  icon:
                    - spin: true

however, this does not work.

If I remove the state: requirement, and move the styles: to the same level as the rest of the card options, then the icon spins.
I know using a 'light' entity for a fan is non-standard, this is a dimmer switch flashed to ESPhome presenting the dimmer as a brightness value.
I've verified the state of the entity is actually 'on' when the entity is on:
[<template TemplateState(<state light.livingroom_ceiling_fan=on; supported_color_modes=[<ColorMode.BRIGHTNESS: 'brightness'>], color_mode=brightness, brightness=38, icon=mdi:fan, friendly_name=Livingroom Ceiling Fan, supported_features=40 @ 2024-11-01T14:11:02.156155-05:00>)>]

GitHub

❇️ Lovelace button-card for home assistant. Contribute to custom-cards/button-card development by creating an account on GitHub.

vapid oak
#

does it work if you take it out of the conditional card?

icy kite
#

I meant to mention that. It does not work outside of the conditional card either

vapid oak
#

ok, that's something at least

#

just to rule it out can you try replacing the value line with:

- operator: template
  value: '[[[ return entity.state == "on" ]]]'
#

also, can you paste your template: fan-button and any other sub-templates?

icy kite
#
button_card_templates:
  standard:
    color_type: card
    size: 80%
    hold_action:
      action: more-info
    styles:
      card:
        - padding: 0.2em
        - '--mdc-ripple-color': yellow
        - '--mdc-ripple-press-opacity': 0.5
      icon:
        - opacity: 0.5
      name:
        - font-size: 0.65em
        - white-space: normal
      state:
        - font-size: 0.65em
        - white-space: normal
      label:
        - font-size: 0.4em
        - white-space: normal
  standard-button:
    template: standard
    state:
      - value: 'on'
        styles:
          card:
            - background-color: gold
          name:
            - color: blue
          icon:
            - color: blue
            - opacity: 1
      - value: 'off'
        styles:
          card:
            - background-color: slategrey
          name:
            - color: white
          icon:
            - color: white
            - opacity: 0.5
  fan-button:
    template: standard-button
    state:
      - id: value_on
        value: 'on'
        icon: mdi:fan
      - id: value_off
        value: 'off'
        icon: mdi:fan-off
vapid oak
#

oh wait, never mind

#

i think i've got it

#

spin: true doesn't go in the style section

icy kite
#

Not seeing any difference

            type: custom:button-card
            entity: light.livingroom_ceiling_fan
            name: Ceiling Fan
            template: fan-button
            icon: mdi:fan
            aspect_ratio: 1/1.1
            hold_action:
              action: more-info
            state:
              - value: "on"
                spin: true
vapid oak
icy kite
#

looks like two areas state: can be declared?

- type: custom:button-card
  [...]
  styles:
    card:
      - xxxx: value
    icon:
      - xxxx: value
    entity_picture:
      - xxxx: value
    name:
      - xxxx: value
    state:
      - xxxx: value
    label:
      - xxxx: value
  state:
    - value: 'on'
      styles:
        card:
          - yyyy: value
        icon:
          - yyyy: value
        entity_picture:
          - yyyy: value
        name:
          - yyyy: value
        state:
          - yyyy: value
        label:
          - yyyy: value
vapid oak
#

i think that styles > state is fundamentally different

#

but idk, i've never used it

icy kite
#

alright. Let me try with a new dashboard

vapid oak
#

well like i said, this is working for me

type: custom:button-card
entity: binary_sensor.home_occupied
name: Ceiling Fan
icon: mdi:fan
hold_action:
  action: more-info
state:
  - value: 'on'
    spin: true

(I set it up before you copied the templates so i deleted that bit)

icy kite
#

okay, I'm getting somewhere now, thanks for the help!
On a new dashboard, the entity works as expected:

views:
  - title: Home
    cards:
      - type: custom:button-card
        entity: light.livingroom_ceiling_fan
        name: Ceiling Fan
        icon: mdi:fan
        aspect_ratio: 1/1.1
        color_type: card
        size: 80%
        hold_action:
          action: more-info
        styles:
          card:
            - padding: 0.2em
            - '--mdc-ripple-color': yellow
            - '--mdc-ripple-press-opacity': 0.5
          icon:
            - opacity: 0.5
          name:
            - font-size: 0.65em
            - white-space: normal
          state:
            - font-size: 0.65em
            - white-space: normal
          label:
            - font-size: 0.4em
            - white-space: normal
        state:
          - value: 'on'
            spin: true
          - id: value_on
            value: 'on'
            icon: mdi:fan
          - id: value_off
            value: 'off'
            icon: mdi:fan-off
          - value: 'on'
            styles:
              card:
                - background-color: gold
              name:
                - color: blue
              icon:
                - color: blue
                - opacity: 1
          - value: 'off'
            styles:
              card:
                - background-color: slategrey
              name:
                - color: white
              icon:
                - color: white
                - opacity: 0.5
#

I removed all the templates and consolidated them to a single card

vapid oak
#

weird....

icy kite
#

okay, copy/pasted the working card on top of the broken card in the original dashboard, and the animation works.

#

It must have something to do with the templates

vapid oak
#

very strange

icy kite
#

It's this template breaking the spin feature:

  standard-button:
    template: standard
    state:
      - value: 'on'
        styles:
          card:
            - background-color: gold
          name:
            - color: blue
          icon:
            - color: blue
            - opacity: 1
      - value: 'off'
        styles:
          card:
            - background-color: slategrey
          name:
            - color: white
          icon:
            - color: white
            - opacity: 0.5
#

frustrating thing is that IIRC, the docs specifically state that templates can be overridden

vapid oak
#

They can, I have done that myself

#

Do you know which bit is breaking it? Just deleting sections until you find the minimum boot that stops it working

icy kite
#

That's what I'm doing now -
this standard-button: config still results in a non-spinning icon:

  standard-button:
    template: standard
    state:
      - value: 'on'
        styles: null
      - value: 'off'
        styles: null
#

If I remove the state: and everything underneath, then the icon spins

vapid oak
#

Hmmm

icy kite
#

I'm curious why , for example, template fan-button: utilizes state IDs, and standard-button: has direct state values

vapid oak
#

I didn't even know id was a key for state

icy kite
#

I'm thinking I should mirror the fan-button configuration to the standard-button template, then set up the values again

vapid oak
#

But it worked in your big merged one

icy kite
#

true

vapid oak
#

Grrr

icy kite
#

yep, that was it

vapid oak
#

Oh yeah?

icy kite
#

Templates

button_card_templates:
  container:
    color_type: label-card
    color: dimgray
    styles:
      card:
        - padding: 0
      name:
        - border-radius: 0.4em 0.4em 0 0
        - padding: 0.1em
        - width: 100%
        - font-weight: bold
      grid:
        - grid-template-areas: '"i" "n" "buttons"'
        - grid-template-columns: 1fr
        - grid-template-rows: 1fr min-content min-content
      custom_fields:
        buttons:
          - background-color: rgba(0,0,0,0.3)
          - margin: 0
          - padding: 0.3em
  standard:
    color_type: card
    size: 80%
    hold_action:
      action: more-info
  standard-button:
    template: standard
    state:
      - id: value_on
        value: 'on'
        styles:
          card:
            - background-color: gold
          name:
            - color: blue
          icon:
            - color: blue
            - opacity: 1
      - id: value_off
        value: 'off'
        styles:
          card:
            - background-color: slategrey
          name:
            - color: white
          icon:
            - color: white
            - opacity: 0.5
  fan-button:
    template: standard-button
    state:
      - id: value_on
        value: 'on'
        icon: mdi:fan
        spin: true
      - id: value_off
        value: 'off'
        icon: mdi:fan-off

This works!

#

Button Config

                - type: conditional
                  conditions:
                    - entity: light.livingroom_ceiling_fan
                      state_not: unavailable
                  card:
                    type: custom:button-card
                    template: fan-button
                    entity: light.livingroom_ceiling_fan
                    name: Ceiling Fan
                    icon: mdi:fan
vapid oak
#

Sweet

icy kite
#

Thanks again for bouncing ideas 🙂

vapid oak
#

It's required for templates overrides of state apparently

icy kite
#

ahh, makes perfect sense now. I have no idea what I'm doing, so I've been copypasta creating buttons that utilize custom:button-card

vapid oak
#

Ah lol

#

Here I thought you were being so fancy with your nested templates :p

icy kite
#

Oh, that was from https://community.home-assistant.io/t/fun-with-custom-button-card/238450
to ensure the entire array utilizes the same format.
I thought it was a good idea, so I kept it.
ESPhome utilizes the same idea in their device configurations

vapid oak
#

Nice. That's very organised

icy kite
#

Now the next project - and I'm not asking for help, so don't feel obligated 🙂
Consolidate Low/Med/High/Off to a single button. Havent decided yet whether to do a vertical-stack and keep the discrete settings, or just have a single button activate select.select_next and output the current state

vapid oak
#

Do a slider

icy kite
#

I'm trying out a few different dashboard configurations -
I have smart switches, that can be set to 'relay-on' or 'relay-switched', depending on whether smart bulbs are attached to the switch circuit. I'm looking for the best way to include both the relay-state, plus I'm already using a conditional to show either the button for the switch or the button for the smart bulbs depending on the relay-state

vapid oak
#

Template number helper to translate between fan states and 0-3 and then use a mushroom number card to make it pretty in the dashboard

icy kite
#

If the switch is in 'switched' mode, then the switch button directly operates the relay. If the switch is in 'always-on' mode, then the button sends an event to HA which is translated to operate the bulbs.

vapid oak
#

I know the kind, yeah

icy kite
#

I love the mushroom cards, but I havent been able to get them set up

#

still struggling to apply the background, but that's a problem for another day

vapid oak
#

Ah well. Good luck!