Fun with custom:button-card

Put it in styles —> card:

  card:
    - '--c-color-home': '#32a852'
    - '--c-color-away': rgb(255,0,0)
    - '--c-color-zone': '#ffbf00'
    - '--c-color-stationary': '#3182b7'
    - '--c-stroke-width': 2.3
    - '--c-icon-color-on': rgb(0,0,0)
    - '--c-icon-color-off': '#97989c'
    - border-radius: 10px
    - border-width: 0px
    - '-webkit-tap-highlight-color': rgba(0,0,0,0)
    - transition: none
    - '--mdc-ripple-color': |
        [[[
          return variables.state_on
              ? 'rgb(0,0,0)'
              : '#97989c';
        ]]]
    - color: |
        [[[
          return variables.state_on
              ? 'rgb(0,0,0)'
              : '#97989c';
        ]]]
    - background-color: |
        [[[
          return variables.state_on
              ? 'rgba(255,255,255, 0.85)'
              : 'rgba(115, 115, 115, 0.25)';
        ]]]
    - background-image: |
        [[[
          return variables.state_on
              ? 'linear-gradient(to bottom, rgba(255,0,0,.5) 0%, rgba(255,0,0,.5) 50%, rgba(0,0,0,0) 50%)'
              : 'rgba(115, 115, 115, 0.25)';
        ]]]

Perfect. Thanks. I’ll give it a try and report back. I’ve actually got three colors I want to choose from, but I think this will point me in the right direction.

You can also use variables:


variables:
  state_on: …
  …
  …
  bg: green

styles:
  …
  …
    - background-image: |
        [[[
          return variables.state_on
              ? 'linear-gradient(to bottom, ' + variables.bg + ' 0%, ' + variables.bg + ' 50%, rgba(0,0,0,0) 50%)'
              : 'rgba(115, 115, 115, 0.25)';
        ]]]

Thank you so much for your help. I’ve got it working now. Still deciding if I like it or not, but it will make it easier to see on the wall-mounted tablet from a distance.

1 Like

Card variables in extra_styles CSS.

Does anybody know how (or even if) you can use the card variables inside the extra_styles section?
I’m creating an animated image slideshow, but I really need tu put the images as variables since I’m using the card as template on multiple places. I have it working without variables.

  extra_styles: |
    @keyframes slideshow {
      0% {
        background: [[[ return variables.img1 ]]];
      }
      100% {
        background: [[[ return variables.img2 ]]];
      }
    }

