Lovelace: Button card

check here for an even niftier solution for the moon name (a mapper in javascript) :wink:

Ok thanks, but the icon itā€™s not a problem, my problem is about the template not working as i coded itā€¦

your code is using the format using a decluttering-template with variables in [].

see GitHub - custom-cards/decluttering-card: šŸ§¹ Declutter your lovelace configuration with the help of this card for documentation on that card.
You should post that decluttering template for us to be able to check why it doesnā€™t work (what does that actually mean, do you get errors, do you get a button at all etc etc)

if you donā€™t have a decluttering template, the code unposted will never work, and you should write a full button card config first to see what you want.

since youā€™re new to HA, you better start getting a more fundamental understanding of the inner workings, before using something as complex, and simply copying other configs, or parts of it. It wont work like that

Hmmmā€¦ i donā€™t have a decluttering template and the full button card config is what i posted in my last message. Or am i wrong? I have others configuration templates without the [[ ]] variables, so i tried to learn putting those variables but at the actual state i am wrong.
Is it possible to have a config template for that button-card without the [[ ]] variables?

yes, read the docs at: button-card/README.md at master Ā· custom-cards/button-card Ā· GitHub

and then try:

                  - type: custom:button-card
                    name: Ciabatta 1
                    entity: switch.ciabatta1
                    icon: mdi:power-socket-eu
                    tap_action:
                      action: toggle
                    styles:
                      card:
                        - font-weight: bold
                        - font-size: 13px
                        - font-family: 'Times New Roman'
                      icon:
                        - color: >
                            [[[
                              if (entity.state == 'on') return "red";
                              return "green";
                            ]]]

Maybe i am not so clear, but i already coded some configuration templates and all are working as i expected.
Now i am having troubles as never did a config template with a toggle action and with an entity_id inside it. I have many button-card like that i posted, so i was thinking to create a config template to use with those card to avoid to repeat every code inside every card like i did with other card but without toggle actionsā€¦ Hope to be more clear now about what i would like to haveā€¦

you donā€™t need that if using a switch and toggling that. See my post above. In fact, you dont even need to define the tap-action since toggle is default for entities in these domains

Ok, so for every similar card i must put the same in every card? Is there a way/option to create something inside button_card_templates to avoid to repeat the same in every card?

For example i have this template:

  mio_header:
    color_type: label-card
    color: rgb(44, 109, 214)
    styles:
      name:
        - font-size: 14px
        - font-weight: bold
        - font-family: 'Times New Roman'
        - color: white

And i use this for every similar card:

              - type: "custom:button-card"
                template: mio_header
                name: Salotto Yeelight

Is it possible with that card?

if you want something like this:

      - type: custom:button-card
        template: switch_regular
        entity: switch.sw_tv_auditorium_template
        name: Tv Aud.

you define a button-template (named ā€˜switch-regularā€™ here) like this:

switch_regular:
  label: >
    [[[
    var id = entity.entity_id.split('.')[1].slice(3, -9);
    return states['sensor.' + id + '_actueel'].state + ' Watt';
    ]]]
  template: button_body_alt

which uses yet another template button_body_alt

button_body_alt:
  color: auto
  size: 30%
  aspect_ratio: 1/1
  show_state: true
  show_label: true
  tap_action:
    action: toggle
    haptic: light
  hold_action:
    action: more-info
    haptic: success
  styles:
    lock:
      - color: red
    card:
      - border-radius: 6px
      - padding-left: 5px
      - box-shadow: '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)'
    name:
      - justify-self: start
      - font-weight: bold
      - font-family: Helvetica 
      - font-size: 13px

      - text-overflow: unset
      - white-space: unset
      - word-break: break-word

      - text-align: start
    label:
      - font-size: 11px
      - font-family: Helvetica
      - justify-self: start
    state:
      - font-size: 11px
      - font-family: Helvetica
      - justify-self: start
      - text-transform: capitalize
      - font-weight: bold
    grid:
      - grid-template-areas: '"i" "n" "s" "l"'
      - grid-template-columns: 1fr
      - grid-template-rows: 1fr min-content min-content
    img_cell:
      - justify-content: start
      - align-items: start
  state:
    - value: 'on'
      styles:
        card:
