Fun with custom:button-card

Hi everybody,

I’m playing with button_card and something (ok that really a detail…) annoying me…

  graph_temp_hum:
    variables:
      entity: "sensor.xiaomi_multisensor_salon_humidite"
      color: "var(--info-color)"
      name: "Default name"
      icon: "mdi:adjust"
    styles:
      card:
        - padding: 0px
      grid:
        - grid-template-areas: '"item1" "item2"'
        - grid-template-columns: 1fr
        - grid-template-rows: 1fr max-content
    custom_fields:
      item1:
        card:
          entity: '[[[ return variables.entity ]]]'
          icon: '[[[ return variables.icon ]]]'
          template:
            - icon_info_vertical
          style: |
            ha-card {
              box-shadow: none;
              background: none;
              border-radius: var(--border-radius);
            }
          styles:
            card:
              - top: 12px
              - left: 12px
              - height: 47px
          type: 'custom:button-card'
      item2:
        card:
          type: 'custom:mini-graph-card'
          entities:
            - entity: '[[[ return variables.entity ]]]'
          line_color: '[[[ return variables.color ]]]'
          line_width: 10
          font_size: 55
          height: 120
          show:
            name: false
            icon: false
            legend: false
            state: true
          style: |
            ha-card {
              box-shadow: none;
              background: none;
              border-radius: var(--border-radius);
            }
          styles:
            card:
              - top: 4px
              - left: 12px

And the result:

How to reduce the tiny white gap ?

Thank you !!

2 Likes

Hello is it possible if some one can help me please? I have a standard button card currently working to press a wiser integration, see below.

"show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: button.wiser_cancel_all_heating_overrides
name: ’ Cancel All Overrides’ "

When i try and run this toggle through a custom button card i get call service failed.

you can’t toggle a button @awallace89
try

type: button
tap_action:
  action: call-service
  service: button.press
  data: {}
  target:
    entity_id: button.wiser_cancel_all_heating_overrides

I completely agree. Using the integrated lovelace button it works, however i cant get button.press service to work in the custom button. I have now just setup a script to press the wiser but. Thank you for your help.

I thought you were asking for a standard button.
@Awallace89 try this for custom:button-card:

tap_action:
  action: call-service
  service: button.press
  service_data:
    entity_id: blah.blah

Please be so kind and format your code according to the forum rules (especially point 8 and 11). :slight_smile: It is helpful for other people that want to answer your question. By not formatting the code properly, you loose ie. the indentation, that is the reason for errors in many, many cases. Without the formatting, we just can’t see, if there is an error. Thank you! :slight_smile:

That being said, if you want to use the toggle service in custom:button-card, you need to set the entity via the “main” button part, not in the “service” part.

In theory something like this:

show_name: true
show_icon: true
type: custom:button-card
entity: button.wiser_cancel_all_heating_overrides
tap_action:
  action: toggle
name: ’ Cancel All Overrides’

What else you’d need is an entity besides a button. A button in HA speach is something that has no state, it is just like these push-buttons in real world, that only react as long as you press them. In theory that button of yours should have something it changes, eg. a binary_sensor or starting a script.

If I understand correctly what you’re doing, I’d choose a script or an automation, that runs and disables your “heating overrides” (not sure what that is) when the custom:button-card is pressed. If you can elaborate a little more about what you want to achieve in the end (this is the point 8 thingy :rofl:), I’m sure there would be a nice and compact solution in button-card. :slight_smile:

in custom:button-card I believe you can toggle switch. or light. type entities. For button type use button.press or input_button use input_button.press
Ignore what this paddyguy said about his theory and his understanding @awallace89. I guess he really just wanted to harass you about code formatting.

I have posted your solution above.

Uh, one know-it-all. :wink: But have you really thought through what you’re saying? Or did you just didn’t know it better… :thinking:

Let’s see, maybe we can find some slow little examples, why you unwillingly proved my point for code formatting. :slight_smile: Thanks btw. :rofl:

I’ll take the example from above, should be easier for you to understand. If it’s still to fast, just say it, we’ll find a good example for you, too. If not, we’ll get some cookies for you. Just for you! :slight_smile:

So this is, how unformatted code looks like:
“show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: button.wiser_cancel_all_heating_overrides
name: ’ Cancel All Overrides’”

This is, how formatted code looks like:

