šŸ”¹ Card-mod - Super-charge your themes!

Is it possible to use arribute of a device to drive card background color?

I am quite happy with my theme setup right now, with active cards having a highlighted color. However, my smart ovens only shows activity through attribute.

my code:

    card-mod-card: |
      ha-card {
        background: {% if is_state(config.entity, 'on') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% elif is_state(config.entity, 'home') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% elif is_state(config.entity, 'open') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% elif is_state(config.entity, 'heating') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% elif is_state(config.entity, 'playing') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% endif %}
      }
      
        ha-card {  background: {{ 'rgba(225, 225, 225, 1)' if
        is_state_attr('config.entity', 'hvac_action',
        'heating') }}; --primary-text-color: black;

        } 


Try achieving the same result (i.e. dependingly of your oven) by using card-mod WITHOUT a theme.

That works very fine, and i could continue doing that. I just want to have most of my settings in my theme to keep it simple.

I proposed to test it w/o a theme it since I thought that there could be some problem with your styles.
You need a styles for the oven entity only - then you should ā€œlimitā€ it correspondingly - like it is done here for a fan entity only:

  card-mod-row-yaml: |
    hui-generic-entity-row $: |
      state-badge {
        {% if config is defined %}
          {% if config.entity is defined %}
            {% if config.entity.startswith('fan.') and is_state(config.entity, 'on') %}
              animation: spin 3s infinite linear;
            {% endif %}
          {% endif %}
        {% endif %}
      }
      @keyframes spin {
        0% {
          transform: rotate(0deg);
        }
        100% {
          transform: rotate(359deg);
        }
      }

Aah, i see!

Iā€™m a hack at this, but will try to play around with it and see if i could get it to work!

Thanks! :relaxed:

Edit:

Works like a charm.

ha-card {
        background: {% if config.entity.startswith('climate.') and is_state_attr(config.entity, 'hvac_action', 'heating') %} rgba(225, 225, 225, 1);
        --primary-text-color: black;
        {% endif %}
      }

check New interactive history explorer custom card - #352 by HeyImAlex

Iā€™ve been using card-mod for quite awhile, but Iā€™m just getting into creating some themes. Unfortunately, I can get neither my icons to change color or to get the battery level bars to appear using the theme below:

