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

Can you not get it to change color at all, or just not make the color state dependent?

i can change icon color. Just unable to change color based on state dependency

Since you are inside a | block, the # will not be treated as a comment by the yaml parser. Remove the line instead.

Are you sure your script changes state? I think it must contain a delay to ever be “on”.

I all else fails, add a space between ) and ]].

Oh, and use the browser object-inspector to see that the injected code is actually what you expect.

removed the # and added spaces but no luck

I’m using rounded corners on my cards, but on the custom banner-card i had to enable “overflow: hidden” to stop a greyed overlap in the bottom corners.
This seems to have stopped working since upgrading to version 4, has the method for this altered?

Hi All, Anyone have any idea how to turn custom:mini-graph-card background to transparent ?

Tried all kind of possibility but still can’t get it work. any help will be appreciate. thanks

Tried this code also not working. With this code the background color not even change. I just wanted to turn it into transparent. :grin:

style: |
  ha-card {
    ha-card-background: rgba(150, 150, 150, 0.1)
  }

- type: entities
  style:
    .: |
      ha-card {
        --ha-card-box-shadow: none;
        background-color: transparent;
      }
    "#states > div > mini-graph-card":
      $: |
        ha-card {
          background-color: transparent;
        }
  entities:
    - type: custom:mini-graph-card
      entities:
        - sensor.power_total
      hours_to_show: 48
      points_per_hour: 1
      more_info: false
      hour24: true
      align_state: center
      height: 110
      line_color: var(--google-red-500)
      line_width: 6
      font_size: 120
      show:
        graph: bar
        name: false
        icon: false
        extrema: true
        labels: false

1 Like

oh man thank you very much !!! But i have a problem still can’t figure it out. custome card is inside a card, can i make it the same size instead have an outer space ? And how to remove the round edge i try this but doesn’t work

type: entities
style:
  .: |
    ha-card {
      --ha-card-box-shadow: none;
      background-color: transparent;
      border-radius: none;

    }
  '#states > div > mini-graph-card':
    $: |
      ha-card {
        background-color: transparent;
      }
entities:
  - type: 'custom:mini-graph-card'
    entities:
      - sensor.u_s_air_quality_index
    hours_to_show: 48
    more_info: false
    hour24: true
    align_state: center
    height: 110
    color_thresholds:
      - value: 10
        color: green
      - value: 60
        color: yellow
      - value: 100
        color: orange
    line_width: 8
    font_size: 120
    show:
      graph: bar
      name: false
      icon: true
      extrema: true
      labels: false

image

1 Like

@d3vilsim, try it

- type: entities
  style:
    .: |
      ha-card {
        background-color: transparent;
        margin: 0px -16px -32px -16px;
      }
    "#states > div > mini-graph-card":
      $: |
        ha-card {
          border-radius: none;
          --ha-card-box-shadow: none;
          background-color: transparent;
          margin: 0px 0px 0px 0px;
        }
  entities:
    - type: custom:mini-graph-card
      entities:

Tell me, does this card-mod only work in YAML lovelace mode?
Will the code work through a raw editor?

It will work in any mode. But using it will make you unable to use the gui editors. Any card containing style: will only be editable as yaml in the editor.

Hi,

I’m trying to build something that looks like a “second row slider” by using a default entity row and a slider-entity-row below of it in full_row mode.

To get the look in the screenshot, I need to set a negative top-margin on the device name in the default entitiy row.
I also need to set a negative top-margin to the slider-entity-row to move it up and a left and right margin to move it away from the icon and the switch.

I already have both styles for card-mod running, but I can’t get them running at the same time.
If I add only one of the styles, this one is working fine.
But if I add both, only one is working.

Is ist because both styles are starting at “#states div”?

Any suggestions how to get this fixed?

- type: entities
        style:
          "#states div":
            slider-entity-row:
              $: |
                .flex {
                  margin-top: -40px;
                  margin-left: 40px;
                  margin-right: 40px;
                }
          "#states div":
            hui-toggle-entity-row:
              $:
                hui-generic-entity-row:
                  $: |
                    .flex .info {
                      margin-top: -20px;
                    }
        show_header_toggle: false
        entities:
          - entity: light.flurlicht
          - type: 'custom:slider-entity-row'
            entity: light.flurlicht
            step: 1
            full_row: true
            toggle: false
            hide_state: true

Thanks you,
Tobias

1 Like

You need to combine them

style:
  "#states div":
    slider-entity-row:
      $: ...etc...
    hui-toggle-entity-row:
      $: ...etc...

Otherwise the second "#states div" overrides the first one.

