🔹 Card-mod - Add css styles to any lovelace card

I’ve tried any mod I could find in this thread, and none seem to work the using Map card like this buit with auto-entities

Note I am also not using person entities anymore, because they lose their lat/long when home on wifi…
Composite device trackers work much better in that regard.

        type: custom:auto-entities
        show_empty: false
        filter:
          include:
            - #domain: person
              entity_id: device_tracker.*composite
              not:
                state: home
              options:
                card_mod:
                  style:
### aware this is not the correct DOM here, but only posting for reference sake, and show what I need
                    ha-entity-marker:
                      $: |
                        entity-picture {
                          filter: {{'grayscale()' if not is_state(config.entity,'home')
                                    else 'none'}};
                        }
        card:
          type: map
          hours_to_show: 48
          auto_fit: true
          dark_mode: ${(/ight|Dark|Matrix/).test(theme)} #${darkmode}
          card_mod:
            style: |
              ha-card {
                box-shadow: none;
              }

seems I have but 1 solution, and that is go back to my custom-ui plugin and do this:

homeassistant:

  customize:

    person.marijn: &picture
      templates:
        entity_picture: >
          var id = entity.entity_id.split('.')[1];
          return state === 'not_home'
          ? '/local/family/' + id + '_not_home.png' : '/local/family/' + id + '.jpg';

and have the entity itself use another picture based on state.
it makes it 100% reliable, show the correct picture also in Moreinfo, and does so system wide, without the need for any card_mod anywhere on the Map card, or any card I need to show these trackers…

Had hoped it not to be the case, but I see no other way

So i will answer myself as i found this bug report:

Here is mod-card used in the exact same way and obviously that is no problem. So i suppose its ok to use mod-card with an entity row.

is it possible to run a script on pressing + or - ?

To answers this myself: Most likely not possible with card-mod.

Hi everyone,

I’ve tried already few things but unfortunately I was not able to achieve what i’m looking for. Maybe someone can help me, it would be much appreciated.

I have a card which displays the room temperature. And I want to display the window icons in the header of that card, and the window icons should change color and the icon depends on the status (open/closed). Maybe A picture makes it easier to understand.

This is my card
cards:
  - align_icon: state
    color_thresholds:
      - color: '#ef1d0f'
        value: 25
      - color: '#ef5a0f'
        value: 24
      - color: '#f0da11'
        value: 22
      - color: '#11f13a'
        value: 19
      - color: '#1da4f2'
        value: 15
    entities:
      - entity: sensor.wohnzimmer_temperature
        index: 0
        lower_bound: 10
        upper_bound: 30
      - color: '#cfcfcf'
        entity: sensor.solar_elevation
        line_width: 1
        show_fill: false
        show_legend: false
        show_state: false
        y_axis: secondary
    hour24: true
    hours_to_show: 24
    more_info: false
    points_per_hour: 6
    name: Wohnzimmer
    show:
      labels: true
      name: true
      extrema: true
    type: custom:mini-graph-card
  - align_icon: state
    color_thresholds:
      - color: '#8500E1'
        value: 70
      - color: '#3000E1'
        value: 60
      - color: '#0096E1'
        value: 50
      - color: '#E1E100'
        value: 40
      - color: '#E14400'
        value: 30
    entities:
      - entity: sensor.wohnzimmer_humidity
        index: 0
    hour24: true
    hours_to_show: 24
    more_info: false
    points_per_hour: 6
    name: ' '
    show:
      labels: true
      name: true
      extrema: true
    type: custom:mini-graph-card

Hi

I have been searching through these threads to try and work out where I’m going wrong. I am only trying to make a simple change but cant get my head around the structure and shadow-root etc.

Here is one of the many codes I have tried

square: false
type: grid
title: Whos Where
cards:
  - type: horizontal-stack
    cards:
      - type: entity-filter
        show_empty: false
        entities:
          - entity: person.kat
          - entity: person.stephen
        state_filter:
          - home
        card:
          type: glance
          title: Home
      - type: entity-filter
        show_empty: false
        entities:
          - person.kat
          - person.stephen
        state_filter:
          - operator: not in
            value: home
        card:
          type: glance
          title: Not Home
  - type: entities
    entities:
      - entity: sensor.mcbain_work_shift
      - entity: sensor.kats_shift
    title: Family Calendar
    show_header_toggle: true
    state_color: false
