Lovelace: Button card

To come back to this question: For me it seems not different, sorry. In both pictures the centered “icon” is not centered. In your phone picture it isn’t that much, because the width in total is far less, but it isn’t centered. :wink:

And to the centered position in general: You set a position for the first “button” from the left, the second as well, and the third one comes from the right. This will never work as intended.

You should let the browser take care of positioning, and use eg. the grid template in button-card. And to sum it up, aspect_ratio is never a good idea in button-card, if you want to place things exactly.

See here, the width of the pic is exactly 400px in my display, 200px are just slightly off center:
ha_button_card_center_01

Yeah, install the extension named “Better Jinja” and then change the language type to Jinja YAML

thanx. modified code, but it doesnt work. pls advise

                [[[
                 var hour = new Date().getHours();
                 var h = hour.toString().padStart(2, "0"); // current hour in format 08, 09, 10, 11
                 if (states['binary_sensor.kute_tana_' + h] == hour) return 'yellow';
                ]]]

Ok thanks.
if you can, would you correct the code for me?
show me how you would do it…
the three icons in a grid, for the central icon I need the button card though.
then vertical stack?

why not try to learn for yourself from the docs. There’s graphics specifically made for this:

Guys, I need your help please. Is it possible to show an icon for a light at the right top corner? I use the button-card to show the state of a binary_sensor. I would like to have another icon in the same card, that shows the state of a light entity with an icon.

This is my code so far:

aspect_ratio: 1/1
color: rgb(150, 150, 150)
entity: binary_sensor.tuerankleide
tap_action:
  action: call-service
  service: light.toggle
  service_data:
    entity_id: light.ankleide
name: Ankleide
state:
  - color: var(--disabled-text-color)
    value: 'off'
  - color: rgb(253, 216, 53)
    value: 'on'
type: custom:button-card

This is my card:
image

Hi,

use this:

{{ now().hour }}

        [[[
        var hour = now().hour;
        var h = hour.toString().padStart(2, "0"); // current hour in format 08, 09, 10, 11
        if (states['binary_sensor.kute_tana_' + h] == hour) return 'yellow';
        ]]]

this gave me error: ButtonCardJSTemplateError: ReferenceError: now is not defined in ‘var hour = now().hour; var h = hour.toString().padStart(2, “0”); // current hour in format 08, 09,…’

when im was using version i wrote earlier there was no errors but also no results.

-The method “tostring” is not known in jinja
-only lower letters are allowed in yaml and jinja
-you can simply combine values in jinja like

{% set hour = now().timestamp() |timestamp_custom("%H") %}
media_player.{{ hour}}

This provides a always leading zero
if you cannot do that directly in the buttom card, simply create a new binary sensor which provides the value you ask for.

his template isn’t jinja, it’s javascript, meaning everything in the template editor is the wrong template language. There is no tester for javascript btw, so you have to use online resources like https://playcode.io but you can’t use any of the built in variables and you have to print out your values with console.log()

Your previous template was fine accept you didn’t provide an else, which is most likely your problem.

              [[[
                 var hour = new Date().getHours();
                 var h = hour.toString().padStart(2, "0"); // current hour in format 08, 09, 10, 11
                 return (states['binary_sensor.kute_tana_' + h] == hour) ? 'yellow' : 'blue';
              ]]]

If you don’t wnat to use the 1 line JS template…

              [[[
                 var hour = new Date().getHours();
                 var h = hour.toString().padStart(2, "0"); // current hour in format 08, 09, 10, 11
                 if (states['binary_sensor.kute_tana_' + h] == hour)
                   return 'yellow';
                 else
                   return 'blue';
              ]]]

I’m sorry, but I don’t have the time right now, as I’m working hard on getting the “Minimalist theme” out in the open (first public beta today or tomorrow). :smiley: :+1:

But I can give you an example out of that “theme”, that shows exactly, what you want to achieve. See the code underneath, it should get you started. :wink:

