Lovelace: Button card

since you copied my code above, here’s the template you are missing:

button_default_title:
  tap_action:
    action: none
  styles:
    card:
      - background-color: var(--background-color-off)
      - color: var(--text-color-off)
      - font-size: 20px
      - font-weight: 400
      - padding: 12px
    name:
      - justify-self: left

note this also relies on some theme variables I have set in my theme definitions.

Always best to not simply copy other peoples yaml, but try to understand what you are doing.

As for the definition of button-card-templates, check the documentation on that aspect: GitHub - custom-cards/button-card: ❇️ Lovelace button-card for home assistant

you need to set that for each dashboard you use (with custom:button-cards)

button_card_templates: !include_dir_merge_named ../button_card_templates

to point to a map inside you /config folder. I use relative notation, but you can also use absolute notation

button_card_templates: !include_dir_merge_named /config/dashboard/button_card_templates

ofc, adjust to your folder naming convention

besides all of the above, there are some navigations set in the hold action to paths I use in my config. So you need to adjust those too (or delete that if you don’t want to navigate away)

Don’t get me wrong, but you explain pretty difficult. That’s why I still haven’t figured out how to configure afvalwijzer like I asked you how I wanted it…

?? wat are you referring to here?

this has nothing to do with afvalwijzer perse.
this is nothing more than a button card styling. Wrapped in a template, so I can use these throughout my dashboards

here, it only styles the top card (Ophaaldata):

if you dont yet use/understand button-card-templates, you can even take it out and simply set that styling on the button in the stack itself

instead of using:

card:
  type: vertical-stack
  cards:
    - type: custom:button-card
      name: Ophaaldata
      template: button_default_title

you then use:

card:
  type: vertical-stack
  cards:
    - type: custom:button-card
      name: Ophaaldata
      tap_action:
        action: none
      styles:
        card:
          - background-color: var(--background-color-off)
          - color: var(--text-color-off)
          - font-size: 20px
          - font-weight: 400
          - padding: 12px
        name:
          - justify-self: left

2 Likes

EDIT : So I was so focused on doing this in YML than I didnt think of the obvious, modifying the picture as a png with low alpha Working great, thanks for the addons !

Hello ! is their a way to have a semi-transparent background-image in a template as a container ?

I use :

button_card_templates:
  container:
    color_type: label-card
    styles:
      card:
        - padding: 0
        - background-color: transparent
      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
        - background-image: >-
            url('https://cdn.couteaux-du-chef.fr/54851/poele-paysanne-bord-haut-de-buyer-fer-32cm.jpg')
        - opacity: 0.5
      custom_fields:
        buttons:
          - margin: 0
          - padding: 0.3em

But It also make the buttons transparents, if anyone have an idea, thanks !

I will try this afternoon… thanks!

@D34DC3N73R I might be a bit late to the party here, sorry but realised I have a solution for you.

So you aren’t able to use the js templates under the triggers_update property unfortunately, however there is a workaround. If you define a custom field as a card within a button-card template then ALL properties of that card definition can use templates! Not only that but it will still automatically update when it’s entity updates regardless of the state of the parent. That said, I have two other entities that need to update the card in mine so…

Here’s an example from the light_motion template in Creative Button Card Templates:

# ...template definition 
  custom_fields:
    motion:
      card:
        type: custom:button-card
        template: transparent
        entity: "[[[ return variables.motion_entity ]]]"
        show_name: false
        show_last_changed: true
        triggers_update:
          - "[[[ return variables.motion_entity ]]]"
          - "[[[ return variables.timer_entity ]]]"
          - "[[[ return variables.enabled_entity ]]]"
        state:
          # ...

You can see in that example that I’m even populating the entity with a js template!

Also all the code for my templates is on Github so feel free to grab anything from there that’ll help. OR better still, load up my templates so you don’t have to redo it yourself. However I completely get it if you already have a whole eco-system going. Just grab the bits you need.

Hope this helps. Let me know if you have any questions about the code.

Hi All,
I’m trying to define a Button card template, but have a problem. Here is the code of template:

  tado_button_card_template:
    variables:
      var_name: var_value1
      var_entity: var_value2
    name: '[[[ return variables.var_name ]]]'
    entity: '[[[ return variables.var_entity ]]]'