You can also apply the styles directly to the entity rows with the latest version of card-mod:

type: entities
entities:
  - entity: light.flurlicht
    style:
      $:
        hui-generic-entity-row: ...etc...
  - type: custom:slider-entity-row
    style:
      $: |
        .flex { ..etc...
    ...etc...

Hello Thomas,

thank you for your quick reply (and your awesome mod :slight_smile: ).
I also tried that yesterday but it’s also not working for me


It should look like that right?

        style:
          "#states div":
            slider-entity-row:
              $: |
                .flex {
                  margin-top: -45px;
                  margin-left: 40px;
                  margin-right: 40px;
                }
            hui-toggle-entity-row:
              $:
                hui-generic-entity-row:
                  $: |
                    .flex .info {
                      margin-top: -20px;
                    }

I still only see the first of the two adjustments.
If I switch the positions of the two, the other one gets visible.

Any idea why?
Thank you also for the other solution.
I guess this would work, but I have a lot dimmer in this entities card, so the general approach would save me a lot copy and paste. :wink:

Try .wrapper instead of .flex in the first one.

Ok, .wrapper didn’t work for my margins, the slider didn’t move.
But I guess your idea is somehow based on a problem, that we shouldn’t use the same identifiers for different selectors?

So I tried to alter my selector in a way that doesn’t change it functionally:

"#states div":
            slider-entity-row:
              $: |
                .flex:first-of-type {
                  margin-top: -40px;
                  margin-left: 40px;
                  margin-right: 40px;
                }
            hui-toggle-entity-row:
              $:
                hui-generic-entity-row:
                  $: |
                    .flex .info {
                      margin-top: -20px;
                    }

This works fine. :slightly_smiling_face:
Can you explain why this happens, as it might help to avoid it for my next css modifications?

I’m afraid I can’t, because this works for me:

  - type: entities
    title: Test
    debug_cardmod: true
    entities:
      - entity: light.bed_light
      - type: custom:slider-entity-row
        entity: light.bed_light
        full_row: true
        toggle: false
        hide_state: true
    style:
      "#states div":
        slider-entity-row:
          $: |
            .wrapper {
              margin-top: -40px;
              margin-left: 40px;
              margin-right: 40px;
              }
        hui-toggle-entity-row:
          $:
            hui-generic-entity-row:
              $: |
                .flex .info {
                  margin-top: -20px;
                }

image

Very neat idea, btw!

Try the debug_cardmod: true option and exploring the object inspector, btw. It usually helps to understand what is and isn’t happening.

1 Like

as it happens, this was just what I was looking for, hoping to have the brightness and/or rgb_color on the second row.

Since you obviously like this idea @thomasloven, would be it be a viable feature request for the slider-entity-row card to enable the second row and set it on specific attributes?

Would prevent many many user errors!

Looking for something like this:

03

showing last_changed, or color attributes on the second line. Having the color temp on the badges wouldn’t hurt either, but that might be pushing it a bit :slight_smile:

1 Like

Please, help me to customize icon color of my battery_s7edge sensor depending on it’s state.

cards:
  - cards:
      - elements:
          - entity: person.oleksandr
            style:
              color: cyan
              left: 20%
              top: 93%
            type: state-label
          - entity: sensor.battery_s7edge
            style:
              '--paper-item-icon-color': green
              left: 65%
              top: 94%

           

This does’t work

style: |
:host {
–paper-item-icon-color:
{% if states(config.entity)|int < 20 %}
red
{% else %}
green
{% endif %}
;


            type: state-icon
          - entity: sensor.battery_s7edge
            style:
              color: white
              left: 80%
              top: 94%
            type: state-label
        image: /local/pics/card_oleksandr.png
        style:
          .: |
            ha-card {
              border-radius: 27px
              border: 1px solid rgba(100,100,100,0.3);
              overflow: hidden;
              width: 97%;
              box-shadow: 3px 3px 5px rgba(0,0,0,1);
            }          
        type: picture-elements
      
    type: horizontal-stack
type: vertical-stack

Elements in a picture-elements card can’t be styled directly by card-mod.

What you can do is define a variable in the card itself:

type: picture-elements
style: |
  ha-card {
    --my-icon-color: {% if states('sensor.battery_s7edge')|int < 20 %} red {% else %} green {% endif %}
  }
elements:

And then use that variable in the element style:

  - type: state-icon
    entity: sensor.battery_s7edge
    style:
      '--paper-item-icon-color': 'var(--my-icon-color)'
      left: 65%
      top: 94%

Unfortunately, you can’t use config.entity with this.

6 Likes