iPhone_Default:
  card-mod-theme: iPhone_Default
  background-image: "center / cover no-repeat fixed url('/local/images/tall/background1.jpg')"
  lovelace-background: var(--background-image)
  primary-color: "#FFFFFF"
  light-primary-color: "#888888"
  primary-background-color: "#e5e5ea"
  secondary-background-color: rgba(255, 255, 255, 0.9)
  divider-color: "#FFFFFF"
  accent-color: rgba(255, 159, 9, 1)
  # Text
  primary-text-color: "#FFFFFF"
  secondary-text-color: "#888888"
  text-primary-color: "#FFFFFF"
  disabled-text-color: "#FFFFFF"
  text-dark-color: "#888888"
  # Sidebar Menu
  sidebar-background-color: var(--primary-background-color)
  sidebar-icon-color: var(--light-primary-color)
  sidebar-text-color: var(--light-primary-color)
  sidebar-selected-background-color: var(--primary-background-color)
  sidebar-selected-icon-color: "#FFFFFF"
  sidebar-selected-text-color: var(--sidebar-selected-icon-color)
  # States and Badges
  state-icon-color: white
  state-icon-active-color: red
  state-icon-unavailable-color: var(--disabled-text-color)
  paper-item-icon-active-color: "#FFFFFF"
  # Sliders
  paper-slider-knob-color: "#FFFFFF"
  paper-slider-knob-start-color: var(--paper-slider-knob-color)
  paper-slider-pin-color: var(--paper-slider-knob-color)
  paper-slider-active-color: "#007aff"
  paper-slider-secondary-color: var(--paper-slider-knob-color)
  paper-slider-container-color: rgba(255, 255, 255, 0.5)
  paper-slider-font-color: "#000"
  ha-slider-background: none !important
  # Labels
  label-badge-background-color: "#23232E"
  label-badge-text-color: "#F1F1F1"
  label-badge-red: rgba(255, 149, 9, 0.7)
  # Cards
  card-background-color: var(--secondary-background-color)
  paper-listbox-background-color: var(--primary-background-color)
  ha-card-border-radius: 20px
  ha-card-background: rgba(245, 245, 245, 0.4)
  paper-card-background-color: var(--ha-card-background)
  ha-card-border-width: 0
  # Toggles
  paper-toggle-button-checked-button-color: "#484848"
  paper-toggle-button-checked-bar-color: "#484848"
  paper-toggle-button-unchecked-button-color: var(--paper-toggle-button-checked-button-color)
  paper-toggle-button-unchecked-bar-color: var(--disabled-text-color)
  # Table row
  table-row-background-color: var(--primary-background-color)
  table-row-alternative-background-color: var(--secondary-background-color)
  # Toggle Switches
  switch-checked-color: "#30d257"
  switch-checked-track-color: "#3092FF"
  switch-checked-button-color: "#00B3FF"
  # Other
  paper-dialog-background-color: rgba(200, 200, 200, 0.8)
  paper-item-icon-color: "#333333"
  more-info-header-background: rgba(230, 230, 230, 0.5)
  lumo-body-text-color: var(--primary-text-color)
  app-header-background-color: rgba(61, 107, 86, 0.4)
  markdown-code-background-color: "#FFFFFF"
  code-editor-background-color: "#FFF"
  # Custom
  mcg-title-letter-spacing: .15em
  mini-media-player-base-color: white
  mini-media-player-icon-color: white
  input-ink-color: var(--primary-text-color)
  input-fill-color: transparent
  input-disabled-fill-color: transparent
  input-label-ink-color: var(--primary-text-color)
  input-disabled-ink-color: var(--disabled-text-color)
  input-dropdown-icon-color: var(--primary-text-color)
  input-idle-line-color: var(--secondary-text-color)
  input-hover-line-color: var(--secondary-text-color)
  codemirror-property: var(--accent-color)
  card-mod-row: |
    :host {
      display: block;
      {% set battery = state_attr(config.entity, 'battery') or state_attr(config.entity, 'battery_level') %}
      {% if battery %}
        background: linear-gradient(to right, rgba(0,255,0,0.5), {{battery}}%, white {{battery}}%);
      {% endif %}
    }

I expect the icons in my entities cards to be white, and to change to red when activeā€¦ but the icons are actually a dark grey color irrespective of state. And the battery bars, wellā€¦ no sign of those. I welcome any input.

A very humble proposal - to describe the issue you may safely remove everything between these lines since it is not related to card-mod.
The post becomes shorter.

Also , the ā€œbatteryā€ variable seem be true or false - do not think this is what you need.

Great idea - proposal accepted, see below. I originally included everything in case something else was impacting my icon colors, but admittedly thatā€™s not related to card-mod (I donā€™t believe).

iPhone_Default:
  card-mod-theme: iPhone_Default
  background-image: "center / cover no-repeat fixed url('/local/images/tall/background1.jpg')"
  lovelace-background: var(--background-image)
  primary-color: "#FFFFFF"
  light-primary-color: "#888888"
  primary-background-color: "#e5e5ea"
  secondary-background-color: rgba(255, 255, 255, 0.9)
  divider-color: "#FFFFFF"
  accent-color: rgba(255, 159, 9, 1)
  [ ... ]
# States and Badges
  state-icon-color: white
  state-icon-active-color: red
  state-icon-unavailable-color: var(--disabled-text-color)
  paper-item-icon-active-color: "#FFFFFF"
  card-mod-row: |
    :host {
      display: block;
      {% set battery = state_attr(config.entity, 'battery') or state_attr(config.entity, 'battery_level') %}
      {% if battery %}
        background: linear-gradient(to right, rgba(0,255,0,0.5), {{battery}}%, white {{battery}}%);
      {% endif %}
    }

I started using this today, and using the art-nouveau theme, I canā€™t see the background image. If I use a local image, one that works outside of the theme, still nothing. If I use background outside the theme, it appears for a split second.

Hi,
Iā€™m no CSS profi but try many thinks with your great card-mod, but I ca not find a solution for the mini-graph-card.

