Lovelace: Button card

Hello,

How can i use this example, to spin the icon for a numeric sensor (in this case is electric power):

type: 'custom:button-card'
styles:
  card:
    - height: 100px
    - width: 100px
  icon:
    - height: 100px
    - width: 100px
entity: sensor.qe_fase_ct_power
show_state: true
show_icon: true
show_name: false
state:
  - value: 'on'
    icon: 'mdi:loading'
    spin: true

I think, I need to change the

state:
  - value: 'on'

but, for what?

Thks in advance


Edit: I found the solution

state:
  - operator: template
    value: |
      [[[ return states['sensor.qe_fase_ct_power'].state != 0 ]]]
    icon: 'mdi:loading'
    spin: true
2 Likes

Hey Guys I am back with a few new questions, but first here is my latest card in progress for my mobile ui.

Without drop down

I recently tried to set up a CBC card with a input_select that had a list of media player that I could play music on. The only way I was able to make the card work was by setting the action to more_info which produced a popup, but that was far from the clean look that select list card has.

Question #1 Can CBC replicated the capabilities that Select List card but with the enhanced css features that we have come to really like?

The Select List card requires a toggle to hide the options for the card.

Question #2 If the answer to Q#1 is yes, would it be possible have the list drop down on tap action and do away with the toggle all together? it a much more polished look in my opinion

hi guys.
Considering I have an custom button card which contains other custom button cards.
Like on screenshot below, bulbs, window and temperature are sub-buttons with different entities
obrazek

The most parent button-card has defined tap_action.
How can I achieve, that clicking anywhere the defined tap action will be executed?
So far I succeeded with disabling any actions from children buttons. But those areas seems to be inactive at all then.

BTW I have to say this card is ingenious one, especially with its inheritance of templates

Set pointer-events: none on all custom_fieldsā€™ style.

Hmm. Iā€™m not able to make it working :frowning: I checked any possible place to add this style.
Could you please assist me where should I put this? I know itā€™s pretty long code to read, but I would be really grateful for that

Here is the card code:

            type: 'custom:button-card'
            template: mycustomcard
            name: Bedroom
            entity: light.lights_bedroom
            icon: 'mdi:lightbulb-group'
            tap_action:
              navigation_path: /lovelace/bedroom
            hold_action:
              service: light.turn_off
              service_data:
                entity_id: light.lights_bedroom
            custom_fields:
              temp:
                card:
                  type: 'custom:button-card'
                  template: subsection_temp
                  entity: sensor.sleeping_temperature
              window:
                card:
                  type: 'custom:button-card'
                  template: subsection 
                  entity: binary_sensor.sleeping_room_window

And its templates if needed

button_card_templates:
  mycustomcard:
    show_icon: true
    show_state: false
    aspect_ratio: 1/1
    card_size: 1
    tap_action:
      action: navigate
    hold_action:
      action: call-service
    styles:
      name:
        - justify-self: start
        - padding-left: 0px
        - font-weight: 500
        - font-size: 14px
        - align-self: middle
        - padding-top: 20px
        - color: 'var(--tile-on-name-text-color, rgba(0, 0, 0, 1))'
      img_cell:
        - justify-content: start
        - align-items: start
        - margin: none
      icon:
        - margin-top: 5px
        - width: 30px
        - height: 30px
        - '--paper-item-icon-color': 'rgba(0,0,0,0.3)'
      card:
        - padding: 10px
        - padding-top: 3px
        - padding-bottom: 7px
        - border-radius: 10%
        - box-shadow: 'rgba(0, 0, 0, 0.3) 0px 1px 3px 0px'
        - background-color: 'var(--tile-on-background, rgba(255, 255, 255, 1))'
      grid:
        - grid-template-areas: '"i window" "n n" "misc temp"'
        - grid-template-columns: 1fr 60%
        - grid-template-rows: 1fr 1fr 1fr
      custom_fields:
        light:
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: start
        window:
          - padding-bottom: 2px
          - align-self: middle
          - justify-self: end
        misc:
          - padding-bottom: 0px
          - align-self: middle
          - justify-self: start
          - color: 'var(--tile-on-state-text-color, rgba(0, 0, 0, 1))'
        temp:
          - padding-bottom: 0px
          - align-self: end
          - justify-self: end
          - margin-right: '-5px'
          - color: 'var(--tile-on-state-text-color, rgba(0, 0, 0, 1))'
  subsection:
    show_name: false
    show_icon: true
    tap_action:
      action: none
    double_tap_action:
      action: none
    hold_action:
      action: none
    styles:
      card:
        - background: transparent
      icon:
        - margin-top: 5px
        - width: 30px
        - height: 30px
        - '--paper-item-icon-color': 'rgba(0,0,0,0.3)'
    style: |
      ha-card {
        box-shadow: none;
      }
  subsection_bottom:
    template: subsection
    styles:
      icon:
        - width: 22px
        - heigth: 22px
        - padding: 0px
        - margin: 0px
  subsection_temp:
    template: subsection_bottom
    show_name: false
    show_icon: true
    show_units: false
    show_state: true
    styles:
      grid:
        - grid-template-areas: '"s i"'
        - grid-template-columns: 1fr 22px
        - grid-template-rows: 1fr
      state:
        - justify-self: start
        - color: 'var(--tile-on-state-text-color, rgba(0, 0, 0, 1))'
        - font-size: 12px
        - margin-top: 6px
      icon:
        - '--paper-item-icon-color': 'rgba(0,0,0,0.3)'
        - color: 'rgba(0,0,0,0.3)'
      card:
        - padding: 0px
        - margin: 0px
