šŸ”¹ Card-mod - Add css styles to any lovelace card

config.entity should never be wrapped in quotes.

Unfortunately, that didnā€™t work. If I remove the quotes around config.entity, it appears to remove all the remaining styling on the card.

Hereā€™s the full styling I tried:

style: |
  ha-card { 
    height: 100%; 
    font-size: 4em; 
    --primary-text-color: {% if is_state(config.entity+'_phone', 'on') %} red {% else %} green {% endif %};
  }

Removing the quotes makes the card look like this

When it should look like this

I guess I should also mention that this glance card is part of a larger grid layout card as well. Not sure if that makes a difference.

Hereā€™s my full card configuration:

- card:
    columns: 1
    show_header_toggle: true
    show_icon: false
    show_state: false
    style: |
      ha-card { 
        height: 100%; 
        font-size: 4em; 
        --primary-text-color: {% if is_state('config.entity' +'phone', 'on') %} red {% else %} green {% endif %};
      }
    type: glance
  filter: 
    exclude:
      - state: 'off'
      - state: unavailable
    include:
      - group: group.voice
    options:
      tap_action:
        action: toggle
  gridcol: 1
  gridrow: 2
  show_empty: true 
  sort:
    method: name
  type: 'custom:auto-entities'

well you still have it in quotes. And it may not work because thereā€™s no configured entity. Try it outside the auto-entities card first.

The glance card doesnā€™t have an entity. Youā€™ll have to set the style on each entity instead, using options: in the filter.

1 Like

Can someone please point out how to get this working with two functions.
If I only do it with ā€œā€“label-badge-background-colorā€ or "display: " it works, but not togheter(?)

views:
  - badges:
      - entity: sensor.weather_temp_reel_feel
        style: |
          :host {
            --label-badge-background-color:
              {% set  temp = states('sensor.weather_temp_reel_feel') | float %}
              {% if   temp <= -50 %} #0000AC
              {% elif temp <= -35 %} #000088
              {% elif temp <= -30 %} #0000A0
              {% elif temp <= -25 %} #0000B8  
              {% elif temp <= -20 %} #0000CF
              {% elif temp <= -15 %} #0000E7
              {% elif temp <= -10 %} #0000FF
              {% elif temp <=  -5 %} #3131FF
              {% elif temp <=  -3 %} #6262FF 
              {% elif temp <=  -1 %} #9393FF 
              {% elif temp <=   0 %} #C4C4FF
              {% elif temp <=   1 %} #F5F5FF
              {% elif temp <=   3 %} #FFFFD2
              {% elif temp <=   5 %} #FFFF7E
              {% endif %};
            display: 
              {% if states('sensor.weather_temp_reel_feel') | float > 5 %}
                none;
              {% endif %}
              }

UPDATE:
Had to do this:

            display: 
              {% set temp = states('sensor.weather_temp_reel_feel')|float %}
              {% if  temp > 4  %} 
                none;
              {% endif %}