square: false
type: grid
cards:
  - type: horizontal-stack
    cards:
      - type: custom:stack-in-card
        cards:
          - type: custom:button-card
            entity: sensor.termometr_kukhnia_temperature
            show_icon: false
            name: Living
            styles:
              card:
                - border-style: none
                - box-shadow: 0px 0px 10px -9px black
              custom_fields:
                temp:
                  - filter: opacity(100%)
                  - justify-self: start
                  - margin-left: 10px
                  - margin-top: 20px
                  - padding-bottom: 10%
                  - font-size: 65%
                graph:
                  - padding-top: 0%
                  - width: 100%
                  - height: 100%
                  - margin-bottom: '-3%'
              icon:
                - width: 25px
                - color: auto
              name:
                - font-size: 87%
                - font-weight: var(--mcg-title-font-weight, 500)
                - justify-self: start
                - margin-top: 6px
                - margin-left: 12px
                - opacity: 0.65
              grid:
                - grid-template-areas: '"n n" "temp temp" "graph graph"'
                - grid-template-columns: 1fr min-content
                - grid-template-rows: 1fr min-content min-content min-content
            custom_fields:
              temp: |
                [[[
                  return `<ha-icon
                    icon="mdi:thermometer"
                    style="width:18px; height: 18px; color:#ff8c00;">
                    </ha-icon><span style="font-size:120%; font-weight: 300;"> 
                    ${states['sensor.termometr_kukhnia_temperature'].state}°C </span> 
                    <ha-icon
                    icon="mdi:water-percent"
                    style="width: 18px; height: 18px; color: #3399ff;">
                    </ha-icon><span style="font-size:120%; font-weight: 300; text-align: center;">
                    ${states['sensor.termometr_kukhnia_humidity'].state}%</span>`
                ]]]
            card_mod:
              style: |
                ha-card {
                  z-index: 1;
                  height: 70px !important;
                }
          - type: custom:mini-graph-card
            entities:
              - entity: sensor.termometr_kukhnia_temperature
                name: Temperature
                color: '#ff8c00'
              - entity: sensor.termometr_kukhnia_humidity
                name: Humidity
                color: '#3399ff'
                y_axis: secondary
            height: 50
            hours_to_show: 24
            line_width: 3
            font_size: 50
            animate: true
            show:
              name: false
              icon: false
              state: false
              legend: false
              fill: fade
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 100%;
                  top: 0px;
                  --ha-card-border-width: 0;
                }
                ha-card:after {
                  content: "";
                  position: absolute;
                  width: 100%;
                  height: 100%;
                  background: linear-gradient(to right, var(--card-background-color) 20%, transparent);
                }
          - type: custom:mushroom-chips-card
            chips:
              - type: light
                entity: light.verkhnii_svet_gostinaia
                content_info: none
                card_mod:
                  style: |
                    ha-card {
                      border: none;
                      box-shadow: none !important;
                      background: none !important;
                    }
            alignment: end
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 100%;
                  top: 0px;
                  z-index: 1;
                }
          - type: custom:mushroom-chips-card
            chips:
              - type: light
                entity: light.svetilnik_kukhnia
                content_info: none
                card_mod:
                  style: |
                    ha-card {
                      border: none;
                      box-shadow: none !important;
                      background: none !important;
                    }
            alignment: end
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 95%;
                  top: 0px;
                  z-index: 1;
                }        
      - type: custom:stack-in-card
        cards:
          - type: custom:button-card
            entity: sensor.termometr_kukhnia_temperature
            show_icon: false
            name: Kitcten
            styles:
              card:
                - border-style: none
                - box-shadow: 0px 0px 10px -9px black
              custom_fields:
                temp:
                  - filter: opacity(100%)
                  - justify-self: start
                  - margin-left: 10px
                  - margin-top: 20px
                  - padding-bottom: 10%
                  - font-size: 65%
                graph:
                  - padding-top: 0%
                  - width: 100%
                  - height: 100%
                  - margin-bottom: '-3%'
              icon:
                - width: 25px
                - color: auto
              name:
                - font-size: 87%
                - font-weight: var(--mcg-title-font-weight, 500)
                - justify-self: start
                - margin-top: 6px
                - margin-left: 12px
                - opacity: 0.65
              grid:
                - grid-template-areas: '"n n" "temp temp" "graph graph"'
                - grid-template-columns: 1fr min-content
                - grid-template-rows: 1fr min-content min-content min-content
            custom_fields:
              temp: |
                [[[
                  return `<ha-icon
                    icon="mdi:thermometer"
                    style="width:18px; height: 18px; color:#ff8c00;">
                    </ha-icon><span style="font-size:120%; font-weight: 300;"> 
                    ${states['sensor.termometr_kukhnia_temperature'].state}°C </span> 
                    <ha-icon
                    icon="mdi:water-percent"
                    style="width: 18px; height: 18px; color: #3399ff;">
                    </ha-icon><span style="font-size:120%; font-weight: 300; text-align: center;">
                    ${states['sensor.termometr_kukhnia_humidity'].state}%</span>`
                ]]]
            card_mod:
              style: |
                ha-card {
                  z-index: 1;
                  height: 70px !important;
                }
          - type: custom:mini-graph-card
            entities:
              - entity: sensor.termometr_kukhnia_temperature
                name: Temperature
                color: '#ff8c00'
              - entity: sensor.termometr_kukhnia_humidity
                name: Humidity
                color: '#3399ff'
                y_axis: secondary
            height: 50
            hours_to_show: 24
            line_width: 3
            font_size: 50
            animate: true
            show:
              name: false
              icon: false
              state: false
              legend: false
              fill: fade
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 100%;
                  top: 0px;
                  --ha-card-border-width: 0;
                }
                ha-card:after {
                  content: "";
                  position: absolute;
                  width: 100%;
                  height: 100%;
                  background: linear-gradient(to right, var(--card-background-color) 20%, transparent);
                }
          - type: custom:mushroom-chips-card
            chips:
              - type: light
                entity: light.verkhnii_svet_gostinaia
                content_info: none
                card_mod:
                  style: |
                    ha-card {
                      border: none;
                      box-shadow: none !important;
                      background: none !important;
                    }
            alignment: end
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 100%;
                  top: 0px;
                  z-index: 1;
                }
          - type: custom:mushroom-chips-card
            chips:
              - type: light
                entity: light.svetilnik_kukhnia
                content_info: none
                card_mod:
                  style: |
                    ha-card {
                      border: none;
                      box-shadow: none !important;
                      background: none !important;
                    }
            alignment: end
            card_mod:
              style: |
                ha-card {
                  position: absolute !important;
                  height: 100%;
                  width: 95%;
                  top: 0px;
                  z-index: 1;
                }        