show_name: true
show_icon: true
type: custom:button-card
tap_action:
  action: toggle
entity: button.wiser_cancel_all_heating_overrides
name: ’ Cancel All Overrides’

but it could be just this, as whitespaces are deleted without proper formatting

show_name: true
show_icon: true
type: custom:button-card
tap_action:
  action: toggle
  entity: button.wiser_cancel_all_heating_overrides
name: ’ Cancel All Overrides’

Can YOU spot the difference? Hint, it’s the entity and it’s indentation. Can mean totally different things. I know, hard to understand for you, that this could matter in a yaml file, but believe it or not, it does. :slight_smile:

Oh, and not to forget, the piece of code you posted, is not for the custom:button-card we’re talking about in this thread (and @awallace89 asked for twice), it’s for the HA default button-card. :rofl: :rofl: But hey, good choice, running around and telling people what their intentions are! :+1:

2 Likes

:-1:t4:

Sometimes I am missing the thumbs-down-button here.

3 Likes

Hi Shan can you please share the code for that 4 buttons from the top left?

afbeelding
Hi, I have made my own button card (on the right) but I would like to have a circle around my icon as well, if that is possible, but I can’t get it to work. Does anyone know how to do it?

          - type: 'custom:button-card'
            entity: light.woonkamerall
            icon: mdi:lightbulb-multiple
            color_type: icon 
            color: rgba(var(--color-yellow-text),1)
            name: Lampen
            layout: icon_name
            tap_action:
              action: navigate
              navigation_path: /ui-lovelace-minimalist/lampen
            styles:
              card:
                - height: 66px
              name:
                - font-weight: bold
                - font-size: 14px
                - align-self: middle
                - justify-self: start
                - padding-bottom: 0px

Is it possible to color button card based on applied aystem theme? I have my buttons colored black with white font, but on phone where I use light theme, I would like to switch that.
So for instance if I have light theme, display it white/black font for me, however at the same time, if my wife is using black theme, color them black.

try outline and outline-offset

styles:
  icon:
    - border-radius: 50%
    - outline: 2px soild red
    - outline-offset: 10px

I’m working on a little write up to share some other css that looks pretty cool in custom:button-card

You need to work with themes and the corresponding theme variables. :slight_smile:

You set a variable in the theme file and use that variable in your css code for the button. Then your color changes with the used or better selected theme. Take a look around in the theme you’re using.

Note: the selected theme is device, not user specific. :slight_smile:

I’m struggling to figure out how to approach this. Any and all advice would be greatly appreciated.

I have a handful of Wiz Bulbs, integrated through the recently added Wiz Integration. I’m looking to enhance the “color” on a button when one of the bulb effects is in use. The ‘auto’ color works great when the entity attribute [color_mode] either [color_temp] or [rgbw].

However, if I use one of the baked in effects, the entity attribute [color_mode] changes to [brightness], and the icon color defaults to the stock orange-ish color. I’d like to override this with an effect specific color somehow.

Can someone help me out? Have two grabs of the state attributes to show what I’m up against.

min_mireds: 153
max_mireds: 454
effect_list:
  - Ocean
  - Romance
  - Sunset
  - Party
  - Fireplace
  - Cozy
  - Forest
  - Pastel Colors
  - Wake up
  - Bedtime
  - Warm White
  - Daylight
  - Cool white
  - Night light
  - Focus
  - Relax
  - True colors
  - TV time
  - Plantgrowth
  - Spring
  - Summer
  - Fall
  - Deepdive
  - Jungle
  - Mojito
  - Club
  - Christmas
  - Halloween
  - Candlelight
  - Golden white
  - Pulse
  - Steampunk
  - Rhythm
supported_color_modes:
  - color_temp
  - rgbw
color_mode: color_temp
brightness: 128
friendly_name: Office02
supported_features: 4
hs_color:
  - 27.827
  - 13.281
rgb_color:
  - 255
  - 236
  - 221
xy_color:
  - 0.355
  - 0.343