Screen_20221114-165833

I want to have a distance from the fine border line to the graph but always the graph is going to the border. Here my code:

  - type: custom:mini-graph-card
    card_mod:
      style: |
        ha-card {
          padding: 10px;
        }
    name: CPU Auslastung
    entities:
      - entity: sensor.processor_use
        state_adaptive_color: true
        show_fill: false
    decimals: 1
    hour24: true
    hours_to_show: 3
    height: 150
    line_width: 4
    points_per_hour: 360
    show:
      name: false
      graph: line
      icon: false
      state: false
      legend: false
      points: false
      labels: false
    color_thresholds:
      - color: '#6aa84f'
        value: 0
      - color: '#f1c232'
      - color: '#e69138'
      - color: '#cc0000'
        value: 100

Thank you for a little help.
Steffen

Iā€™m struggling with adapting my old solution as well.

Placing is set in

image

And this variable is displayed as inherited from ha-dialog as before. But changes to this are not taken into account anymore.

image

The below if from card_mod but the above is used now, coming from HA.

Even if I try to ingest in .mdc-dialog__container directly

    ha-dialog:
      $: |
        .mdc-dialog__container {
          align-items: center !important;
          color: red !important;
        }

it is not in css/dom at all.

Perhaps Ildar has an idea or explanation about the behavior?

Update: Easier than expected.

    .: |
      ha-dialog {
        --vertical-align-dialog: center !important;
      }

I seems that they have corrected a typo, which I didnā€™t see neither in the past nor in the screenshow but used from the old definition. If I corrected it now as well ā€¦

But I still not understand why I canā€™t shadow-root in ha-dialog.

1 Like

never mind, it works now.

using

  styles:
    tooltip:
      - transition: opacity 0.5s

on all my button-card tooltips throughout the dashboards, I suddenly realize the tooltips on the main menu items are not using this. Having a look into the card-mod-theme variables I couldnā€™t find the right place (if at all possible) to add this to the main mods, to make the tooltips immediate.

Would anyone be able to help me out here?

Ive tried to add it to either of these:

        /* Set the color of the currently selected tab indicator. */
        ha-tabs {
          --paper-tabs-selection-bar-color: var(--text-primary-color);
        }
        /* Set the color of the currently selected tab indicator.
           Set size of the currently selected tab icon*/
        paper-tab[aria-selected=true] {
          color: gold;
          background-color: rgba(var(--primary),0.3);
          --mdc-icon-size: {{states('input_number.active_icon_size')}}px;
        }

but not successfullyā€¦they need an actual click for that. The tooltip is a hover

        app-header, app-toolbar {
          background: {{'radial-gradient(var(--primary-color),var(--card-background-color))'
                         if states('input_select.theme')|regex_search('(ight|Dark|Matrix)')
                          else 'var(--primary-color)'}};
          color: var(--text-primary-color);
          transition: opacity 0.5s;
        }

wont do it either, so. Its a bit frustrating to ā€˜guessā€™ what to do.

I previously used card-mod to increase the size of the icons in my header bar, but at some point I lost that change. I thought @Ildar_Gabdullin posted about it, but I cannot find that in here either.

How do you change the size of the header bar icons?

I do not remember about changing an iconā€™s size on a header.
But you may try it yourself using my examples of customizing a header:
card-mod thread ā†’ 1st post ā†’ link at the bottom ā†’ examples for themes

1 Like

I hide the search magnifying glass and 3-dot menu.

card-mod-root-yaml: |
    .: |
      app-toolbar > ha-icon-button {
        display: {{'none' if is_state('input_boolean.hide_admin','on')}};
      }
      app-toolbar > ha-button-menu {
        display: {{'none' if is_state('input_boolean.hide_admin','on')}};
      }

However, it doesnā€™t hide them in the Settings page.
I noticed a different path, (ha-panel-config vs. ha-panel-lovelace) but I donā€™t know how to approach it:

Settings page:

Main page:

Suggestions?

Iā€™m using this to change the color of a single card-mod popup:

              card_mod:
                style: 
                  ha-dialog$: |
                    div.mdc-dialog__surface {background: rgba(64,64,64,1.0) !important}