And here is the card:

type: custom:button-card
template: tado_button_card_template
variables:
  var_name: Bedroom
  var_entity: climate.bedroom

But when I try to click on the card instead of entity opened (climate control in this case), I have following error:

Thanks for the suggestion, I’ll check it out.

You’re missing quotes around var_value1 and var_value2.

Unfortunately the problem is not into the quotes. I’m using Raw editor and it automatically removes the quotes and second - name variable works perfectly.

So, if I understand correctly, var_name doesn’t work and var_entity does?

As far as I know you can’t use the entity as a variable (or it’s not meant to at least). Variables are well, variables. So things that you can alter regardless of the entity. Things like name, icon, label etc. Which is why your card shows that error: it can’t return an entity. I believe the templates support the same variable as the javascript template option: GitHub - custom-cards/button-card: ❇️ Lovelace button-card for home assistant.

You need to declare the entity in the card itself, not as a variable. So like this:

type: custom:button-card
entity: climate.bedroom
template: tado_button_card_template
variables:
  var_name: Bedroom

Perhaps I’m wrong and you can use entity as a variable, but I always declare the entity in the card since it’s how the docs explain it as well.

Hi all,

I would like to use a button card that displays the state of my window contact sensor and if and only if the window is open, displays the time since it has been opened below the state.

I first tried the show_last_state option but first of all, it displays the information always and not depending on the state and secondly I want to have the format of the output slightly different.

So I tried to realize this using the label of the button card which was successful except the fact that the value was not updated. Is there any way to have the label being refreshed, say every minute?

Here is my button card configuration (I’m using a template as I want to apply this to multiple button cards):

type: custom:button-card
name: Küche
entity: binary_sensor.kitchen_window
icon: mdi:window-closed-variant
template: my_template

button_card_templates:
  my_template:
    color_type: card
    show_name: true
    show_icon: true
    show_state: true
    show_label: true
    state:
      - id: state_on
        value: 'on'
        color: var(--accent-color)
        label: >
          [[[
            let diff = Date.now() - new Date(entity.last_changed);
            if (diff < 60000)
            {
              return "Weniger als eine Minute";
            }
            else if (diff < 3600000)
            {
              let since = Math.floor(diff / 60000);
              return "Seit " + since + " " + ((since == 1) ? "Minute" : "Minuten");
            }
            else
            {
              let since = Math.floor(diff / 3600000);
              return "Seit " + since + " " + ((since == 1) ? "Stunde" : "Stunden");
            }
          ]]]
      - id: state_off
        value: 'off'
        color: var(--ha-card-background)

Hi,
I’m trying to build a customer button-card template, where I have nested custom:button-card elements and want to use a second template to customize the nested buttons. Is it possible?

you should probably should use this, though I havent checked your full config.

[[[ return variables.var_entity.entity_id ]]]

you can do things like:

button_motion:
  variables:
    id: >
      [[[ return 'switch.' + entity.entity_id.split('.')[1]; ]]]
  template:
    - button_body
    - styles_ripple
  show_last_changed: true
  tap_action:
    action: call-service
    service: switch.toggle
    service_data:
      entity_id: >
        [[[ return variables.id; ]]]
  state_display: >
    [[[ return states[variables.id].state === 'off' ? 'Uit'
        : entity.state === 'off' ? 'Geen' : 'Beweging'; ]]]
  state:
    - value: 'on'
      icon: >
        [[[ return variables.on_icon; ]]]
      styles:
        card:
          - color: red
          - border-top: 0.5rem solid red
        name:
          - color: black
        icon:
          - color: red

and use a config like:

          - type: custom:button-card
            template: button_motion
            name: Laundry
            entity: binary_sensor.laundry_sensor_motion
            triggers_update: switch.laundry_sensor_motion
            variables:
              clear_icon: mdi:washing-machine
              on_icon: mdi:washing-machine-alert
              off_icon: mdi:washing-machine-off

note still the triggers_update is still required and it is hard-coded. Button-card uses templates and can not use variables inside those, as it would mean it had to update on all state changes. It did so before, and was taken out because it could bring down the instance… so triggers_update was introduced