custom_card_tpx01_aircondition_with_buttons:
  variables:
    name: null
  styles:
    grid:
      - grid-template-areas: '"item1" "item2"'
      - grid-template-columns: 1fr
      - grid-template-rows: min-content  min-content
      - row-gap: 12px
    card:
      - border-radius: var(--border-radius)
      - box-shadow: var(--box-shadow)
      - padding: 12px
  custom_fields:
    item1:
      card:
        type: custom:button-card
        template: list_items_favorite
        custom_fields:
          item1:
            card:
              type: 'custom:button-card'
              template:
                - icon_info
                - custom_card_tpx01_aircondition
              tap_action:
                action: more-info
              name: >
                [[[
                    if (variables.name == null) {
                      return variables.entity;
                    }
                    return variables.name;
                ]]]
              entity: '[[[ return variables.entity ]]]'
          item2:
            card:
              type: horizontal-stack
              cards:
                - type: conditional
                  conditions:
                    - entity: '[[[ return variables.entity ]]]'
                      state: 'off'
                  card:
                    type: custom:button-card
                    template: widget_icon
                    tap_action:
                      action: call-service
                      service: climate.set_hvac_mode
                      service_data:
                        entity_id: '[[[ return variables.entity ]]]'
                        hvac_mode: 'cool'
                    icon: mdi:power
                - type: conditional
                  conditions:
                    - entity: '[[[ return variables.entity ]]]'
                      state_not: 'off'
                  card:
                    type: custom:button-card
                    template: widget_icon
                    tap_action:
                      action: call-service
                      service: climate.set_hvac_mode
                      service_data:
                        entity_id: '[[[ return variables.entity ]]]'
                        hvac_mode: 'off'
                    icon: mdi:power-off
    item2:
      card:
        type: 'custom:button-card'
        template: list_items
        custom_fields:
          item1:
            card:
              type: 'custom:button-card'
              template: widget_icon
              tap_action:
                action: call-service
                service: script.decrease_climate_temperature
                service_data:
                  entity_id: '[[[ return variables.entity ]]]'
              icon: 'mdi:minus'
          item2:
            card:
              type: 'custom:button-card'
              template: widget_temperature
              tap_action:
                action: none
              entity: '[[[ return variables.entity ]]]'
              icon: 'mdi:temperature-celsius'
          item3:
            card:
              type: 'custom:button-card'
              template: widget_icon
              tap_action:
                action: call-service
                service: script.increment_climate_temperature
                service_data:
                  entity_id: '[[[ return variables.entity ]]]'
              icon: 'mdi:plus'

This is the code of a three button-card, it looks like this:
ha_minimalist_aircon_01

In the second line of that card you see three buttons next to each other. This is where you want to look at the code (same as above, here starts the “magic”):

    item2:
      card:
        type: 'custom:button-card'
        template: list_items
        custom_fields:
          item1:
            card:
              type: 'custom:button-card'
              template: widget_icon
              tap_action:
                action: call-service
                service: script.decrease_climate_temperature
                service_data:
                  entity_id: '[[[ return variables.entity ]]]'
              icon: 'mdi:minus'

And to position all of this (the three buttons), the template list_icon:

list_items:
  styles:
    grid:
      - grid-template-areas: '"item1 item2 item3"'
      - grid-template-columns: 1fr 1fr 1fr
      - grid-template-rows: min-content
      - column-gap: 7px
    card:
      - box-shadow: none
      - padding: 0px

The essence is: you can use as many custom_fields as you want, nested into each other. And you can simply use a horizontal-stack inside these custom_fields. :wink:

Well, i think you are trying to help… thank you for that.
But tbh i have no clue about css styling and tried to understand the docs without succes.

If you could give me one example for my problem i would try to play with it and learn…

thanx man. its sort of work now. i see blue now and its still dont check what hour we have, color stays blue whatever sensor name i write there. pls advise.

It won’t update per hour, if you want to it to update per hour, you need to add a entity to triggers update

Look just in the post above yours. That is an example, of what you want to achieve. It uses custom_fields to place the items and much more.

The problem is, the example in the documentation of button-card is exactly what one wants to see as an example. Nevertheless it is complicated stuff, and without understanding these basics, it won’t get you far. Believe me, I know what I’m talking about, I sat hours and read it over and over…

Sorry, can’t tell you something better. :slight_smile:

thank you. sorry, but… how?

https://github.com/custom-cards/button-card#triggers_update

Hi, I’m sorry but I am unable to use your method.
I tried to do it like this:

type: grid
cards:
  - type: custom:stack-in-card
    mode: vertical
    cards:
      - type: custom:stack-in-card
        mode: horizontal
        cards:
          - type: button
            tap_action:
              action: toggle
            entity: switch.riscaldamento_00_off
            name: Spegni
            icon: hass:power
          - type: custom:button-card
            name: CALDAIA
            styles:
              card:
                - font-size: 10px
              icon: null
              name:
                - font-weight: bold
                - font-size: 17px
                - line-height: 28px
            entity: sensor.stato_riscaldamento
            color: rgb(128, 128, 128)
            state:
              - value: IN FUNZIONE
                color: rgb(255, 0, 0)
            show_state: true
            show_name: true
            show_label: true
            style: |
              ha-card {
              box-shadow: none;
          - type: button
            tap_action:
              action: toggle
            entity: switch.riscaldamento_20_on
            name: 20° / ON
            icon: hass:fire
        style: |
          ha-card {
          box-shadow: none;       
      - type: custom:button-card
        aspect_ratio: 1/1
        styles:
          card:
            - font-size: 100%
          name:
            - font-weight: bold
            - font-size: 18px
            - align-self: middle
            - justify-self: center
          img_cell:
            - justify-content: center
            - align-items: center
          custom_fields:
            thermo:
              - position: absolute
              - width: 100%
        custom_fields:
          thermo:
            card:
              type: custom:thermostat-card
              title: Thermo
              entity: climate.termostato
              no_card: false
              step: 1
              style: |
                ha-card {
                box-shadow: none;
columns: 1
square: true

Now I have fewer problems, but I have only one problem:
the lower edge of a pc is different than a smartphone …

PC
pc

smartphone

I don’t understand where the mistake is …