How do I modify that to insert into a theme to change the background for all of my popups? This suggests I just add ā€˜ā€“ā€™ in front of background, but that does not work. Iā€™ve tried a few other variations which also donā€™t work. Thanks.

I have a problem with inside light gray border lines - could You help me to entirely get rid off them?


My code atm:

cards:
  - cards:
      - cards:
          - entity: sensor.drukarka_3d_print_status
            name: CR-6 SE
            type: entity
            icon: None
          - entity: switch.gniazdko_drukarka3d_pietro
            hold_action:
              action: more-info
            show_icon: true
            show_name: false
            tap_action:
              action: toggle
            type: button
        type: horizontal-stack
      - entities:
          - entity: switch.drukarka_3d_led
        show_header_toggle: false
        type: entities
    mode: vertical
    type: custom:stack-in-card
  - card:
      cards:
        - entity: sensor.drukarka_3d_print_progress
          type: custom:bar-card
          color: null
          positions:
            icon: 'off'
            indicator: inside
        - entities:
            - entity: sensor.drukarka_3d_print_time_left
            - entity: sensor.drukarka_3d_print_time
            - entity: sensor.drukarka_3d_print_file
            - entity: sensor.drukarka_3d_current_z
            - entity: sensor.drukarka_3d_tool_0_target
            - entity: sensor.drukarka_3d_bed_target
          show_header_toggle: false
          type: entities
        - cards:
            - entity: switch.drukarka_3d_emergency_stop
              hold_action:
                action: more-info
              name: Stop
              show_icon: true
              show_name: true
              type: button
            - entity: switch.drukarka_3d_cancel_print
              hold_action:
                action: more-info
              name: Anuluj
              show_icon: true
              show_name: true
              type: button
            - entity: switch.drukarka_3d_pause_print
              hold_action:
                action: more-info
              name: Pauza
              show_icon: true
              show_name: true
              type: button
            - entity: switch.drukarka_3d_shutdown_system
              hold_action:
                action: more-info
              name: Wyłączenie
              show_icon: true
              show_name: true
              type: button
          type: horizontal-stack
      mode: vertical
      type: custom:stack-in-card
    conditions:
      - entity: binary_sensor.drukarka_3d_printing
        state_not: 'off'
    type: conditional
  - card:
      decimals: 1
      entities:
        - entity: sensor.drukarka_3d_tool_0_temperature
          name: Dysza
          show_state: true
        - entity: sensor.drukarka_3d_bed_temperature
          name: StĆ³Å‚
          show_state: true
      hours_to_show: 1
      name: Temperatura dyszy/ stołu
      points_per_hour: 120
      type: custom:mini-graph-card
    conditions:
      - entity: binary_sensor.drukarka_3d_printing
        state_not: 'off'
    type: conditional
  - entities:
      - entities:
          - entity: sensor.filament_temperatura
            name: false
        entity: sensor.filament_wilgotnosc
        icon: mdi:thermometer
        name: Temperatura/ wilgotność filamentu
        secondary_info: last-changed
        type: custom:multiple-entity-row
    show_header_toggle: false
    type: entities
type: vertical-stack

Thank you in advance for any help and info!

final challenge in my menubarā€¦

this is in full width:

but changing the window makes the text template cover all of my tab icons:

would there be any way to limit the space the text template can use to a fixed width, (and maybe scroll in that text)?

I am using an input_boolean to use that template:

      .: |

        /* Hide chevrons
        paper-tabs$: |
          .not-visible {
            display: none;
          } */

        /* Optionally set the three-dots transparency,
           to allow for a replacement template text. */
        ha-button-menu {
          color: {{'transparent' if is_state('input_boolean.menu_options_template','on')}}; /*var(--primary-color)*/
        }

        /* Optionally set a replacement template text. */
        ha-button-menu::before {
          content: "{{states('sensor.custom_header_template')}}";
          color: var(--app-header-text-color);
          visibility: visible;
          position: relative;
          top: 24px;
          white-space: nowrap;
        }

so, if it cant be done, I might be able to auto-turn_off that boolean based on the screen width?

hope you can have a look, thanks!