Lovelace: Button card

I like this new top bar colour too!
image

5 Likes

I tried it with:

  opacity-on: rgba(var(--background-color-on),0.8)
  opacity-off: rgba(var(--background-color-off),0.8)

in my theme, and

    state:
      - value: 'on'
        id: state-on
        styles:
          card:
            - background-color: var(--opacity-on)
      - value: 'off'
        id: state-off
        styles:
          card:
            - background-color: var(--opacity-off)

is that what you suggest?
even tried the main variables in the theme:

  opacity-on: rgba(var(--primary-color),0.8)
  opacity-off: rgba(var(--card-background-color),0.8)

Hi!
One day i saw ā€œbutton card template is missingā€ and noticed that code in lovelace dashboards for button_card_templates disappeared and YAML starts with

title: Home
views:

I had a backup, so I restored it, but it disappeared again and again after approx one hour. I canā€™t see anything in logs (I have an error log level). How can I define button_card_templates in Lovelace dashboards?

now my dashboard looks like this
please help

small update:

using theme variables with:

  opacity-on: rgba(255,100,100,0.8)
  opacity-off: rgba(100,255,255,0.8)

works fine, proving the variable is at least set correctly and merged using the id: in the button templates.

probably should conclude (again, or, after all) that using a color variable in the rgba(), simply isnā€™t allowed?

It is allowed if the css variable is defined as name: 123, 123, 123 which I forgot to mention in my initial message :blush:

Your button-card templates are missing from your lovelace config

Now you lost meā€¦ really sorry but I donā€™t understand what to do.

In my theme I am merely following the main variables primary-color and card-background-color, so no where do I set the rgb numbers myself.

I canā€™t either, because there are several themes used, all with their own coloring set.

Please give it one more thought how I could use these ā€˜namedā€™ variables with the opacity?

Look, just do what works for you, thereā€™s no one size fits all way to tackle problems in the web world. :slight_smile:
In your post above you had something which worked for you, just use that.

well, thats just it, I havenā€™t found a way to use opacity on a named variable, but Iā€™ll take it elsewhere, thanks for the support and suggestions!

for reference: I also tried, as a final option, to have the main theme colors like primary-color: set with rgb values (mine were set in hex) so to follow your last suggestion to the letter. unfortunately that doesnt help either. so for now: I havenā€™t found a way to use a color variable name in the rgba() construct to have it use an opacity.

To recap:

  1. In your theme: my-color: 123, 123, 123. Note this is not a color, itā€™s just 3 numbers separated by a coma.
    Use it like this: color: rgba(var(--my-color), 0.5)
  2. In your theme: my-color: rgba(123, 123, 123, 0.5)
    Use it like this: color: var(--my-color)

Thatā€™s the 2 options. Itā€™s not possible to re-use an existing color css variable youā€™ll have to to duplicate it.

1 Like

great idea, and now I see what you said before.

copied the colors of primary-color in to a new primary variable name:

  # Main colors
  primary-color: '#1675C9'                                            # Header
  primary: 22, 117, 201

and use it like:

            card:
              - background-color: rgba(var(--primary),0.8)

or as an intermediary theme color:

  opacity-on: rgba(var(--primary),0.8)

used as

          card:
            - background-color: var(--opacity-on))

unfortunately no such luckā€¦

Edit:
Of course I need to select the themeā€¦. Duh
Success! Thanks!

please read my first message in the topic!

Are you using lovelace YAML mode? If not, you might be using some custom views which rewrites the dashboard. If so it seems to be an issue with that other custom resource.

Just testing the triggers_update but itā€™s not working for me. The card is only updated by the entity but not form the triggers_update entity. Is there anything iā€™m doing wrong?

type: custom:button-card
entity: binary_sensor.voordeur
triggers_update:
  - binary_sensor.achterdeur

triggers_update updates the card (which is useful if you have javascript templates) but the card doesnā€™t reflect the state of what is defined in triggers_update if thatā€™s your intent.

Can I use an if statement to set the ā€œtopā€ and ā€œleftā€ styles? I cannot get this to workā€¦

          - type: 'custom:button-card'
            entity: input_select.page
            style:
              top: >
                [[[
                  if (entity.state == 'Lighting') return '215px';
                  if (entity.state == 'Home') return '175px';
                  else return '500px';
                ]]]
              left: >
               [[[
                if (entity.state == 'Lighting') return '270px';
                if (entity.state == 'Home') return '175px';
                else return '500px';
               ]]]

style is part of card-mod, it doesnā€™t support javascript templates but I believe you can use jinja2 templates with card-mod.

I thought so, but I was told otherwiseā€¦ Card-Mod Post

Iā€™ve tried the jinja2 templates also without success

              top: > 
                {% if is_state('input_select.tablet_page','Lighting') %} 
                  215px 
                {% else %} 
                  500px
                {% endif %}

I see, this is for a picture element I guess.
The format is not correct, it should be something like:

card_mod:
  style: |
    :host {
      top: jinja here;
      left: jinja here;
    }