đŸ”č Card-mod - Add css styles to any lovelace card

The glance card has no entity property. The things in the glance card do, though. Try applying the styles to them instead.

Awesome - thanks Thomas. CSS is weird


OK - I think I see what you mean - I think I’ve misunderstood the use of config.entity.

I had hoped it would allow me to set some dynamic CSS (eg set colour based on temperature) at the card level, which would be applied to each entity in turn at render time. But I think you are saying that I must do this at the entity level, which means reentering the same dynamic CSS code for each entity. A little verbose, but I guess it gets the job done.

You can avoid a lot of copy pasting with node anchors.

2 Likes

Ah Thomas - you’re a legend and a gentleman. Thanks - node anchors work beautifully.

Hi Thomas,

Since HA 110 changes the way it handles icons, the ‘old’ custom-ui way of customizing icon_color doesnt work anymore. Which is a major bummer, since custom-ui was able to customize entities globally, and every where in HA these entities are displayed with their customizations. Any card, be it custom or core, and, importantly, in the more-info.

Did file a feature request to please add a new way of customizing entities in Ha core Frontend, but that will be a long shot I fear.

So, trying my best to customize icons with what’s available right now, and using your card-mod Style of course. But, that only styles the entities in a Lovelace card, and not their more-info, as the quote above already indicates.

I’ve managed to template the icon color in an auto-entities card and would really have that functionality used in more-info. Which, without the color, in fact will be a Less-info from Ha 110 onward


Since your answer above was a long time ago (talking Ha development time), I was wondering if you know of a way yet to globally customize items, so the more-info on the entity is also customized?

If not, could you give me a pointer what to look for in the ‘old’ custom-ui, and what has been changed in the 110 HA icon handling, so I can try to adapt that script to that? I haven’t been able to find that in the GitHub.
thanks for having a look.

I would like to be able to move the card title up slightly to match my card backgrounds:

Screenshot_2020-05-19 Overview - Home Assistant

I’ve found the right element using the browser inspector but am having trouble translating this to card-mod css:

div

I’ve tried both inside and outside ha-card:

style: |
  ha-card {
    card-header {
      padding-top: 8px;
      padding-bottom: 36px;
    };
    border: solid 1px var(--primary-color);
    background: 
      {% if is_state('input_select.select_theme', 'Night') %}
        url('/local/background/card_bg_night.png');
      {% else %}
        url('/local/background/card_bg_day.png');
      {% endif %}  
  }

Any hints?

have you tried a dot, period, full-stop, whatever in front of card-header?

I have now. It made no difference unfortunately.

Is this any good?

style:
  .: |
    ha-card {
      border: solid 1px var(--primary-color);
      background: 
        {% if is_state('input_select.select_theme', 'Night') %}
          url('/local/background/card_bg_night.png');
        {% else %}
          url('/local/background/card_bg_day.png');
        {% endif %}  
    }
    ha-card div.card-header {
      padding-top: 8px;
      padding-bottom: 36px;
    }
1 Like

Yep that did it. Thank you. I changed my file names to make it a little simpler as per Mariusthvdb’s advice in another topic.

style:
  .: |
    ha-card {
      border: solid 1px var(--primary-color);
      background: url("/local/background/card_bg_{{states('input_select.select_theme')}}.png");
    }
    ha-card div.card-header {
      padding-top: 8px;
      padding-bottom: 36px;
    }

Now I just have to apply it to literally hundreds of cards


Great! I think I’m nicking your idea of changing the background like this


1 Like

you’re not alone, I am faced with a burden alike, while things could be so much simpler. Were simpler even

EDIT: just to keep things tidy: my issue above has been resolved


on your repetitive job: isn’t a yaml anchor an option for you?

To be honest I’ve never bothered with anchors.

VSCode multi-line find and replace is making short work of it. I just have to be careful when some cards are indented more than others due to being in a stack.

Hi
“config.entity” NOT works with Entities Card, the unique that I am been able to works is using specific entity, any ideas why “config.entity” is not working with my code?. I have a similar but with Glance Card and all is working fine

  • type: entities
    show_header_toggle: false
    entities:
    - entity: input_boolean.riego_frente_auto
    - entity: input_boolean.riego_jardin_auto
    - entity: input_boolean.riego_recordatorio_orquidea
    style: |
    :host {
    –paper-item-icon-color:
    {% if is_state(‘config.entity’, ‘on’) %}
    red
    {% else %}
    blue
    {% endif %}
    ;
    }

There is no entity in the configuration of the entities card. Try adding the style to the entities instead of the card itself. There’s an example in the readme.

1 Like

Thanks for that information, now I can continue.

If I have the following code the bg color gets set:

entities:
  - entity: sensor.upper_freezer_temp
    color: blue
style: |
  ha-card {
    background-color: #0000ee
    }
font_size: 75
line_color: var(--accent-color)
line_width: 8
type: 'custom:mini-graph-card'

If I change it to the following it doesn’t work

entities:
  - entity: sensor.upper_freezer_temp
    color: blue
style: |
  ha-card {
    background-color: states('sensor.maintank_color')
    }
font_size: 75
line_color: var(--accent-color)
line_width: 8
type: 'custom:mini-graph-card'

sensor.maintank_color is an mqtt sensor whose values are colors in hex format including the #. If I look at the state of sensor.maintank_color using the developer tools the state is #0000ee. Is there any reason this shouldn’t work?

You need to enclose templates in “{{ }}”

background-color: "{{ states('sensor.maintank_color') }}"

Thank you. I don’t know if it’s a byproduct of using the Configure UI editor, but I had to omit the ".
So it literally looks like:

background-color: {{ states('sensor.maintank_color') }}