Lovelace: Button card

I also wanted this so I just added ${state.attributes.unit_of_measurement} in the <div> after ${state.state}. Would be nice to have it as a config value in the main card.

Another thought. Would it be possible to have different icons based on state?

Is there a way to have the button set variables for a script? I can only get it to toggle a script but how to set it up to include variables in the homeassistant.toggle?

Also how do I create custom icons or entity-pictures for my buttons? I saw a screenshot earlier where someone had the Netflix logo etc. inside their buttons?

BR, Rasmus

1 Like

Were you able to solve it ?

Can you please share how did you manage to solve the error ?

Thanks

Hi all, is there any chance to group buttons in a single card with title?

2 Likes

yeah nested in side a horizontal-stack or vertical-stack

Sadly, you canā€™t put a title into horizontal or vertical stack, and there arenā€™t a background on this stacks.
Do you understand what I need? :pensive:

Thanks anyway

@kuuji
Trying to do this as well, for the moment I am fine with just a button to open and another button to close. How can I achieve that?

action: open_cover ??
action: close_cover ??

found the solution

  - type: "custom:button-card"
    action: service
    service:
      domain: cover
      action: close_cover
      data:
        entity_id: cover.xxxx

Well, this was just me not reading through the whole documentation.
For the sake of others that did the same, in the ui-lovelace import section, the type should be module, not JS :

resources:
  - url: /local/custom_ui/button-card.js?v=1
    type: module

im getting all the time error:

https://my.ip.address/local/button-card.js:169:11 TypeError: state is undefined

any help? @kuuji

same error here started with upgrade to 79.0 hassbian:

button-card.js?v=0.0.2:109:50 Uncaught TypeError: Cannot read property ā€˜stateā€™ of undefined

have a look at this:

1 Like

Hi @kuuji
Thanks for the great work, this is super useful!

Just wondering, is it possible to add a feature to remove the border for the button/card?

Hey there! Thank you a lot, this is nice. Could you say, how can I make buttons smaller?

Here is what I have:

  - type: custom:button-card
    entity: switch.wall_switch_left_158d000245c5ca
    icon: mdi:lightbulb-on-outline
    name: 'ŠšŠ¾Ń€ŠøŠ“Š¾Ń€'
    color: '#00abfb'
    size: 20%

Is it possible to have a button where the background color is red if the sensor im using have the state ā€œOccupiedā€ and green background if the state is ā€œVacantā€.
Do i have to write some kind of template for that?

youā€™ll have to modify the .js for that

check the class: ā€œbuildCssColorAttributeā€

Iā€™d also like to color a button which represents a thermostat, so the state is ā€œheatā€, and not ā€œonā€.

2 Likes

This is a great custom card. I love it and used it in a lot of my lovelace views. Thank you!

There is one great enhancement which would make the button card more powerful. Could you implement a long press option like @thomasloven did for picture elements? (My Lovelace Plugins) This would be great!

1 Like

@kuuji would it be possible to implement templating support for the icon. If not could you add state icons for on and off?