color_temp: 183
min_mireds: 153
max_mireds: 454
effect_list:
  - Ocean
  - Romance
  - Sunset
  - Party
  - Fireplace
  - Cozy
  - Forest
  - Pastel Colors
  - Wake up
  - Bedtime
  - Warm White
  - Daylight
  - Cool white
  - Night light
  - Focus
  - Relax
  - True colors
  - TV time
  - Plantgrowth
  - Spring
  - Summer
  - Fall
  - Deepdive
  - Jungle
  - Mojito
  - Club
  - Christmas
  - Halloween
  - Candlelight
  - Golden white
  - Pulse
  - Steampunk
  - Rhythm
supported_color_modes:
  - color_temp
  - rgbw
color_mode: brightness
brightness: 128
friendly_name: Office02
supported_features: 4
effect: Romance

Hi Sel,

Sorry i add it to my config but still the same it don’t work… Any Idea?

Does anyone know if it is possible to set up an icon like a battery icon and change it by colour to the lowest percentage of a list of entities?

Example:
Battery state of the temperature sensor in the living room is 100%
Battery state of the temperature sensor in the sleeping room is 80%
Battery state of the temperature sensor in the office is 30%

Display the chosen colour for <40 on the icon, because the battery state of the office is the lowest.

What I have got now, and it works for 1 entity, but I want to add another 2 entities to the script.
That shows the lowest percentage as my example.

type: custom:button-card
icon: mdi:battery-outline
size: 80%
show_state: true
show_name: false
group_expand: true
entity: sensor.temperatuur_zolder_battery
styles:
  card:
    - height: 80px
    - width: 80px
state:
  - value: 10
    color: rgb(125, 128, 130)
    operator: <
  - value: 20
    operator: <
    color: rgb(15, 219, 22)
  - value: 30
    operator: <
    color: rgb(222, 209, 22)
  - value: 40
    operator: <
    color: rgb(237, 14, 37)

Think it would be possible if you can group these sensor entities but looking at the helper in HA it isn’t possible to group sensors?

If I use
entities:
instead of
entity:
It would not work.

@JasonVT, My initial thought is using the variables feature of the button card to specify your list of entities as an array variable, then in your state checks you use the scripting feature to get the min value of all the entities in the variable.

A different way to go that I find useful for myself is the battery state card. I have mine set up to be hidden unless batteries are below a specified minimum, and only those low batteries are shown. It also handles color gradients based on percentage of remaining battery.

I have also experimented with conditionally showing a small battery icon overlay on the same button card that I use to show/control the battery operated device. I use the custom_fields feature of the button card for the overlay. The nice thing about overlays is they can be clicked separately from the rest of the button to see the details of the battery.

Hi @electros, hear you go…

Button code when not selected

type: custom:button-card
color_type: card
color: black
name: Living Room
tap_action:
  action: navigate
  navigation_path: /tablet-livingroom/tablet-lr
styles:
  card:
    - height: 45px
    - box-shadow: 0px 0px 5px 4px gray
    - webkit-box-shadow: 0px 0px 50px 4px gray
  name:
    - text-transform: uppercase
    - letter-spacing: 0.2em
    - font-familly: cursive
    - justify-self: middle
    - align-self: middle
    - padding: 1px 1px
    - color: grey
  state:
    - justify-self: start
    - font-size: 2px
    - padding: 1px 1px

This is the code for highlighted buttons.

type: custom:button-card
color_type: card
color: grey
name: Main
tap_action:
  action: navigate
  navigation_path: /tablet-main/tablet-main
styles:
  card:
    - height: 45px
    - box-shadow: 0px 0px 5px 4px gray
    - webkit-box-shadow: 0px 0px 50px 4px gray
  name:
    - text-transform: uppercase
    - letter-spacing: 0.2em
    - font-familly: cursive
    - justify-self: middle
    - align-self: middle
    - padding: 1px 1px
    - color: black
  state:
    - justify-self: start
    - font-size: 2px
    - padding: 1px 1px

2 Likes

I have looked around, but I can’t seem to find an answer to my query - I suspect its simple, but I can’t work it out! I’m guessing its a case of using the button grid, but can’t seem to make it work.

I want to try and create a button that appears like the mock-up I’ve shown below. It would be for an electric car, and uses two sensors - one the battery percent, and the other the mileage range. (Be aware, I accidentally used the total car milage in my mock up, hence the mileage showing so high lol)

So ideally, i just want a button that allows a very quick glance at the range and battery… I plan to then look at changing the icon to orange when the battery goes below 25%. Though need to get the below sorted first.

Any thoughts? Thanks!

carstatus