Lovelace: Button card

It will behave in the same way I’m afraid. It looks like the last_changed attribute is not updated when you start a timer that is already running. That’s more a HA core component bug… I’ll have a look if I can PR something there.

EDIT: In the meantime, you could timer.cancel and then timer.start again. Use a script to do that and instead of calling timer.start call that script from your automation or your frontend.

Hihi, I actually wanted to report a bug, but it seems it is an iOS 13 problem :stuck_out_tongue:

Everytime I press a button on the iphone it will do it again (so it cancels the previous action). When I turn a light on it will immediately turn off again. Only when doing it in fast succession it will work. Anyways nothing to do about it for now. Safari does the same thing. Though I thought lets try it on my desktop and older ios devices and it works fine there :stuck_out_tongue:

That would be more than brilliant if you managed that.
If you remember, please let me know if you do PR so that I can follow it.

LOL! No iOS13 bugs in here!

That’s why it’s still called a beta :stuck_out_tongue:

Lol I know, that is why I said, “wanted to”. But no worries, I can live with a workaround so np, the darkmode is just too awesome (and all other stuff seems to work fine).

Btw, just a question. I’m a bit confused about the operator stuff, is it used for changing an icon depending on state value? Or is it just for changing color? And if not, how can I change the icon, say I want a power icon when it is on and another icon when it is off.

Sure you can, the state objects can contain many things: button-card/README.md at master · custom-cards/button-card · GitHub

state:
  - value: 'on'
    icon: mdi:icon_on
  - value: 'off'
    icon: mdi:icon_off

That’s a complete example for a battery button:

- type: "custom:button-card"
  icon: mdi:battery
  # name: Battery
  color_type: card
  entity: sensor.battery
  show_name: false
  show_state: true
  tap_action:
    action: more-info
  state:
  - value: 10
    operator: '<='
    color: "#FF0000" #red
    icon: "mdi:battery-10"
    styles:
      grid:
      - animation: blink 2s linear infinite

  - value: 20
    operator: '<='
    color: "#ff6600" #red orange
    icon: "mdi:battery-20"

  - value: 30
    operator: '<='
    color: "#ff9933" #dark orange
    icon: "mdi:battery-30"

  - value: 40
    operator: '<='
    color: "#ffcc00" #light orange
    icon: "mdi:battery-40"

  - value: 50
    operator: '<='
    color: "#FFFF00" #yellow
    icon: "mdi:battery-50"

  - value: 60
    operator: '<='
    color: "#FFFF00" #yellow
    icon: "mdi:battery-60"

  - value: 70
    operator: '<='
    color: "#FFFF00" #yellow
    icon: "mdi:battery-70"

  - value: 80
    operator: '<='
    color: "#CCFF33" #yellow green
    icon: "mdi:battery-80"

  - value: 90
    operator: '<='
    color: "#66FF33" #light green
    icon: "mdi:battery-90"

  - value: 100
    operator: '<='
    color: "#279b37" #dark green
    icon: "mdi:battery"
2 Likes

This is fantastic! Battery monitoring was on my to-do list.

Oh was it that simple :stuck_out_tongue: didn’t know you could assign an icon like that. That is just great.

I understand the operator function a lot better now, thanks a lot @RomRider

That’s correct, if you were going to use my config “as-is” you’d need to use YAML mode. However, you could still take bits and pieces of it to use with the UI editor.

this would be a great opportunity to ask you to have a look at my earlier feature request for icon_template, (might have been snowed under here: Lovelace: Button card)

though in this case the battery icon might be better served with device_class battery which automatically changes all these icons… the icon template could color like:

    icon_color: >
      if (state > 75) return 'green';
      if (state > 50) return 'yellow';
      if (state > 25) return 'orange';
      if (state > 10) return 'brown';
      return 'red';

I will not duplicate features @Mariusthvdb. The state object can cover all those request and I prefer declarative YAML over javascript.

Thanks, though I am truly amazed tbh…
Considering you allow entity_picture_template (which is magic, and working wonders) among the other templates, this would be the logical thing to add wouldn’t it? You’ve introduced card templates to declutter the config, you’ve even created a dedicated unclutter card. And very glad you did!

Adding this template option would seriously enhance the options of the Button card while in the same time, seriously make it easier (and much much shorter) to configure, maintain and debug. Talk about uncluttering, this would be it :wink:
Just look at all the code doubling in your example which 1 simple template could reduce significantly. Less code, less risk for errors.

added to that, sometimes it can be useful to have the same functionality in several ways:

        state:
          - operator: '>'
            value: 0
            styles:
              card:
                - color: '#555B65'
                - background-color: '#f0c209'
              icon:
                - color: '#555B65'

and

        state:
          - operator: template
            value: return entity.state > 0 
            styles:
              card:
                - color: '#555B65'
                - background-color: '#f0c209'
              icon:
                - color: '#555B65'