#          - box-shadow: '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)'
#          - box-shadow: 0px 0px 2px 1px rgb(85, 91, 101)
#          - box-shadow: 0px 0px 2px 1px var(--paper-item-icon-active-color)
          - background-color: '#F0C209'
        name:
          - color: '#555B65'
        state:
          - color: gray
        label:
          - color: red
        icon:
          - color: '#555B65'
      id: on-icon
    - value: 'off'
      styles:
        card:
          - color: '#F0C209'
          - background-color: '#555B65'
#          - box-shadow: 0px 0px 2px 1px
        label:
          - color: rgba(0, 0, 0, 0.0)
        icon:
          - color: '#F0C209'
      id: off-icon
    - value: 'unavailable'
      styles:
        card:
          - opacity: 0.6
          - color: grey
          - --paper-item-icon-color: grey
        label:
          - color: rgba(0, 0, 0, 0.0)

you then can reference this method on all switches you like to have that config for.

1 Like

Yes, ok thatā€™s what i wanted since the beginning of our conversationā€¦ Now iā€™ll study your config and make for my neededā€¦ thanks again for your support!

Can you explain me what the switch_regular template does? It shows the label of the card, but cannot understand how the var works hereā€¦

I have my switches and sensor named according to strict guidelines, to be able to manipulate their idā€™s in templates like this. In the config, you should probably not use the first template, but change that into the second. I showed it here, to explain how these templates can be inherited.

it automatically creates the name of the sensor that is relevant for the switch.

to set the var id
it takes the entity_id of a switch: ā€˜switch.sw_tv_auditorium_templateā€™,
splits it at the ā€˜.ā€™ and takes the right part of it ā€˜[1]ā€™: sw_tv_auditorium_templateā€™,
and then slices from the 4th character on the left ā€˜[3]ā€™: ā€˜tv_auditorium_templateā€™
to the 9nth from the right ā€˜[-9]ā€™ : ā€˜tv_auditoriumā€™

this var id is then injected in to the return template states['sensor.' + id + '_actueel'].state to result in states['sensor.tv_auditorium_actueel'].state which is the corresponding sensor to read the state and display in the buttonā€¦

1 Like

HI, silly me, Ive only now discovered the confirmation: optionā€¦ is this still alive?
because when I try this:

      - type: custom:button-card
        template: switch_regular
        entity: switch.sw_audio_auditorium_template
        name: Audio Aud.
        lock: true
        confirmation: 'Sure to toggle? If not do nothing.'

No popup or confirmation box, on either platform or device.
26

Just the lock opening up for a few seconds and than closing again.

I tried this just now and in my environment it works. At the first press the lock disappear, then pressing again i get the confirmation box

A I see, I had to press once more. Got it working yes, very nice.

But, and @RomRider might be asked already, can we template this confirmation field too?:

        confirmation: >
          [[[return 'Sure to toggle ' + entity.name + '? If not do nothing.']]]

Answer for now is no, but maybe this could be added?
Please have a look, thanks!

Not yet, feature requests on github please :slight_smile:

will do done, thanks for no declining :wink:

You make me sound like a tyrant who never accepts feature request :stuck_out_tongue_closed_eyes:

haha, no way, wouldnā€™t dareā€¦

this is a nice 1 though isnā€™t it, would make it a cool feature indeed, especially using config templates.

Hi all, I have asked this in other posts but I thought may be it would be possible to use here.

I use Jupyter notebook to scrape a web page.
Using DataFrame

import pandas as pd
d = pd.read_html(ā€˜https://www.clevelandbrowns.com/team/standings/ā€™, index_col=0)
df = d[0]
df

I can save this file using a few different options.

So my question could the output of the notebook be displayed using a template on this card? If this is a stupid question Iā€™m sorry, Iā€™m just trying to figure out how to use the information somehow in one of my views.

Thanks!