Lovelace: Button card

Here’s the updated version, it’s also in my github now

# lovelace_gen

{% set color = color|default('var(--paper-item-icon-active-color)') %}
{% set aspect_ratio = aspect_ratio|default('1/1') %}

type: custom:button-card
aspect_ratio: {{ aspect_ratio }}
entity: {{ entity }}
icon: {{ icon }}
color: var(--paper-item-icon-color)
show_name: true
show_label: true
show_icon: true
show_last_changed: true
size: 70%
tap_action:
  action: more-info
  haptic: light
styles:
  icon:
  - opacity: 0.3
  - width: 100%
  img_cell:
  - top: 0%
  - left: 30%
  - position: absolute
  - z-index: 2
  grid:
  - grid-template-areas: '"info info" "n n" "l l"'
  - grid-template-columns: 40% 1fr
  - grid-template-rows: 1fr min-content min-content
  - position: relative
  card:
  - padding: 10px
  - border-radius: 15px
  - z-index: 0
  name:
  - justify-self: start
  - align-self: end
  - font-weight: bold
  - font-family: Helvetica 
  - font-size: 12px
  - text-align: start
  - background-image: linear-gradient(to right, white 0%, white 80%, rgba(0,0,0,0))
  - -webkit-background-clip: text
  - -webkit-text-fill-color: transparent
  - position: relative
  - display: inline-block
  - width: 100%
  - align-content: start
  - text-align: start
  - text-overflow: unset
  - z-index: 5
  label:
  - justify-self: start
  - align-self: end
  - font-weight: bold
  - font-family: Helvetica 
  - font-size: 12px
  - text-align: start
  - background-image: linear-gradient(to right, var(--paper-item-icon-color) 0%, var(--paper-item-icon-color) 80%, rgba(0,0,0,0))
  - -webkit-background-clip: text
  - -webkit-text-fill-color: transparent
  - position: relative
  - display: inline-block
  - width: 100%
  - align-content: start
  - text-align: start
  - text-overflow: unset
  - z-index: 5
  custom_fields:
    plot:
    - position: absolute
    - top: 55%
    - left: 50%
    - width: calc(100% + 25px)
    - transform: translate(-50%, calc(-50% + 10px))
    - z-index: 3
    - --paper-card-background-color: 'rgba(0, 0, 0, 0.0)'
    - --ha-card-background: "rgba(0, 0, 0, 0.0)"
    - --ha-card-box-shadow: 'none'
    - pointer-events: none
    info:
    - align-self: start
    - width: 40%
    - z-index: 5