Thanks. It looks like - “main” entity - cannot be controlled by variable. This is not a big issue - as it’s easy to add entity with name - instead of variable - as the variable can be used in nested custom:button-card. To give more idea what I’m trying to achieve - I have TADO TVR’s on all my regurgitators - now I want to build a template for card - that can be easily reproduced for all of them - keeping most important parameters visible. So into the template - I’m defining all elements and then into the dashboard / card configuration with just few variables (and entity) - I’m specifying “custom” elements. I want also to add few buttons where I can preform few operations on the TVR - like temp +/- and On/Off. Here is the very draft version of the card (please ignore colors, as I just put few of them to see that they are working, but final design of the card will be on the next stage):

image

1 Like

cool, nice and complex :wink:

and yes, the main card entity can be used for that, and should be chosen wisely. I have some buttons using another entity for exactly those templating purposes.

Since the button-card is endlessly customizable, there always is an option somewhere :wink:

Thanks for the feedback. Definitely:

  • Cool - agree :slight_smile:
  • nice - far away - I need to play a bit with sizes and etc. Colors are terrible
  • Complex - if it’s not complex - it’s not so interesting :slight_smile:
    The main goals that I have for the moment, before stating the polishing design is to see if I can use template also for the buttons below - as at the moment have 4 buttons and all parameters are in all of them and its very annoying to change 4 times all of the components…

Other problem is that Tado is a bit complex as integration - from one side - there is a climate control - where half of attributes are available and second - a lot of sensors (and binary_sernsors) - where the rest of attributes are publish - so I need a lot of variables to pass them to the card. But in general - I’m really happy with the custom:button-card and plan to use it a lot into the new redesign of the dashbaord.

your card just might be able to help me out… though I am a button-card user for a long time, and have it make up half of my Frontend, I dont have many cards with embedded cards/entities.

Which probably might be what I need currently: I have a set of bigger cards representing my Rooms, and they are in a stack or swiper, depending on device(width). Clicking any of these takes me to the view of that room in the path.

Those cards have an background image entity_picture of the zone, and can be greyed if a main entity is off. Also they can have a top border turn red if motion is detected:

template is like:

plattegrond:
  template:
    - styles_menu_tooltip
  aspect_ratio: 1/1
  tooltip: >
    [[[ return variables.tooltip; ]]]
  tap_action:
    action: navigate
    navigation_path: >
      [[[ return variables.path; ]]]
  hold_action:
    action: toggle #call-service
#             service: light.toggle
#             service_data:
#               entity_id: entity

  entity_picture: >
    [[[ return "/local/images/areas/" + variables.picture; ]]]
  size: 140%
  show_name: false
  show_icon: false
  show_entity_picture: true
  styles:
    card:
      - padding: 0px
#       - background-image: >
#           [[[ return  `url("/local/images/areas/${variables.picture}")`; ]]]
#       - background-size: cover
#       - background-repeat: no-repeat

#       - border-bottom: 4rem solid transparent
    entity_picture:
      - filter: >
          [[[ if (entity.state == 'off' || entity.state == 'unavailable') return 'grayscale(100%)';
              return 'grayscale(0%)'; ]]]

What Id love to add is a significant area at the bottom, just like the real Area card, (or the picture-entity card) and have control of what I show there, mostly a single temp entity state, and a humidity entity state.
I am not using the Area card, because that is way to dangerous with clicking it, and no way to control that.

this is a single instance of a room, using the above template:

        - type: custom:button-card
          entity: light.laundry_ceiling
          template: plattegrond
          variables:
            path: /ui-sub-views/bijkeuken
            picture: bijkeuken_klein.jpg
            tooltip: Bijkeuken
          styles:
            card:
              - border-top: >
                  [[[ return (states['binary_sensor.laundry_sensor_motion'].state == 'on')
                      ? '0.5rem solid red' : 'none'; ]]]

I’d envision adding some variables there for the temp and humidity entities, which then need to be placed in side the card through the template in the blurred section at the bottom of the card.

hope this makes sense…

Nested custom:button-card is very easy to be create:

  • you are defining place into the grid
  • into custom_filed - you are defining entire card - with style and other parameters.

Good news is that you can use variables for the “main” card - to pass parameters into the nested (even entity - can be passed).