Lovelace: Button card

You will have to use the layout-card to set the width of other cards than button-card. It’s not something possible without.

Eg:

- type: custom:layout-card
  layout: grid
  gridrows: auto
  gridcols: auto 20% auto

just a small note - I looked into it and !include is not a YAML feature, it’s done by a parser.

we use the python parser called yaml. It’s standard in it. Do you really need to nitpick that much?

I presume that for people who don’t know why you need a dash in raw editor and don’t need it in UI editor yaml and YAML are the same (and it is confusing in a way).
There was nothing I’d call ‘nitpicking’ in my message but I got your message.

If you simply search for yaml includes you’ll get all resources for pythons yaml parser and it’s abilities, so I really don’t see why it even needs to be said. Most users here who don’t understand it won’t even venture outside the home assistant site and home assistant youtube videos. 100% nitpicking. It’s like you just want to correct something for nothing. It offers no help towards the person asking the original question.

is it possible without the use of another template sensor, that a button represents the on/off (button pressed or not) based on a entity attributes? i have an entity called remote.harmony …
that harmony has 4 activities, like (plex,netflix,tv,radio), thats an attribute of remote.harmony => attr = current_activity
so i have also 4 buttons, based on the current_acitivity , i want the button have the pressed state

ty

it’s a pain in the ass. Not worth the effort but it is doable. It requires templates across the board. I have a few in my configuration that do this.

Can you post some examples? I have only 4 activitys, so I can ditch my sensors maybe :wink:

I don’t have any that will satisfy your needs. The closest I have is this

even then, it won’t do what you want, which is style based on a state attribute.

Ok , I’ll have a look, thnx for info

Thanks but that’s not helping me at all. What I would like to know is how to integrate this data in a button card. Here is my attempt which doesn’t work.


        - type: 'custom:button-card'
          aspect_ratio: 1/1
            icon: 'mdi:home-account'
            name: ACCUEIL
            show_name: true
            size: 30px
            state:
                  - styles:
                      icon:
                        - color: '#4284f4'
                    window.location: '/lovelace/general'
            styles:
              name:
                - font-size: 14px
                - font-weight: bold
                - padding: 0px 0px 10px 0px
            tap_action:
              action: navigate
              navigation_path: /lovelace/general

window.location is a js object, only accessible in the templates.

You’d have to make a color: template that checks the window.location based on an input that you set in variables.

By the way, you’ll never see those buttons light up unless they are on every page. Because once you navigate to the new page, you can’t see the page where it’s supposed to light up.

Thanks. They are already on every page. I will look into templates then.

          - type: 'custom:button-card'
            aspect_ratio: 1/1
            icon: 'mdi:home-account'
            name: ACCUEIL
            show_name: true
            size: 30px
            color: >
              [[[
                var my_array = window.location.href.split('/');
                var location = my_array[my_array.length-1];
                if (location === 'general')
                  return '#4284f4';
                else
                  return 'var(--paper-item-icon-color)';
              ]]]
            styles:
              name:
                - font-size: 14px
                - font-weight: bold
                - padding: 0px 0px 10px 0px
            tap_action:
              action: navigate
              navigation_path: /lovelace/general

Thanks for the help, but no luck…I tried fooling around by putting [2] after the slash or even added /lovelace/general. No dice. If you have other ideas, they are more than welcome!

is there a way to automaticly use an entity-icon on button-card? something like icon: {entity} ?

Don’t fill in the field and it will use the entities icon.

so instead of

icon: blah

you have

I am Quite happy with how this turned out, I thought I would share.

4 Likes

looks nice.
as some suggested, if you have a Github account - publish your config with come notes and screenshots there and link from this post to make it perfect :wink:

don’t you want to show something like “home”/“away” instead of “Nathan: On”? :wink:
And maybe it’s reasonable to display time only if your washer/dryer is running as otherwise it’s a bit useless and confusing (imho).