custom_fields:
  plot:
    card:
      type: custom:mini-graph-card
      entities:
        - {{ entity }}
      group: true
      points_per_hour: 1
      hour24: true
      line_color: {{ color }}
      line_width: 10
      hours_to_show: 24
      update_interval: 600
      show:
        name: false
        icon: false
        state: false
        points: false
        legend: false
        average: false
        extrema: false
        labels: false
        fill: false
        labels_secondary: false
        name_adaptive_color: false
        icon_adaptive_color: false
  info: >
    [[[
      var entity_id = (entity === undefined) ? 'Invalid Entity' : entity.entity_id;
      var statestr = (entity === undefined || entity.state === undefined) ? null : entity.state;
      var units = (statestr && entity.attributes.unit_of_measurement) ? entity.attributes.unit_of_measurement : null;
      var date = (statestr && entity.attributes.device_class === 'timestamp') ? new Date(statestr) : null;
      var value;
      if (statestr && date === null) {
        if (statestr.split('.').length - 1 <= 1){
          var test = parseFloat(parseFloat(statestr).toFixed(2));
          value = (isNaN(test)) ? null : test;
          // test if units are in the state because some sensors are stupid.  Looking
          //   at you synology.
          const expr = /[^-.0-9]+/;
          var has_units = expr.test(statestr.trim());
          // console.log(`${entity_id}: "${statestr}" ${matches}`);
          if (value && has_units)
            units = statestr.replace(/[.0-9]+/, ''); 
        }
      }
      // console.log(`${entity_id}: ${statestr}, ${units}, ${date}, ${value}`);
      const length = 50;
      const width = 3;
      var radius = length / 2;
      if (date){
        let now = new Date();
        var tdelta = Math.floor((now - date)/1000);
        // console.log(`${entity_id}: ${tdelta}`);
        function plural(descriptor, divisor){
          var ret = Math.floor(tdelta/divisor);
          return (ret == 1) ? [ret, descriptor] : [ret, `${descriptor}s`];
        }
        var values;
        if (tdelta < 60)
          values = plural('second', 1);
        else if (tdelta < 60 * 60)
          values = plural('minute', 60);
        else if (tdelta < 60 * 60 * 24)
          values = plural('hour', 60 * 60);
        else if (tdelta < 7 * 60 * 60 * 24)
          values = plural('day', 60 * 60 * 24);
        else
          values = plural('week', 7 * 60 * 60 * 24);
        return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="{{ color }}" />
            <text x="50%" y="43%" fill="var(--paper-card-background-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${values[0]}<tspan x="50%" dy="1.2em" font-size="10" font-weight="normal" >${values[1]}</tspan>
            </text>
          </svg>
          `;
      }
      else if (value && units && units === '%') {
        radius = (length - 3) / 2;
        const circumference = radius * 2 * Math.PI;
        return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="none" stroke="var(--paper-item-icon-color)" opacity="0.5" stroke-width="${width}" />
            <circle style="
                transform: rotate(-90deg);
                transform-origin: 50% 50%;
                stroke-dasharray: ${circumference};
                stroke-dashoffset: ${circumference - value / 100 * circumference};
              "
              id="c_brightness" cx="25" cy="25" r="${radius}" stroke="var(--paper-item-icon-active-color)" stroke-width="${width}" fill="none" stroke-linecap="round" />
            <text x="50%" y="54%" fill="var(--primary-text-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${value}<tspan font-size="10" font-weight="normal" >%</tspan>
            </text>
          </svg>
          `;
        }
      else if (value && units && units.includes('°')) {
        return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="{{ color }}" />
            <text x="50%" y="54%" fill="var(--paper-card-background-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${value}<tspan font-size="10" font-weight="normal" >${units}</tspan>
            </text>
          </svg>
          `;
      }
      else if (value && units && units.length > 1) {
        var y = (String(value).length > units.length) ? "50%" : "43%";
        return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="{{ color }}" />
            <text x="50%" y="${y}" fill="var(--paper-card-background-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${value}<tspan x="50%" dy="1.2em" font-size="10" font-weight="normal" >${units}</tspan>
            </text>
          </svg>
          `;
        }
      else if (value) {
        return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="{{ color }}" />
            <text x="50%" y="54%" fill="var(--paper-card-background-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${value}<tspan font-size="10" font-weight="normal" >${units}</tspan>
            </text>
          </svg>
          `;
      }
      return `
          <svg viewBox="0 0 50 50">
            <circle cx="25" cy="25" r="${radius}" fill="{{ color }}" />
            <text x="50%" y="54%" fill="var(--paper-card-background-color)" font-weight="bold" font-size="14" text-anchor="middle" alignment-baseline="middle">${statestr}
            </text>
          </svg>
          `; 
    ]]]
   
1 Like

Without polling the device, you’ll have to keep track of what was last pressed in the backend. This will cause your system to also get out of sync with the devices during restart of HA.

You have many options:

  1. Make a template fan using send_command services.
  2. Make template switches with send_command services, attach the value_template to an input_select that ‘stores’ the which switch was last pressed.
  3. Attempt to make this work with just the button card, but you’d need to query the state (which you said you didn’t want to do)

Either way, all of these are grounds for a separate post because they all require other integrations.

Quick question, I decided to use input_select and how do you update the input select from the button?

This is my input selection

input_select:
  fan_speed:
    name: fan speed
    options:
      - one
      - two
      - none
    initial: none

button

     - type: vertical-stack
        title: Study room Fan        
        cards:
        - type: horizontal-stack
          cards:
          - type: 'custom:button-card'
            styles:
              card:
                - height: 50px
                - width: 50px
            entity: switch.study_room_celing_fan_speed_two
            service:
              domain: input_select
              action: select_option
              data:
                entity_id: input_select.fan_speed
                option: one
            show_name: false
            color_type: card
            color: rgb(66, 134, 244)
            state:
            - value: 'off'
              color: rgb(255, 0, 0)
            icon: mdi:fan

somehow input select doesnt get updated :frowning:

Yes, as I said before, this needs to be done OUTSIDE the button card. It has to be done with a template fan or with template switches.

EDIT: Unless you’re doing it with an automation

if that’s the case, your service is incorrectly formatted.

tap_action:
  action: call-service
  service: input_select.select_option
  service_data:
    entity_id: input_select.fan_speed
    option: one

Hi at all… someone could help me to make my custombutton card blinking only when another entity is on??? ths is my code:

color_type: icon
entity: input_boolean.ad_alarm
hold_action: none
icon: 'mdi:battery-charging'
show_label: true
show_state: false
name: BATTERY
size: 20%
state:
  - label: |
      [[[
        if (states['alert.battery'].state == 'on')
        return "ALLARM";
        return "ACTIVE";
      ]]]
    styles:
      icon:
        - color: |
            [[[
              if (states['input_boolean.ad_alarm'].state == 'on')
                return 'green';
                return '';
            ]]]          
             
      label:
        - color: |
            [[[
              if (states['alert.battery'].state == 'on')
                return 'red';
                return '';
            ]]]
        - font-size: 14px
        - font-weight: 600
      name:
        - color: '#ffffff'
        - font-size: 16px
        - font-weight: 600
    value: 'on'
styles:
  card:
    - height: 120px
  label:
    - font-weight: bold
type: 'custom:button-card'

What I need is to make the card blinking only when alert.battery is ON

Thanks a lot

Hi Petro,

what ist new in this Version?

works without lovelace gen?

it’s not using 3 cards to make a single button. It’s no longer using the picture-elements. Also, I think I fixed a bunch of random errors in the codebase.

Managed to copy paste codes from this thread and made this button:

This buttons embeds gauge-card, mini-graph-card and bar-card

One issue is tap-action, when clicling on empty space or title it is working, but when clicking on embedded gauge or bar cards it shows more-info only for one sensor and not for entire card

How to make tap-action work even when clicked on embedded cards?

Template:

button_card_templates:
  plug:
    triggers_update: all
    aspect_ratio: 1/1.05
    styles:
      img_cell:
        - justify-content: start
      card:
        - padding: 5%
        - opacity: 100%
        - text-transform: capitalize
        - text-shadow: 0px 0px 3px black
        - font-size: 10px
        - font-weight: bold
        - background: '#254117'
      name:
        - font-weight: bold
        - justify-self: start
        - font-size: 13px
        - overflow: visible
        - text-align: left
        - white-space: normal
      custom_fields:
        gauge:
          - '--ha-card-background': 'rgba(0, 0, 0, 0.0)'
        bar:
          - margin-top: '-5px'
          - '--ha-card-background': 'rgba(0, 0, 0, 0.0)'
        graph:
          - '--ha-card-background': 'rgba(0, 0, 0, 0.0)'
      grid:
        - grid-template-areas: '"n gauge" "graph graph" "bar bar"'
        - grid-template-columns: 1fr 1fr
        - grid-template-rows: 2fr 2fr 2fr
    custom_fields:
      gauge:
        card:
          style: |-
            .type-gauge {
              padding: 0%;
            }
            div.name {
              font-size: 0px;
            }
          type: gauge
          entity: |
            [[[
              if (states[entity.entity_id].state != 'unavailable') {
              var ent = entity.entity_id
              var ent_p = ent.replace("switch", "sensor")
              ent_p += "_energy_power"
              return `${[ent_p]}`}
            ]]]
          min: 0
          max: 3000
          severity:
            green: 0
            yellow: 1000
            red: 2000
      graph:
        card:
          type: 'custom:mini-graph-card'
          entities:
            - entity: |
                [[[
                  if (states[entity.entity_id].state != 'unavailable') {
                  var ent = entity.entity_id
                  var ent_p = ent.replace("switch", "sensor")
                  ent_p += "_energy_power"
                  return `${[ent_p]}`}
                ]]]
          group: true
          points_per_hour: 60
          line_color: red
          line_width: 5
          hours_to_show: 24
          update_interval: 10
          show:
            name: false
            icon: false
            state: false
            points: false
            labels: false
            fill: false
      bar:
        card:
          style: |-
            bar-card-currentbar, bar-card-backgroundbar{
              border-radius: 3px;
            }
            .card-content {
              text-align: start;
              padding: 0px
            }
            bar-card-name, bar-card-value {
              overflow: visible;
            }
          height: 11
          animation:
            state: 'on'
            speed: 1
          type: 'custom:bar-card'
          entities:
            - entity: |
                [[[
                  if (states[entity.entity_id].state != 'unavailable') {
                  var ent = entity.entity_id
                  var ent_s = ent.replace("switch", "sensor")
                  ent_s += "_energy_voltage"
                  return `${[ent_s]}`}
                ]]]
              name: voltage
              min: 0
              max: 300
              severity:
                - from: 0
                  to: 210
                  color: '#0000ff'
                - from: 210
                  to: 220
                  color: '#00ffff'
                - from: 220
                  to: 240
                  color: '#00ff00'
                - from: 240
                  to: 250
                  color: '#ffa500'
                - from: 250
                  to: 260
                  color: '#ff00ff'
                - from: 260
                  to: 300
                  color: '#ff0000'
            - entity: |
                [[[
                  if (states[entity.entity_id].state != 'unavailable') {
                  var ent = entity.entity_id
                  var ent_d = ent.replace("switch", "sensor")
                  ent_d += "_energy_today"
                  return `${[ent_d]}`}
                ]]]
              name: today
              min: 0
              max: 1000
              severity:
                - from: 0
                  to: 100
                  color: '#0000ff'
                - from: 100
                  to: 200
                  color: '#00ffff'
                - from: 200
                  to: 300
                  color: '#00ff00'
                - from: 300
                  to: 400
                  color: '#ffff00'
                - from: 400
                  to: 500
                  color: '#ffa500'
                - from: 500
                  to: 600
                  color: '#ff00ff'
                - from: 600
                  to: 1000
                  color: '#ff0000'
            - entity: |
                [[[
                  if (states[entity.entity_id].state != 'unavailable') {
                  var ent = entity.entity_id
                  var ent_m = ent.replace("switch", "sensor")
                  ent_m += "_energy_total"
                  return `${[ent_m]}`}
                ]]]
              name: month
              min: 0
              max: 100
              severity:
                - from: 0
                  to: 10
                  color: '#0000ff'
                - from: 10
                  to: 20
                  color: '#00ffff'
                - from: 20
                  to: 30
                  color: '#00ff00'
                - from: 30
                  to: 40
                  color: '#ffff00'
                - from: 40
                  to: 50
                  color: '#ffa500'
                - from: 50
                  to: 60
                  color: '#ff00ff'
                - from: 60
                  to: 100
                  color: '#ff0000'
          positions:
            icon: 'off'
            name: inside
            indicator: 'off'
    tap_action:
      action: call-service
      service: browser_mod.popup
      service_data:
        card:
          entities: |
            [[[
              var ent = entity.entity_id
              var ent_power = ent.replace("switch", "sensor")
              var ent_volt = ent.replace("switch", "sensor")
              var ent_today = ent.replace("switch", "sensor")
              var ent_month = ent.replace("switch", "sensor")
              ent_power += "_energy_power"
              ent_volt += "_energy_voltage"
              ent_today += "_energy_today"
              ent_month += "_energy_total"
              return [ent,ent_power,ent_volt,ent_today,ent_month]
            ]]]
          type: entities
        title: |
          [[[
            return [entity.attributes.friendly_name]
          ]]]

Card:

type: 'custom:button-card'
entity: switch.plug_fridge
template: plug
5 Likes

This is not possible for now, however, you can probably tackle it using a custom_field with a transparent button-card inside with position: absolute and z-index: 999 which would hold your tap_action and take the full width/height of the card.

1 Like

Hello,

Is it possible to select a service based on a template? Something like this, where I try to select turn_on or turn_off based on the status of a binary_sensor.

The input_boolean will trigger a sequence in Node Red to send an infrared command to the turn on or off the TV.

- type: custom:button-card
  template: lroom_tv_buttons
  name: Power
  show_name: true
  entity: binary_sensor.lroom_tv_power
  icon: mdi:power
  tap_action:
    action: call-service
    service_template: >
      [[[
        if (states['binary_sensor.lroom_tv_power'].state === 'off')
          input_boolean.turn_on
        else
          input_boolean.turn_off
        endif
      ]]]
    service_data:
      entity_id: input_boolean.lroom_tv_power
  state:
    - value: 'on'
      color: limegreen
    - value: 'off'
      color: red

Thanks for any help/suggestion. This is an awesome community!
Tales

Hello , I need help with the button-card and call an additional window in the form of a popup, somehow I managed to cover the previous things, but I want to add a window in the form of a fan remote and something does not work, here is the code for the button-card type card code, and here is the code for the remote control that I want to add code , how to connect it together so that clicking a button-card will pop up a new window with the remote control, thanks for the help Zrzut ekranu 2020-11-06 204259
Button Card Code

                  - type: 'custom:button-card'
                    icon: 'mdi:power-socket-eu'
                    name: Gniazdko Tv
                    size: 30%
                    styles:
                      img_cell:
                        - padding-left: 30px
                        - justify-content: start
                      card:
                        - margin: 5px
                        - width: 100px
                        - height: 100px
                        - border-radius: 15px
                        - box-shadow: >
                            [[[ return states['sun.sun'].state ==
                            'below_horizon'
                              ? '-5px -5px 10px rgba(50, 50, 50, .2), 6px 6px 10px rgba(0, 0, 0, .08)'
                              : '-5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03)';
                            ]]]
                        - background-color: var(--primary-background-color)
                      icon:
                        - color: var(--primary-text-color)
                      grid:
                        - grid-template-areas: '"i" "n" "s"'
                        - grid-template-columns: 1fr
                        - grid-template-rows: 1fr min-content min-content
                      name:
                        - justify-self: start
                        - font-weight: bold
                        - font-size: 15px
                        - padding-left: 15px
                      state:
                        - justify-self: start
                        - font-weight: bold
                        - font-size: 15px
                        - opacity: 0.6
                        - padding: 0 15px 5px
                    show_state: true
                    state:
                      - value: 'on'
                        styles:
                          card:
                            - border-width: 2px
                            - box-shadow: >
                                [[[ return states['sun.sun'].state ==
                                'below_horizon'
                                  ? 'inset -4px -4px 5px rgba(60, 60, 60, .6), inset 4px 4px 5px rgba(0, 0, 0, .5)'
                                  : 'inset -3px -3px 5px rgba(255, 255, 255), inset 3px 3px 5px rgba(0, 0, 0, .08)';
                                ]]]
                            - border-color: var(--paper-item-icon-active-color)
                          icon:
                            - color: var(--paper-item-icon-active-color)
                    tap_action:
                      action: call-service
                      service: browser_mod.command
                      service_data:

Remote Code

entities:
  - cards:
      - entities:
          - cards:
              - icon: 'mdi:weather-windy'
                show_icon: true
                show_name: false
                size: 100%
                styles:
                  card:
                    - margin-left: 69px
                    - box-shadow: none
                    - width: 50px
                    - height: 50px
                    - background-color: var(--primary-background-color)
                  icon:
                    - color: var(--primary-text-color)
                tap_action:
                  action: call-service
                  service: switch.turn_on
                  service_data:
                    entity_id: switch.wenytylator_speed_high
                type: 'custom:button-card'
            type: 'custom:hui-horizontal-stack-card'
          - cards:
              - icon: 'mdi:minus'
                show_icon: true
                show_name: false
                size: 100%
                styles:
                  card:
                    - margin-left: 11px
                    - box-shadow: none
                    - width: 50px
                    - height: 50px
                    - background-color: var(--primary-background-color)
                  icon:
                    - color: var(--primary-text-color)
                tap_action:
                  action: call-service
                  service: switch.turn_on
                  service_data:
                    entity_id: switch.wenytylator_speed_down
                type: 'custom:button-card'
              - name: OK
                show_icon: false
                show_name: false
                style: |
                  ha-card {
                    box-shadow:
                      {% if is_state('sun.sun', 'above_horizon') %}
                        -5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
                      {% elif is_state('sun.sun', 'below_horizon') %}
                        -5px -5px 8px rgba(50, 50, 50, .2), 5px 5px 8px rgba(0, 0, 0, .08);
                      {% endif %}
                  }
                styles:
                  card:
                    - width: 50px
                    - height: 50px
                    - border-radius: 100px
                    - background-color: var(--primary-background-color)
                  name:
                    - font-size: 20px
                    - font-weight: bold
                    - font-family: Helvetica
                    - letter-spacing: '-0.01em'
                tap_action:
                  action: call-service
                  service: switch.turn_on
                  service_data:
                    command: enter
                    entity_id: remote.xiaomi
                type: 'custom:button-card'
              - icon: 'mdi:plus'
                show_icon: true
                show_name: false
                size: 100%
                styles:
                  card:
                    - box-shadow: none
                    - width: 50px
                    - height: 50px
                    - background-color: var(--primary-background-color)
                  icon:
                    - color: var(--primary-text-color)
                tap_action:
                  action: call-service
                  service: switch.turn_on
                  service_data:
                    entity_id: switch.wenytylator_speed_up
                type: 'custom:button-card'
            type: 'custom:hui-horizontal-stack-card'
          - cards:
              - icon: 'mdi:cloud-outline'
                show_icon: true
                show_name: false
                size: 100%
                styles:
                  card:
                    - margin-left: 69px
                    - box-shadow: none
                    - width: 50px
                    - height: 50px
                    - background-color: var(--primary-background-color)
                  icon:
                    - color: var(--primary-text-color)
                tap_action:
                  action: call-service
                  service: switch.turn_on
                  service_data:
                    entity_id: switch.wenytylator_speed_low
                type: 'custom:button-card'
            type: 'custom:hui-horizontal-stack-card'
        show_header_toggle: false
        style: |
          ha-card {
            box-shadow:
              {% if is_state('sun.sun', 'above_horizon') %}
                inset -3px -3px 5px rgba(255,255,255,.65), inset 3px 3px 5px rgba(0,0,0,.035);
              {% elif is_state('sun.sun', 'below_horizon') %}
                inset -3px -3px 5px rgba(50, 50, 50,.5), inset 3px 3px 5px rgba(0,0,0,.3);
              {% endif %}
            border-radius: 30px;
            background-color: var(--primary-background-color)
          }
        type: 'custom:hui-entities-card'
    type: 'custom:hui-horizontal-stack-card'
  - show_icon: true
    show_name: false
    style: |
      ha-card {
        --ha-card-background: none !important;
        box-shadow: none !important;
      }
    styles:
      card:
        - width: 10px
        - height: 10px
    type: 'custom:button-card'
  - cards:
      - icon: 'mdi:sync'
        show_icon: true
        show_name: false
        style: |
          ha-card {
            box-shadow:
              {% if is_state('sun.sun', 'above_horizon') %}
                -5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
              {% elif is_state('sun.sun', 'below_horizon') %}
                -5px -5px 8px rgba(50, 50, 50, .2), 5px 5px 8px rgba(0, 0, 0, .08);
              {% endif %}
          }
        styles:
          card:
            - margin-top: 10px
            - margin-left: 5px
            - width: 60px
            - height: 60px
            - border-radius: 15px
            - background-color: var(--primary-background-color)
          icon:
            - color: var(--primary-text-color)
        tap_action:
          action: call-service
          service: switch.turn_on
          service_data:
            entity_id: switch.wenytylator_rotation
        type: 'custom:button-card'
      - icon: 'mdi:power'
        show_icon: true
        show_name: false
        style: |
          ha-card {
            box-shadow:
              {% if is_state('sun.sun', 'above_horizon') %}
                -5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
              {% elif is_state('sun.sun', 'below_horizon') %}
                -5px -5px 8px rgba(50, 50, 50, .2), 5px 5px 8px rgba(0, 0, 0, .08);
              {% endif %}
          }
        styles:
          card:
            - margin-top: 10px
            - margin-left: 8px
            - width: 60px
            - height: 60px
            - border-radius: 15px
            - background-color: var(--primary-background-color)
          icon:
            - color: var(--primary-text-color)
        tap_action:
          action: call-service
          service: switch.turn_on
          service_data:
            entity_id: switch.wenytylator_power
        type: 'custom:button-card'
      - icon: 'mdi:timer'
        show_icon: true
        show_name: false
        style: |
          ha-card {
            box-shadow:
              {% if is_state('sun.sun', 'above_horizon') %}
                -5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
              {% elif is_state('sun.sun', 'below_horizon') %}
                -5px -5px 8px rgba(50, 50, 50, .2), 5px 5px 8px rgba(0, 0, 0, .08);
              {% endif %}
          }
        styles:
          card:
            - margin-top: 10px
            - margin-left: 8px
            - width: 60px
            - height: 60px
            - border-radius: 15px
            - background-color: var(--primary-background-color)
          icon:
            - color: var(--primary-text-color)
        tap_action:
          action: call-service
          service: switch.turn_on
          service_data:
            entity_id: switch.wenytylator_timer
        type: 'custom:button-card'
    type: 'custom:hui-horizontal-stack-card'
show_header_toggle: false
style: |
  ha-card {
    background-color: var(--primary-background-color);
    width: 250px;
    border-radius: 10px;
    margin: 10px auto;
    box-shadow:
      {% if is_state('sun.sun', 'above_horizon') %}
        -5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
      {% elif is_state('sun.sun', 'below_horizon') %}
        -5px -5px 8px rgba(50, 50, 50, .2), 5px 5px 8px rgba(0, 0, 0, .08);
      {% endif %}
  }
type: entities

Did it wit a script, which I call from button-card. But it would be nice to know if it can be done directly in button-card.

Cheers
Tales

Yes, but it’s not service_template, just service :slight_smile:

browser_mod.command is not a valid service for a popup, please check browser_mod’s documentation.

ok @RomRider have this error (Entity object at position 1 is missing entity field.) now my code looks like this:

                  - type: 'custom:button-card'
                    entity: switch.gniazdko_salon_2
                    icon: 'mdi:power-socket-eu'
                    name: Gniazdko Tv
                    size: 30%
                    styles:
                      img_cell:
                        - padding-left: 30px
                        - justify-content: start
                      card:
                        - margin: 5px
                        - width: 100px
                        - height: 100px
                        - border-radius: 15px
                        - box-shadow: >
                            [[[ return states['sun.sun'].state ==
                            'below_horizon'
                              ? '-5px -5px 10px rgba(50, 50, 50, .2), 6px 6px 10px rgba(0, 0, 0, .08)'
                              : '-5px -5px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03)';
                            ]]]
                        - background-color: var(--primary-background-color)
                      icon:
                        - color: var(--primary-text-color)
                      grid:
                        - grid-template-areas: '"i" "n" "s"'
                        - grid-template-columns: 1fr
                        - grid-template-rows: 1fr min-content min-content
                      name:
                        - justify-self: start
                        - font-weight: bold
                        - font-size: 15px
                        - padding-left: 15px
                      state:
                        - justify-self: start
                        - font-weight: bold
                        - font-size: 15px
                        - opacity: 0.6
                        - padding: 0 15px 5px
                    show_state: true
                    state:
                      - value: 'on'
                        styles:
                          card:
                            - border-width: 2px
                            - box-shadow: >
                                [[[ return states['sun.sun'].state ==
                                'below_horizon'
                                  ? 'inset -4px -4px 5px rgba(60, 60, 60, .6), inset 4px 4px 5px rgba(0, 0, 0, .5)'
                                  : 'inset -3px -3px 5px rgba(255, 255, 255), inset 3px 3px 5px rgba(0, 0, 0, .08)';
                                ]]]
                            - border-color: var(--paper-item-icon-active-color)
                          icon:
                            - color: var(--paper-item-icon-active-color)
                    tap_action:
                      action: call-service
                      service: browser_mod.popup
                      service_data:
                        title: Popup example
                        large: true
                        card:
                          type: 'entities'                        
                          entities:
                            - cards:
                                - icon: 'mdi:weather-windy'
                                  show_icon: true
                                  show_name: false
                                  size: 100%
                                  styles:
                                    card:
                                      - margin-left: 69px
                                      - box-shadow: none
                                      - width: 50px
                                      - height: 50px
                                      - background-color: var(--primary-background-color)
                                    icon:
                                      - color: var(--primary-text-color)
                                  tap_action:
                                    action: call-service
                                    service: switch.turn_on
                                    service_data:
                                      entity_id: switch.wenytylator_speed_high
                                  type: 'custom:button-card'
                              type: 'custom:hui-horizontal-stack-card'
                            - cards:
                                - icon: 'mdi:minus'
                                  show_icon: true
                                  show_name: false
                                  size: 100%
                                  styles:
                                    card:
                                      - margin-left: 11px
                                      - box-shadow: none
                                      - width: 50px
                                      - height: 50px
                                      - background-color: var(--primary-background-color)
                                    icon:
                                      - color: var(--primary-text-color)
                                  tap_action:
                                    action: call-service
                                    service: switch.turn_on
                                    service_data:
                                      entity_id: switch.wenytylator_speed_down
                                  type: 'custom:button-card'                            
                                  deviceID:
                                    - this

Your entity card inside your pop-up is wrong. entities doesn’t take a card list but an entity list.

Hello, I had tried that, but I got this:

  2020-11-07 22:23:22 ERROR (MainThread) [frontend.js.latest.202010214] http://homeassistant.local:8123/local/button-card.js?v=3.4.0-3:1739:80 Uncaught ButtonCardJSTemplateError: ReferenceError: input_boolean is not defined in 'if (states['binary_sensor.lroom_tv_power'].state === 'off')
      input_boolean.turn_on
    else
      i...'

I solved ir for now with a script, but i’d be happy to learn about what I’m doing wrong.

Thanks
Tales

This and the other one should be strings, it’s not jinja2.
return "input_boolean.turn_on" or off

how to do it ? Buddy, to have a button-type card and after pressing the button, the remote control that I showed earlier opened?

Is it possible to use a template for the ‘entity’ in? Basically I want it to use either entity A or B depending on their state. I saw that it’s not listed in the docs as an option (while name, label, state etc do have that listed). Just wanted to ask perhaps someone has a different way to achieve this, before I do it a different way (which takes more resources).

How can I make the icon colour behave like that of the built-in entities card? For example, for an RGB light, the built-in entities card seems to use shades of yellow if the light is set to pure white when varying the brightness. This means, on full brightness, it will use the same yellow as for a non-RGB light when it’s on. The custom button card under the same circumstances will show a white icon which disappears against the default white background. Technically, there is nothing wrong with that. I’d just like it to behave the same, if possible. As one can see, for other colours, the two are in sync (e.g. the light green colour).



EDIT:
Here’s my config for that light (I tried setting color: auto):

          - type: custom:button-card
            name: Dining Room
            entity: light.smart_bulb_3
            size: 20%
            color: var(--button-card-light-color)
            show_label: true
            label: >
              [[[
                var b = states['light.smart_bulb_3'].attributes.brightness;
                return parseInt(b ? b/2.55 : '0') + '%';
              ]]]
            styles:
              name:
                - color: var(--paper-item-icon-color)
              label:
                - color: var(--paper-item-icon-color)
                - padding-left: 1ex
              card:
                - font-size: 12px
              grid:
                - grid-template-areas: '"l" "i" "n"'
                - grid-template-rows: min-content 1fr min-content
                - grid-template-columns: 1fr
            tap_action:
              action: toggle
              haptic: light
            hold_action:
              action: more-info
              haptic: selection