on the picture-entity is it possible to change the font size?

      - type: custom:mod-card
        card: 
          type: horizontal-stack
          cards:
            - type: picture-entity
              image: /local/lampada_rgb_piloty.jpg
              entity: light.yeelight_color1_286c07ae4140       
              tap_action:
                action: toggle
              style: |
                ha-card {
                   background: rgba(0, 0, 0, 0.7);
                   border-radius: 25px;
                   border: solid 3px rgb(255,152,0);
                   width: 95%;
                   height: 100%;
            - type: picture-entity
              image: /local/barw.jpg
              entity: light.yeelight_strip1_286c078614cc   
              tap_action: 
                action: toggle
              style: |
                ha-card {
                   background: rgba(0, 0, 0, 0.7);
                   border-radius: 25px;
                   border: solid 3px rgb(255,152,0);
                   width: 95%;
                   height: 100%;
                }

add font-size: 90000px

he donā€™t change with this

Thatā€™s a typical case of advanced usage. Use your browsers inspector to find the DOM path, and step through it until you find the right place.

Hi @thomasloven,
I love this plugin, i use and abuse of it for months now, thanks !

One thing i would like to do is set a display:none to state-badge of various input_select, input_datetime or other input_* cards.

Below is a composed ā€œcardā€ for my adaptive target sensor/target temp scheduler NodeRed thermostat.
On mobile the 2 input_select donā€™t have enough space to be well displayed because of state-badges which are useless in my case.

Here is the best iā€™ve achieved with negative padding/margin ( :nauseated_face:) and iā€™ve been constraint to put input_ elements on the left of the card(absolutely not my preference):

Iā€™ve hardly tried to set display:none to state-badge(not just set empty icon) but iā€™ve never succeed in reaching it for input_ cards

Would you have any tips ?

Inputs arenā€™t cards, theyā€™re rows, so they donā€™t have a ha-card.
Card-mod can apply styles to them though, but only if they are in an entities card:

type: entities
entities:
  - entity: input_select.home_mode
    style: |
      state-badge{
        display: none;
      }

image
Outside of an entities card it depends on how you use it, but with mod-card it should be possible.

1 Like

Your example was exactly what i was using and didnā€™t worked on my system but your screenshot lead me look elsewhere and i quickly found the source of my issue:
I was using an obsolete version of card-mod not managed by Hacs(Arff)ā€¦ after updated it that works far better now !!
Many thanks @thomasloven !

@thomasloven

I am getting a lot of errors in my console many of which refer at the top level to card-mod.
Would you mind taking a look and telling me if you think they do relate to this card, if they are anything to worry about and if you have a suggestion to avoid them?

Thanks.


I believe youā€™re using fold-entity-row with style: set for either a header or some items. Could you please show me your configuration for that?

Indeed I am:

              #=== Schedule 2
              - type: custom:fold-entity-row
                head: 
                  type: custom:restriction-card
                  row: true
                  card:
                    entity: input_boolean.guest_mode_schedule_2
                  style: |
                    :host {
                      --restriction-regular-lock-color: red;
                    }
                entities:
                  - input_text.guest_mode_schedule_2_name
                  - input_select.guest_mode_schedule_2_day
                  - input_datetime.guest_mode_schedule_2_start_time
                  - input_number.guest_mode_schedule_2_duration

image

Please tell me, what am I doing wrong?
I needed to place (on a common card) horizontally 3 pictures of different sizes, 60% 20% 20% wide.
2020-02-23_143723
The code below results in a 100% CPU-load and inability to load HA-interface. Code that uses only ā€œ%%ā€ does not work:

- type: custom:mod-card
  style: |
        ha-card { background: white; }
  card:
    type: custom:layout-card
    layout: horizontal
    min_columns: 3
    column_width: [60%, 20%, 20%]
    cards:
      - type: picture
        image: /local/pic-1.png
        style: |
          ha-card { background-color: red; }
      - type: picture
        image: /local/pic-2.png
        style: |
          ha-card { background-color: green; }
      - type: picture
        image: /local/pic-3.png
        style: |
          ha-card { background-color: blue; }

And all the same, I achieved the correct result - everything began to work perfectly, as I need - I had to add an extra column of 1px, but I understand that this is not the correct code:

- type: custom:mod-card
  style: |
        ha-card { background: white; }
  card:
    type: custom:layout-card
    layout: horizontal
    min_columns: 4
    column_width: [59%, 20%, 20%, 1px]
    cards:
      - type: picture
        image: /local/pic-1.png
        style: |
          ha-card { background-color: red; }
      - type: picture
        image: /local/pic-2.png
        style: |
          ha-card { background-color: green; }
      - type: picture
        image: /local/pic-3.png
        style: |
          ha-card { background-color: blue; }

2020-02-23_143032

Is it possible to make a badge (or the badge icon) and a entity icon in a card to blink?
If so please, share the code.

Can I set an icon color template for a whole card based on a specific attribute? Iā€™m trying, but Iā€™m unsuccessful in combining the various examples, hereā€™s my failed attempt:

style: |
   :ha-card {
    --paper-item-icon-color:
      {% if state_attr(config.entity,'1 Dag') < 0 %}
        #ff0000
      {% else %}
        #00cc00
      {% endif %}
      ;
  }
entities:
  - entity: sensor.dnb_health_care_n
    secondary_info: '[[ {entity}.attributes.Dato ]], [[ {entity}.attributes.1 Dag ]]%'
    type: 'custom:secondaryinfo-entity-row'
  - entity: sensor.dnb_norge_indeks_a
    secondary_info: '[[ {entity}.attributes.Dato ]], [[ {entity}.attributes.1 Dag ]]%'
    type: 'custom:secondaryinfo-entity-row'
  - entity: sensor.dnb_teknologi_n
    secondary_info: '[[ {entity}.attributes.Dato ]], [[ {entity}.attributes.1 Dag ]]%'
    type: 'custom:secondaryinfo-entity-row'
show_header_toggle: false
title: Fond
type: entities

If possible, I would also like to apply the color to the state and/or the percent part of the secondary info line.

Maybe something like this?

style: |
         @keyframes blinker { 50% { opacity: 0; } }
         ha-card { animation: blinker 1s linear infinite; }

Tried your code, and the code in the documentation, without luck.