columns: 1

how to make the entire card clickable?


square: false
type: grid
cards:
  - type: horizontal-stack
    cards:
      - type: custom:stack-in-card
        cards:
          - type: custom:button-card
            entity: sensor.termometr_kukhnia_temperature
            show_icon: false
            name: Living
            tap_action:
              action: url
              url_path: http://google.com

this does not work

2 Likes

This worked for me at a higher level as I’m not using custom:stack-in-card…

type: vertical-stack
cards:
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        name: Aquarium
        icon: mdi:fish
        layout: vertical
        tap_action:
          action: navigate
          navigation_path: /lovelace/aquarium
      - type: custom:button-card
        name: Bedroom
        icon: mdi:bed
        entity: light.bedroom_lighting
        tap_action:
          action: url
          url_path: https://www.google.ca
        hold_action:
          action: toggle
          entity: light.bedroom_lighting
        custom_fields:
          motion: |
type: custom:button-card
tap_action:
  action: none
custom_fields:
  wuguan:
    card:
      type: custom:button-card
      entity: device_tracker.neo6
      show_entity_picture: true
      card mode:
        style: |
          ha-card {
            box-shadow: none;
          }
      tap_action:
        action: none
      show_name: true
      name: |

        [[[ return states['sensor.wu_guan_bu_shu'].state + '步';]]]
      entity_picture: /local/header/wuguan.png
      aspect_ratio: 1/1.4
      styles:
        card:
          - background-color: transparent
        img_cell:
          - padding: 60%
          - margin-top: '-50%'
        name:
          - font-weight: bold
          - font-size: 13px
          - color: black
          - align-self: middle
          - justify-self: center
          - padding-bottom: 4px
          - margin-top: '-50%'
      state:
        - value: not_home
          styles:
            card:
              - filter: opacity(100%)
            icon:
              - filter: grayscale(100%)
  baby:
    card:
      type: custom:button-card
      entity: device_tracker.neo8
      show_name: true
      name: |

        [[[ return states['sensor.bao_bao_bu_shu'].state + 'setup; ]]]
      show_entity_picture: true
      entity_picture: /local/header/baby.png
      aspect_ratio: 1/1.4
      tap_action:
        action: none
      styles:
        img_cell:
          - padding: 60%
          - margin-top: '-50%'
        name:
          - font-weight: bold
          - font-size: 13px
          - color: black
          - align-self: middle
          - justify-self: center
          - padding-bottom: 4px
          - margin-top: '-50%'
      state:
        - value: not_home
          styles:
            card:
              - filter: opacity(100%)
            icon:
              - filter: grayscale(100%)
  weather:
    card:
      type: custom:button-card
      entity: weather.yinchuan
      show_name: true
      name: >

        [[[ return states['weather.yinchuan'].attributes.apparent_temperature +
        '℃'; ]]]
      show_entity_picture: false
      aspect_ratio: 1/1.4
      tap_action:
        action: none
      styles:
        icon:
          - padding: 20%
          - margin-top: '-50%'
          - color: '#f9d840'
        name:
          - font-weight: bold
          - font-size: 13px
          - color: black
          - align-self: middle
          - justify-self: center
          - padding-bottom: 4px
          - margin-top: '-50%'
styles:
  custom_fields:
    wuguan:
      - background-color: transparent
      - padding-left: 0%
      - width: 55px
      - align-self: start
      - justify-self: start
      - justify-content: start
      - align-items: start
    baby:
      - padding-left: 30%
      - width: 55px
      - align-self: start
      - justify-self: start
      - justify-content: start
      - align-items: start
    weather:
      - padding-left: 30%
      - width: 55px
      - align-self: start
      - justify-self: end
      - justify-content: start
      - align-items: start
    notice:
      - width: 100%
    info:
      - width: 100%
  card:
    - overflow: unset
    - height: min-content
    - border-radius: 0%
    - padding-left: 0%
    - padding-top: 0%
    - padding-bottom: 0%
  grid:
    - grid-template-areas: '"wuguan baby weather" "notice notice notice" "info info info"'
    - grid-template-columns: min-content min-content 1fr
    - grid-template-rows: min-content min-content min-content

image

Set tap_action to none, there is no click result but the click effect cannot be deleted
How to delete click effects

Hi,
I want to move entity picture inside button card according to value of a sensor.
Is it possible to get current position of it to convert into variable and use it inside animations keyframe statement?
TIA

Hi,

I created a binary sensor (Aqara T1 Door Sensor) button card which calls a script to turn on my A/C on tap action. This function works fine, and I’m also able to change the state name to On/Off instead of the default Open/Closed.

However, I have difficulty changing the icon color based on the state. Below is my code, is there anything I’m doing wrong?

type: custom:button-card
entity: binary_sensor.living_room_air_con_sensor_contact
name: Air Con
show_name: false
show_state: true
size: 30%
tap_action:
  action: call-service
  service: script.living_room_air_con_toggle
color_type: icon
color: |
  [[[
    if (entity.state === 'off')
      return 'Green'
    else
      return 'Grey'
  ]]]
state_display: |
  [[[
    if (entity.state === 'off')
      return 'Off'
    else
      return 'On'
  ]]]

I’ve also tried using;

  state:
    - value: 'On'
      color: Green
    - value: 'Off'
      color: Grey

The icon color changes to yellow despite the above coding, which seems to be the default color for this senor/entity.

Thanks.

guys ive got a real werid one and not sure if this is the right place to post.

my setup is as follows.

  • Core2023.11.1
  • Frontend20231030.1
    Button card v4.1.1

So I have 2 lights (sideboard & underlight)

image

The code for these lights is

                  - type: custom:button-card
                    entity: light.kitchen_sideboard
                    name: <marquee behavior=scroll scrollamount="3">Side Board Lamp</marquee>
                    template:
                      - light
                      - icon_lamp
                      #- loader

                  - type: custom:button-card
                    entity: light.kitchen_under_light
                    name: Underlight
                    template:
                      - base
                      - icon_lamp

If i turn light.kitchen_sideboard on/off works fine no issues.

BUT if i turn off light.kitchen_under_light i get this error

When i turn the light back on goes back to normal.

So its as if it can report something in its off state? BUT the strange thing is the other light light.kitchen_sideboard works fine when on/off with no errors.? which is throwing me to work out what it is.?!?!

I have tried switching templates from -base to -light

Any help would be great

I’ve not managed to make any progress with this - can anyone shed any light on how to achieve? Would it require CSS styling instead, in order to split out the format?

Hi,
I have an issue with variables not showing.
Followed the instructions, but unfortunately no success.
Any obvious errors?

type: custom:button-card
entity: input_select.bs9000
show_name: true
show_icon: true
variables:
  - var_disc: input_select.bs9000
  - var_pos: input_number.bs9000_sled
name: [[[ return variable.var_disc; ]]]

Hello,

I’m able to display the name of the logged in user with this code.

type: custom:button-card
name: |
  [[[
    return "Hi "+ user.name + "!"
  ]]]

Does anyone know if it’s also possible to display the profile picture for the logged in user?
This is how I’m thinking it would look.
image

The image above is done by statically setting entity: person.drew and show_entity_picture: true. I’m looking for the picture to by dynamic, just like the name based on whoever is logged in.

This should work:

type: custom:button-card
entity: '[[[ return "person." + user.name.toLowerCase(); ]]]'
show_entity_picture: true
name: '[[[ return "Hi " + user.name + "!" ]]]'
1 Like

YES!!! Thank you!

1 Like

Is oit posssible to use two images in an setup like
“i s i”
“i n i”
“l s l”
?

Hi,
How can I use marquee on sensor value?

- type: custom:button-card
  entity: media_player.lounge_2
  label: >
    [[[ return '<marquee> entity.attributes.media_title <\marquee>' ]]]

This scrolls: entity.attributes.media_title and not the value of entity.

Hi,

is it possible to use something like replace here on ${states[“sensor.enceinte_etat”].state
like replace “-” by line break

enceinte: '[[[return `<ha-icon icon="mdi:speaker" style="width: 14px;
 color: var(--color-icon-blue); margin-right: 2px;"></ha-icon><span>
 ${states["sensor.enceinte_etat"].state}</span>`]]]'

Thanks for all help

Your closing marquee tag should be </marquee> - see if that resolves it

1 Like