Lovelace: Button card

I’m not aware of any possibility to overlay 2 cards, so I suggest the following:


variables:
  person: person.michal
  bg: url('/local/michal/Biuro.png')
  status: states['sensor.michal_sleep_status'].state
type: custom:button-card
triggers_update: all
show_name: false
show_icon: false
show_state: false
show_label: false
styles:
  card:
    - border-radius: 0
    - box-shadow: none
    - padding: 0
    - height: 200px
    - background: blue
  grid:
    - grid-template-areas: '"item1" "item2"'
    - grid-template-columns: 1fr
    - grid-template-rows: min-content  min-content
    - row-gap: 0px
custom_fields:
  item1:
    card:
      type: custom:button-card
      styles:
        card:
          - height: 100px
          - border-radius: 0
          - box-shadow: none
          - padding: 0
          - background: black
  item2:
    card:
      type: custom:button-card
      entity: '[[[ return variables.person ]]]'
      show_entity_picture: true
      show_name: false
      show_icon: false
      styles:
        card:
          - padding: 0
          - box-shadow: none
          - border-radius: 0
          - background-image: '[[[ return variables.bg ]]]'
          - background-size: cover
          - background-position: center
          - overflow: visible
        img_cell:
          - width: 110px
          - height: 110px
          - border-radius: 50%
          - border: 6px solid yellow
          - border-color: |
              [[[
                return variables.status === 'Asleep'
                ? 'var(--state-icon-color)'
                : 'var(--state-icon-active-color)'
              ]]]
          - place-self: center
          - position: relative
          - top: '-50%'
        grid:
          - grid-template-areas: '"i"'
        entity_picture:
          - width: 110px

Bild

1 Like

Thank you very much!

Hi all!

I have been struggling with this situation for a few days and come here looking for any help:

I have designed this bar for many of my views:

And I want to for the yellow coloured button to open a popup card passing the .yaml to open as a variable.

This is the button:

      - type: custom:button-card
        template: card_title_with_return_and_config_button
        variables:
          ulm_card_navigate_path: "#menu_master"
          ulm_card_title: 'Alarma Técnica'
          ulm_card_config_title: 'Configuración - Alarma Técnica'
          ulm_card_config_yaml: '022_config_technical_alarm.yaml' 

and an extract of the button template which should open the yaml in the variable ulm_card_config_yaml but is not working:

card_title_with_return_and_config_button: 
  custom_fields:              
    config: 
      card: 
        type: 'custom:button-card'
        tap_action:  
          action: fire-dom-event
          browser_mod:
            command: popup
            title: "[[[ return variables.ulm_card_config_title ]]]"
            card: "[[[ return '!include /config/lovelace/00_minimalist/01_cards/01_popup/' +  variables.ulm_card_config_yaml ]]]" 

The “card” configuration inside browser_mod options is which is not working.
Any hint?
Thank you!

This is driving me mad…

For a temperature sensor, I would like to have the temperature (so the state) big in the middle, the icon small in the right corner and the name centered below the temperature. But it simply does not work, the grid partly ignores how the parts should be arranged and just puts the state back at the bottom, the name does not take the two columns as expected, etc.

grafik

type: custom:button-card
aspect_ratio: 1/1
entity: sensor.bsb_lan_trinkwassertemperatur
name: Wasser-Temp.
show_state: true
styles:
  grid:
    - grid-template-areas: '"s i" "s s" "n n"'
    - grid-template-columns: 80% 1fr
    - grid-template-rows: 1fr 1fr min-content
  name:
    - font-size: 12px
    - align-self: end
    - justify-self: center
    - padding-bottom: 0px
  icon:
    - width: 20%
    - margin-top: '-20%'

If I just exchange the i in the grid also with an s, it does suddenly move the state value up and positions the name as expected, so there is any internal logic that overwrites what I have defined in the grid:

grafik

type: custom:button-card
aspect_ratio: 1/1
entity: sensor.bsb_lan_trinkwassertemperatur
name: Wasser-Temp.
show_state: true
styles:
  grid:
    - grid-template-areas: '"s s" "s s" "n n"'
    - grid-template-columns: 80% 1fr
    - grid-template-rows: 1fr 1fr min-content
  name:
    - font-size: 12px
    - align-self: end
    - justify-self: center
    - padding-bottom: 0px
  icon:
    - width: 20%
    - margin-top: '-20%'

How can I place the icon as I want, or is there for whatever reason only the workaround to use a custom icon in a custom field?

You may confuse the grid with using an “l” (for label) or whatever name you like so it reserves the space you don’t want to be occupied for an entity that doesn’t exist:

...
        styles:
          grid:
            - grid-template-areas: '"l i" "s s" "n n"'
            - grid-template-columns: 80% 1fr
            - grid-template-rows: 10% 1fr min-content
...

Thanks, that generally works, with the downside that it takes exclusively space (now 20%) for a whole row to display the icon on the right side, instead of having that in the same row than the state (just aligned to the top right).
I find that not really logical/buggy, but was able to achieve my goal (still to be adjusted in details, but that was the main part to achieve).
grafik

Hi

I’m using decluttering cards now quite some time
For example

- type: conditional
  conditions:
    - entity: binary_sensor.lampen
      state: "on"
  card:
    type: custom:decluttering-card
    template: notification_template
    variables:
      - name: Er zijn lampen aan!

Using template :