columns: 1
card_mod:
  style:
    hui-grid-card:
      $: |-
        .card-header {
          text-align: center;
        }

All I am trying to achieve is to center the title.

image

Can anyone help and explain where i am going wrong.

Thanks in advance.

1st post → link at the bottom → grid

1 Like

Until you find a better way, you could use a markdown card:

square: false
type: grid
cards:
  - type: markdown
    content: <font size="5pt"><b>Centered</b></font>
    card_mod:
      style: |
        ha-card {
          --ha-card-background: var(--primary-background-color);
          border: 0px;
          max-height: 70px;
          text-align: center;
        }
  - type: entity
    entity: sun.sun
columns: 1

You have to disable “Render cards as squares”, though.

Is card mod styling cleared if a card is updated using the visual editor? I’m seeing this with a glance card that has style applied per each entity.

There is an issue on Github for this (if I understand you correctly).

Edit the card from YAML and see if you have the same issue. If no @Ildar_Gabdullin comment is 100%.

Hey guys. I need your help.
I want to style the mini media player card.
Background-change works fine but I want also change the color of the icon.
It doesn’t work.

Can you explain me, how I could the two style elements together?


card_mod:
  style: |
    .mmp__bg {
        {% if is_state_attr ('media_player.lg_webos_smart_tv', 'source', 'Netflix') %}
        background-image: url("/local/IMG_9493.jpeg") !important;
        background-size: 100% 150% !important;
        .mmp__bg {
        {% elif is_state_attr ('media_player.lg_webos_smart_tv', 'source', 'Prime Video') %}
        background-image: url("/local/IMG_9490.jpeg") !important;
        background-size: 100% 150% !important;
      {% endif %}
      }
      style:
        mmp-powerstrip $: |
        ha-icon-button {
        color: cyan !important;
        }

1st post → link at the bottom → others → combining

Changing the icon color is pretty straight forward.

type: custom:mini-media-player
entity: media_player.main_tv
background: red
card_mod:
  style: |
    :host {
      {{ '--mini-media-player-icon-color: red' if states('light.kitchen', '--mini-media-player-icon-color: green') else 'No' }};
      {% if states('media_player.main_tv', 'on') %}
        --mini-media-player-base-color:blue
       {% else %}
      --mini-media-player-base-color: yellow
       {% endif %}
        }

Sorry, I don´t know, what to do.

Thats my entity card:

type: custom:mini-media-player
entity: media_player.lg_webos_smart_tv
power_color: true
artwork: material
name: OLED TV
icon: phu:lg
volume_stateless: true
source: full
card_mod:
  style: |
    .mmp__bg {
        {% if is_state_attr ('media_player.lg_webos_smart_tv', 'source', 'Rakuten TV') %}
        background-image: url("/local/IMG_9493.jpeg") !important;
        background-size: 100% 150% !important;
        .mmp__bg {
        {% elif is_state_attr ('media_player.lg_webos_smart_tv', 'source', 'Prime Video') %}
        background-image: url("/local/IMG_9490.jpeg") !important;
        background-size: 100% 150% !important;
      {% endif %}
      }

And i want to combine it with this:

card_mod:
      style:
        mmp-powerstrip $: |
          ha-icon-button {
          color: 
            {% if is_state ('media_player.lg_speaker_dsp11ra_3462', 'playing',) %}
              #30d058 !important
            {% else %}
              white
            {% endif %}
              }

@Ildar_Gabdullin, @LiQuid_cOOled, thanks. It must be the existing issue because if I edit from yaml then styling is not cleared.

Did you follow this route and example there?

1st post → link at the bottom → others → combining

2 Likes

Thanks, now it works.

:slight_smile:

I was wondering how I can create alternate row colors when using this card-mod. I have a markdown card where I generate HTML based on json I receive from a rest api call. To improve readability, I would like to alternate row colors in this table, using css:

table tr td:nth-child(2) {
    background: #ccc;
}

But I can’t figure out where to put this css code.

Even adding a background-color directly in the tag ( < td bgcolor= “color_name | hex_number | rgb_number” > ) doesn’t seem to work.

Who can provide the solution?

Thanks. This did the job nice and easily.

1 Like