1 Like

add - pointer-events: none to custom_field styles, hereā€™s an example from my config

styles:
  ... bunch of crap ...
  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    #<--------------------------- REMOVES CLICKING

Youā€™ll have to do that for each custom_field you have. light, window, misc, and temp.

Yeahā€¦
I think I had custom_fields: level missing in styles when I was trying.
thank you very much.

1 Like

Hi, I am relatively new to HA, so sorry for the perhaps very basic question.
I want to make a remote control card for my HomeTheater setup, with the button card, using this page as a guide
https://community.home-assistant.io/t/lovelace-button-card/65981
and I am running the latest version of HA (2021.3.4)

I created a www directory in the configuration directory, and downloaded button-card.js there.

~ $ ls
addons  backup  config  share   ssl
~ $ cd config/www
www $ ls
button-card.js

Then I put this in my lovelace configuration file
When browsing through the configuration directory and its subdirectories, I did not find a file called ui-lovelace-card.yaml, so I suppose I need to put this config in the file editor that opens when you click on the Raw configuration editor menu item in the lovelace editor ?
Any ideas where this file is in the HA filesystem ?

 - title: MediaControl
    path: mediacontrol
    icon: 'hass:television-box'
    resources:
      - url: /local/button-card.js
        type: module
    badges: []
    cards:
      - type: 'custom:button-card'
        entity: switch.middenlichtsalon
        icon: 'mdi:air-conditioner'
        color: 'rgb(28, 128, 199)'
      - type: button
        name: up
        tap_action:
          action: call-service
          service: remote.send_command
          service_data:
            entity_id: remote.rmproplus_remote
            device: Orange
            command: home
        double_tap_action:
          action: call-service
          service: remote.send_command
          service_data:
            entity_id: remote.rmproplus_remote
            device: Orange
            command: exit
      - type: entities
        entities:
          - input_select.dropdown1234

I get an error telling me that the button-card does not exist in HA

Custom element doesn't exist: button-card.

type: 'custom:button-card'
entity: switch.middenlichtsalon
icon: 'mdi:air-conditioner'
color: 'rgb(28, 128, 199)'

I copy/pasted the config from the examples, and changed the entity name to a name that is known in my system (switch.middenlichtsalon)

I also restarted HA core to make sure the changes have been activated.

What am I doing wrong ?

I love this Button! thank you!

here is my take on this :slight_smile:

Capture3443

still learning! im a noob!

1 Like

what were we thinkingā€¦

tap_action:
  action: call-service
  service: switch.toggle #>
#    [[[ return states['switch.espresso_keuken'].state == 'off'
#        ? 'switch.turn_on' : 'switch.turn_off' ]]]
  service_data:
    entity_id: switch.espresso_keuken

is fully functionalā€¦ why didnā€™t we think of that? Itā€™s not set as short as could be, but at least does away with the nasty template :wink:

have another question though:

on a button with a complex hold_action object, we need the entity for a more-info to be explicitly referenced even when it is the entity of the button?

type: custom:button-card
template: button_alarm
variables:
  dst: >
    [[[ return states['input_boolean.dst'].state ]]]