decluttering_templates:
  notification_template:     # This is the name of a template
    card:
      type: custom:button-card
      name: '[[name]]'
      size: 50%
      show_state: false
      show_label: false
      layout: icon_name
      tap_action: 
        action: none
      hold_action: 
        action: none
      styles:
        card:
          - --ha-card-background: rgba(0,0,0,0.0)
          - box-shadow: none
          - height: 10px
        name:
          - font-size: 18px
          - font-family: Helvetica
          - justify-self: start
          - font-weight: normal
        grid: 
          - grid-template-areas: '"i n"'
          - grid-template-columns: 2% 1fr
          - grid-template-rows: 1fr

However, now i’m trying to do the same but instead of putting in the name “Er zijn lampen aan” , i want to count the lamps that are on.

I have a sensor for that, thats has state equal to number lights that are on.

However i dont succeed in putting that into "Er zijn (states('sensor.current_lights_on) lampen aan

Someone at decluttering card pointed me that i need to use javascript templates (o ow)
It seems i’m trying to use Jinja2 templates with button card. That doesn’t work. Probably cause i used markdown before. He said i had to try this

    name:  |
      [[[
        return "Er zijn " + states['sensor.current_lights_on'].state + " lampen aan";
      ]]]

However, im getting an error with it:)
Anyone can help me out here?
I would be grateful

Just play around with the tamplate-areas. This would be my favourite layout (note: aspect_ratio destroys the button on my HAss completely –on any button-card– so I had to disable it):

type: custom:button-card
#aspect_ratio: 1/1
entity: sensor.hmip_dg_t2_temp
name: Temperatur
show_state: true
show_icon: true
styles:
  grid:
    - grid-template-areas: '"s s i" "n n n"'
    - grid-template-columns: 40% 40% 1fr
#    - grid-template-rows: 1fr min-content
  state:
    - justify-self: right
  name:
    - font-size: 12px
    - align-self: end
    - justify-self: center
    - padding-bottom: 0px
  icon:
   - width: 50%
   - margin-top: '-20%'
  card:
    - width: 100px

resulting in (I use dark layout):
button-card003

Yeah thanks, the more I play around with it the more buggy I find this.
If state and icon are in the same row, the state can be positioned with justify-self and align-self, but the icon not at all - unless i insert a negative margin-top, that seems to increase the box in which the icon can be positioned and then align-self does work.

type: custom:button-card
entity: sensor.bsb_lan_trinkwassertemperatur
name: Temperatur
show_state: true
show_icon: true
styles:
  grid:
    - grid-template-areas: '"s s i" "n n n"'
    - grid-template-columns: 40% 40% 1fr
  state:
    - justify-self: right
  name:
    - font-size: 12px
    - align-self: center
    - justify-self: center
    - padding-bottom: 0px
  icon:
    - width: 100%
    - margin-top: '-100%'
    - align-self: start
  card:
    - height: 100px

grafik
Now align-self: end puts it on the height of the state, start puts it to the top. But the top is only determined by the negative margin (which I need to position with try & error) - which the state does not need to be positioned in its full part of the grid. Without the margin, align-self does not work.

I find this example based on yours also a bit “dirty” with the state being aligned to the right in its 80% box. That is why I tried to have the state in its own row, but every way seems to have some drawbacks.

I like the idea of the grid, but either there are CSS specialties that I do now understand so far, or it does not always behave like it should based on the definition.
Is that a bug or why do state and icon behave differently in the grid positioning?

Has anyone found any creative ways to use the button card to adjust times in an input_datetime?

I simply use more-info action.

I did something like this:

tap_action:
  action: fire-dom-event
  browser_mod:
    command: call-service
    service: browser_mod.popup
    service_data:
      title: Settings
      deviceID:
        - this
      card:
        entities:
          - entity: input_datetime.housewife_starts
          - entity: input_number.cleaning_time_minutes
          - entity: input_select.clean_day
        state_color: true
        type: entities

looks like this:
image

Anyone can help me with the template pls?

The name’s code for custom:button-card is correct. Seems to be more of a problem with the other custom card.

Are you referring to me?
What do you mean with the name’s code for custom:button-card?

You mean the part in the decluttering template?
Or this part i nthe custom:decluttering-card

    name:  |
      [[[
        return "Er zijn " + states['sensor.current_lights_on'].state + " lampen aan";
      ]]]

Yes, I answered you. This


    name:  |
      [[[
        return "Er zijn " + states['sensor.current_lights_on'].state + " lampen aan";
      ]]]

is a working code for custom:button-card. So I’m assuming that the problem is with decluttering card.

Mmm strange, cause at the topic from decluttering, they say its a problem of the custom button card

If i add it, i get this

As said, I’m not familiar with decluttering card, therefore I don’t see the context with


    type: custom:decluttering-card
    …
      - name: Er zijn lampen aan!  ## this


      type: custom:button-card
      name: '[[name]]'   ## and this*

  • normally here stands the mentioned code

name:  |
      [[[
        return "Er zijn " + states['sensor.current_lights_on'].state + " lampen aan";
      ]]]

Hey Kongo! I tried for hours to- get this working but I can’t, I’m getting errors no matter which way I try to set up the scripts. Can’t put them in configuration.yaml, but not in a separate yaml either. The card I got looks way out of whack too. Could you perhaps share your full config to compare?

Or do you have an updated version? I’ve been trying for months to get my humi/puri setup in HA and im going crazy! Thanks for your work. :slight_smile:

What exactly is going wrong? How does it look?