Lovelace: Button card

Thanks, I didn’t realize there was 4 with the layout: icon_label. I thought there was 3 rows where the icon and label share the same row.

I have that set. I’m using the following config to allow me to use carriage returns (\r\n) inside the label field.

      label:
        - text-transform: capitalize
        - padding: 10px 20px
        - font-size: 12px
        - justify-self: start
        - align-self: start
        - color: white
        - text-align: start;
        - white-space: pre

the white-space: pre allows me to use carriage returns in css. See below if (playing) return Title: ${title}\r\nArtist: ${artist}.

                    - <<: *custom_button_remote_1column_active_glow_name_stateless
                      name: Media
                      icon: mdi:music-note
                      label_template: >
                        var playing = states['media_player.living_room_dot'].state === 'playing';
                        if (playing) {
                          var title = states['media_player.living_room_dot'].attributes.media_title;
                          var artist = states['media_player.living_room_dot'].attributes.media_artist;
                          return `Title: ${title}\r\nArtist: ${artist}`;
                        }
                        return 'No Media';

This shows up as a text block that is justified and aligned at the start.

However the multi-lines are centered based on the inheritance from the card in this line of the JS file, and I cannot override it.

  ha-card.button-card-main {
    padding: 4% 0px;
    text-transform: none;
    font-weight: 400;
    font-size: 1.2rem;
    align-items: center;
    text-align: center;
    letter-spacing: normal;
    width: 100%;
  }

Carriage return in HTML is <br /> not \n\r :wink:

Picture please :slight_smile:

I’m trying to but everything up against the red line that I drew.

3 Likes

Found it, ths!
Here is for reference if someown else has trouble finding it in github

        label_template: >
          return 'Sensor name: ' + states['sensor.time'].state;
2 Likes

You can override the icon by using the icon field.

color: auto

great !
thanks
one more question: can i change the icon :slight_smile:
when ON --> Icon 1
when OFF --> Icon 2
if unavaialable -> Icon 3

Yep, all these questions are covered in the docs btw. https://github.com/custom-cards/button-card

  state:
    - value: 'off'
      icon: mdi:power-off
1 Like

great
thanks

how can i add this card to button card?

entities:

  • entity: cover.estore_garagem
    icon: ‘mdi:blinds’
    name: Garagem
  • entity: cover.estore_garagem
    full_row: true
    type: ‘custom:slider-entity-row’
    title: null
    type: entities
    image

I don’t believe you can currently. This card only supports 1 entity and it doesn’t support any cards or entity rows.

Thanks all for helping with the support :pray: I’m away from keyboard for 2 days so expect some latency in my answers :blush:

A well-deserved break for you, @RomRider! Enjoy it.

1 Like

hello
i had read the documentation but cannot find how to change backfground of the button
can help please?
type: vertical-stack
cards:
- type: ‘custom:button-card’
styles:
card:
- height: 40px
color_type: label-card
color: ‘rgb(44, 109, 214)’
name: ILUMINAÇÃO DA SALA
- type: horizontal-stack
cards:
- type: ‘custom:button-card’
entity: light.luz_sala_de_estar
name: SALA DE ESTAR
icon: ‘mdi:ceiling-light’
tap_action:
action: toggle
dbltap_action:
action: more-info
color_type: card
color: ‘rgb(61, 134, 244)’
- type: ‘custom:button-card’

        entity: light.luz_sala_de_jantar
        color_type: card
        color: 'rgb(61, 134, 244)'
        icon: 'mdi:ceiling-light'
        name: SALA DE JANTAR
        tap_action:
          action: toggle
        dbltap_action:
          action: more-info
      - type: 'custom:button-card'
        entity: light.yeelight_color1_04cf8c9557ff
        name: CANDEEIRO DE PÉ
        color_type: card
        color: auto
        icon: 'mdi:floor-lamp'
        tap_action:
          action: toggle
        dbltap_action:
          action: more-info
  - type: horizontal-stack
    cards:
      - type: 'custom:button-card'
        entity: light.luz_hall
        color_type: card
        color: 'rgb(66, 134, 244)'
        icon: 'mdi:lightbulb'
        name: HALL
        tap_action:
          action: toggle
        dbltap_action:
          action: more-info
      - type: 'custom:button-card'
        entity: light.luz_philips_xiaomi
        color_type: card
        color: auto'
        icon: 'mdi:lamp'
        name: APARADOR
        tap_action:
          action: toggle
        dbltap_action:
          action: more-info
      - type: 'custom:button-card'
        entity: light.yeelight_color2_04cf8c842ee1
        icon: 'mdi:television-box'
        name: AMBILIGHT
        color_type: card
        color: auto
        tap_action:
          action: toggle
        dbltap_action:
          action: more-info
          state: null

the css style to change background color is --paper-card-background-color

        styles:
          card:
            - --paper-card-background-color: rgba(40, 40, 40)

I love this, if you wouldn’t mind could you look at this and tell me if im doing something wrong.
I set up livingroom, kitchen, diningroom. They are all listed but the entities won’t hide when pressing the button. I love this idea! Thanks :slight_smile:

automation.yaml

- id: 
  alias: Diningroom Card -  ON
  trigger:
  - platform: state
    entity_id: input_boolean.diningroom
    from: 'off'
    to: 'on'
  condition: []
  action:
    - service: homeassistant.turn_off
      entity_id: group.input_diningroom_on

groups.yaml

input_diningroom_on:
  name: Input Dining Room ON
  view: no
  entities:
    - input_boolean.kitchen
    - input_boolean.livingroom