replace the value 0 in the last example with a state of another entity, and it makes sense to use the template variant.
Anyways, really hope you might reconsider at sometime.

HI,

have you given the <br> in name issue some thought yet? Would be really cool to have multiline names possible. I obviously tried it before asking but no such luck yet using

        name_template: >
          'Master' + "<br>" + 'bedroom'

also, will you be developing this button-cards-in-card Lovelace: Button card

Would be the final clincher…(#fingerscrossed)

Could you please share your code on the section/divider for covers and living room lights.
It looks awesome how you have some customized buttons on them!

I am sorry if this is shown somewhere in this post already… this post is just so huge :rofl:

Is there different configuration for toggling lights and switches?
I’ve configured exactly the same switch and light, the switch toggle works perfect, but when I use it with light - it always opening “more-info” popup like this:
image

      - action: toggle
        color: auto
        color_off: '#333333'
        color_type: card
        default_color: '#997701'
        entity: light.8331804184f3eb9c0e4a
        icon: 'mdi:lightbulb-outline'
        name: Salon
        style:
          - font-size: 12px
          - font-weight: bold
          - text-transform: none
        type: 'custom:button-card'

      - action: toggle
        color: auto
        color_off: '#333333'
        color_type: card
        default_color: '#997701'
        entity: switch.kitchen_lights
        icon: 'mdi:lightbulb-outline'
        name: Kitchen
        style:
          - font-size: 12px
          - font-weight: bold
          - text-transform: none
        type: 'custom:button-card'

according to the docs, the proper use for tap is:

tap_action:
  action: toggle

and if you do not define it, it is by default toggle.

Thanks, been there already, still the same (it does the toggle but always opening the more-info popup):
image

      - tap_action: 
          action: toggle
        color: auto
        color_off: '#333333'
        color_type: card
        default_color: '#997701'
        entity: light.8331804184f3eb9c0e4a
        icon: 'mdi:lightbulb-outline'
        name: Salon
        style:
          - font-size: 12px
          - font-weight: bold
          - text-transform: none
        type: 'custom:button-card'

You’re probably not using the latest version of the card and if you do, don’t forget to clear your cache.
You configuration is valid for the version 0.4, not valid for any version after that (default_color, color_off, … that’s deprecated for a long time already)

I don’t think I’ve shared that, here’s the code:

### That's for the covers
          - type: custom:vertical-stack-in-card
            cards:
              - type: horizontal-stack
                cards:
                - type: custom:button-card
                  template: header_with_other_stuff
                  name: Covers
                - type: custom:button-card
                  template: header_icon_middle
                  icon: mdi:arrow-up-thick
                  tap_action:
                    action: call-service
                    service: cover.open_cover
                    service_data:
                      entity_id: cover.all_covers
                - type: custom:button-card
                  template: header_icon_middle
                  icon: mdi:stop
                  tap_action:
                    action: call-service
                    service: cover.stop_cover
                    service_data:
                      entity_id: cover.all_covers
                - type: custom:button-card
                  template: header_icon_end
                  icon: mdi:arrow-down-thick
                  tap_action:
                    action: call-service
                    service: cover.close_cover
                    service_data:
                      entity_id: cover.all_covers

### That's for the lights:
          - type: custom:vertical-stack-in-card
            cards:
              - type: horizontal-stack
                cards:
                  - type: custom:button-card
                    template: header_with_other_stuff
                    name: Living Room Lights
                  - type: custom:button-card
                    template: header_icon_end
                    icon: mdi:power
                    tap_action:
                      action: call-service
                      service: switch.turn_off
                      service_data:
                        entity_id: switch.all_living_room

That’s for the templates used:

header:
  styles:
    card:
      - padding: 5px 15px
      - background-color: var(--paper-item-icon-active-color)
    name:
      - text-transform: uppercase
      - color: var(--primary-background-color)
      - justify-self: start
      - font-weight: bold
    label:
      - text-transform: uppercase
      - color: var(--primary-background-color)
      - justify-self: start
      - font-weight: bold

header_with_other_stuff:
  template: header
  styles:
    card:
      - border-top-right-radius: unset
      - border-bottom-right-radius: unset

header_icon:
  size: 50%
  styles:
    card:
      - height: 100%
      - width: 50px
      - background-color: var(--paper-item-icon-active-color)
    icon:
      - color: var(--primary-background-color)

header_icon_middle:
  template: header_icon
  size: 50%
  styles:
    card:
      - border-radius: unset

header_icon_end:
  template: header_icon
  styles:
    card:
      - border-top-left-radius: unset
      - border-bottom-left-radius: unset
1 Like

I think I might know…
Are you enclosing the button in an entities card? Like so:

type: entities
entities:
  - type: custom:button-card
    ...

If that is the case… I don’t think there is a work around. It will always trigger more-info.
You should try custom:vertical-stack-in-card, if you are trying to group a button with say… for example a lovelace-slider-entity-row.

It would be funny if this is the reason, because I just tried doing this lol.