entity: sensor.dst

show_state: true
show_name: false

tap_action:
  action: call-service
  service: input_boolean.toggle
  service_data:
    entity_id: input_boolean.dst

hold_action:
  action: >
    [[[ return (window.location.pathname.split('/')[2] == 'time_settings')
        ? 'more-info' : 'navigate'; ]]]
  navigation_path: >
    [[[ return (window.location.pathname.split('/')[2] == 'time_settings')
        ? null : '/ui-data/time_settings'; ]]]
# why is the below entity necessary? depending on the current view, it should go either elsewhere, or show the more info of the button entity, which is default for more-info?
  entity: >
    [[[ return (window.location.pathname.split('/')[2] == 'time_settings')
        ? entity.entity_id : null; ]]]

A quick question: color: auto makes the bulb blue and dim it according to the level of brightness. Is there a simple way how to dim a yellow instead of blue bulb icon?

Blue color make sense with bulbs that can manage color temp and brightness but blue does not make sense e.g. with vintage bulbs that are yellow by default. Thanks!

Hi @RomRider

seeking your assistance once again, in trying to have a hold action do something depending on the entity:

  hold_action:
    action: >
      [[[ return variables.z_wave ? 'call-service' : 'call-service'; ]]]
    service: >
      [[[ return variables.z_wave ? 'zwave_js.refresh_value' : 'script.turn_on'; ]]]
    service_data:
      entity_id: >
        [[[ return variables.z_wave ? entity.entity_id : 'script.' + id + '_meterget_power'; ]]]
      refresh_all_values: >
        [[[ return variables.z_wave ? true : null; ]]]

bottom line is I need this to happen to variables.z_wave entities:

service: zwave_js.refresh_value
data:
  entity_id: entity.entity_id
  refresh_all_values: true

and am not sure the templates or object I made above is valid, could you please check and correct that if needed? thanks!

Just a note, overriding templating by the following code

state:
  - value: off
    icon: 'mdi:cloud'

does not work. So there are limits in templating?

No, you donā€™t need it

The color of the icon is based on your primary accent color. I believe if you override it at the card level in the styles option, you can achieve what you want.

[[[ return variables.z_wave ? true : null; ]]] is better with [[[ return variables.z_wave ? true : undefined; ]]]

Else I donā€™t see any problem

well, of course I tried before askingā€¦ the line below my comment is needed or else it simply doesnā€™t show a more info

will update the other to ā€˜undefinedā€™ (btw, what exactly is the difference between the 2? I use the null everywhere in the js logic to do nothingā€¦ seems to work without issues?)

If I understand it right, this code under the particular card (or in the template) should do it?

styles:
  card:
    - '--primary-accent-color': 'rgb(255, 204, 0)'

This one does not work for me.

Sorry, the css variable used for the icon color is this one: --paper-item-icon-active-color

Thanks! There is development but such tweak influence only entities that are in a domain group. All entities on light domain are not affected.

My complete code:

Template

  light:
    layout: name_state
    color: auto
    tap_action:
      action: toggle
      haptic: light
    hold_action:
      action: more-info
      haptic: success
    styles:
      card:
        - border-radius: 10px
        - width: 60px
        - height: 50px
        - padding: 7px
      name:
        - font-size: 12px
    state:
      - value: 'on'
        icon: 'mdi:lightbulb-on'
        styles:
          card:
            - background: Gainsboro
            - '--paper-item-icon-active-color': 'rgb(255, 205, 0)'
          name:
            - color: black
      - value: 'off'
        icon: 'mdi:lightbulb'
        styles:
          icon:
            - color: darkred

Button that does not work:

type: 'custom:button-card'
template: light
entity: light.kitchen_desk
name: Desk

Button influenced:

type: 'custom:button-card'
template: light
entity: group.stove
name: Stove

Itā€™s not domain dependent but some buttons are, some are not, influenced while they share the same template.

Im trying to create a button that displays a picture.
Using {{ states.sensor.sack_colour.attributes.entity_picture }} in Dev Tools Template returns the string /local/bag_black.jpg

So im trying to use this in a button:

type: 'custom:button-card'
show_entity_picture: true
entity_picture: >
  [[[
    return '{states.sensor.sack_colour.attributes.entity_picture}'
  ]]]
aspect_ratio: 1/1

Is this not possible or (more likely) have I got it wrong?