lovelace.yaml

  - type: "custom:button-card" 
    show_icon: false
    color_type: card
    name: Diningroom
    entity: input_boolean.diningroom
    state:
      - value: 'on'
      - value: 'off'
    tap_action:
      action: call-service
      service: homeassistant.turn_on
      service_data:
        entity_id: input_boolean.diningroom        
  - type: conditional
    conditions:
      - entity: input_boolean.diningroom
        state: "on"
    card: 
    type: entities
    entities:
      - entity: switch.sonoff_100067d7e9
        name: Sanyo TV
        secondary_info: last-changed
      - type: divider
      - entity: light.tree
        secondary_info: last-changed
        icon: mdi:tree
      - type: custom:slider-entity-row
        entity: light.tree
        full_row: true 
      - entity: light.dining_room_ceiling
        secondary_info: last-changed
        name: Chandelier
        icon: mdi:light-switch
      - type: custom:slider-entity-row
        entity: light.dining_room_ceiling
        full_row: true 
      - entity: input_boolean.fireplace_dr
        secondary_info: last-changed
        name: Fireplace
        icon: mdi:fire
      - entity: sensor.garage_door
        icon: mdi:garage
        secondary_info: last_changed       
    title: Diningroom
    show_header_toggle: true
1 Like

@dmatik and @RomRider thank you for all the responses to my questions and even some that came along on the way (like the anchors)

I wanted to thank all of you for telling me about this and showing an example. It was pretty easy to setup and man it saved me over 6000 lines of code already!! (and not even done yet).

I also adapted the new grid style for the Homekit button I previously made with padding. They look pretty much the same now. I was actually forced using the grid style as a spinning icon would not spin around its own axis when using padding, so all my icons were flying over the screen (which was pretty funny actually).

For the ones wanting the Homekit button I posted earlier, here is the new code.
Add spin: true to the state, under value

  - type: "custom:button-card" 
    name: Plafond
    icon: "mdi:ceiling-light"
    entity: light.woonkamer_plafond
    label_template: >
      var bri = Math.round(states['light.woonkamer_plafond'].attributes.brightness / 2.55);
      return (bri ? bri : '0') + '%';
    color: auto
    size: 30%
    show_state: true
    show_label: true
    tap_action:
      action: toggle
      haptic: light
    hold_action:
      action: more-info
      haptic: success
    styles:
      card:
        - border-radius: 12px
        - width: 105px
        - height: 105px
        - --paper-card-background-color: rgb(255, 251, 239)
      label:
        - color: gray
        - font-size: 11px
        - font-family: Helvetica
        - padding: 0px 10px
        - justify-self: start
      state:
        - font-size: 11px
        - font-family: Helvetica
        - padding: 0px 10px
        - justify-self: start
        - text-transform: capitalize
        - font-weight: bold
        - padding-left: 10px
      grid:
        - grid-template-areas: '"i" "n" "s" "l"'
        - grid-template-columns: 1fr
        - grid-template-rows: 1fr min-content min-content
      img_cell:
        - align-self: center
        - text-align: start
        - margin-left: 10px
      name:
        - justify-self: start
        - padding-left: 10px
        - font-weight: bold
        - font-family: Helvetica 
        - font-size: 13px
    state:
      - value: "on"
        # spin: true (uncomment this line for spinning icon)
        styles:
          name:
            - color: black
          state:
            - color: gray
      - value: "off"
        style:
          - opacity: 0.4
        styles:
          icon:
            - color: gray
          name:
            - color: gray
          state:
            - color: gray
      - value: "unavailable"
        style:
          - opacity: 0.2
          - color: black
          - --paper-item-icon-color: black

Here is how it looks with the updated grid code:

8 Likes

I probably need to stare at this a bit longer but so far everything looks right. What I don’t see is your input_boolean declaration in configuration.yaml. Without that, none of this works. Also, don’t forget to restart home assistant.

EDIT: I noticed that your Group, Automation, and Lovelace code snippets are specific to the Dining Room Card. I assume you also have similar code for the Living Room and Ktichen as well, correct?

Yes, I do have those and the input_booleans also

You should use an input_select, it’s easier for a menu with more than 2 entries, no automation is needed.

Also here your indentation is off

  - type: conditional
    conditions:
      - entity: input_boolean.diningroom
        state: "on"
    card: 
    type: entities   ## <--- indentation 
    entities:
      - entity: switch.sonoff_100067d7e9
        name: Sanyo TV
        secondary_info: last-changed

that looks mightily impressive, thanks for posting.

I am looking for a future replacement for my Tiles card, since that seems to no longer be maintained.

The huge thing about that card is, it sets a config style, and only per entity settings in the entity config below that.

Looking at your code, the full styling would be a config global setting, except for maybe names and icons.

Is there some way the Button card could be set to use a main global setting for all buttons, and only the button specific settings in the actual button?

example from my Tiles:

type: custom:tiles-card
card_settings:
  title: Light panel
  row_height: 25px

global_settings:
  icon:
    color:
      value_on: '#555B65'
      value_off: '#F0C209'
  label:
    color:
      value_on: '#555B65'
      value_off: '#F0C209'
  label_sec:
    color:
      value_on: '#555B65'
      value_off: '#F0C209'
  background:
    value_on: '#F0C209'
    value_off: '#555B65'

entities:
  - entity: group.all_lights_only
    templates:
      label: >
        if (entities['sensor.lights_badge'].state !== 0) return 'Total lights on: ' + entities['sensor.lights_badge'].state;
        return 'No lights on';
#      icon: >
#        if (state === 'on') return 'mdi:power-plug';
#        return 'mdi:power-plug-off';
    background:
      value_on: '#5daf35'
    label:
      color:
        value_off: '#5daf35'
    column: 1
    column_span: 3
    row: 1
    row_span: 1

below 2 snippets from mu lights panel (which is quite a bit larger, but this should give an idea)
25
48

That’s coming in the next version (this week probably) :wink: