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

Thank you @Ildar_Gabdullin , that fixed the column width problem.

But I have two (hopefully now small) issues remaining:

  1. The column width is defined manually and it seems that this value is mandatory.
layout:
  column_widths: 70% 30%
  width: 220

But this results in the columns being pushed below each other depending on the amount of cards in the dashboard despite being shown correctly in editor mode.



  1. Is there a way to use % instead of px e.g. for heights?

The latter may also solve the first issue. Essentially I do not want to define the total width of the horizontal-stack, just the ratios inside it.

Current code for reference and sharing :)
type: custom:layout-card
layout_type: custom:horizontal-layout
layout:
  column_widths: 70% 30%
  width: 200
cards:
  - type: vertical-stack
    cards:
      - type: custom:slider-entity-row
        entity: climate.eq_3_living_room
        name: Living Room
        min: 4.5
        max: 23
        step: 0.5
        hide_state: false
        icon: mdi:fire
      - type: custom:apexcharts-card
        graph_span: 24h
        experimental:
          color_threshold: true
        update_interval: 10 s
        now:
          show: false
          color: red
          label: Now
        yaxis:
          - show: false
        apex_config:
          grid:
            show: false
          chart:
            height: 100px
        series:
          - entity: sensor.eq_3_temperature_lr
            stroke_width: 2
            group_by:
              func: last
            fill_raw: zero
            color_threshold:
              - value: 4.5
                color: blue
              - value: 16
                color: yellow
              - value: 18
                color: orange
              - value: 20
                color: red
  - type: vertical-stack
    cards:
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 'Off'
        show_name: true
        show_icon: false
        show_state: false
        styles:
          card:
            - height: 50px
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 4.5; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 4.5
            entity_id: climate.eq_3_living_room
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 18 °C
        show_name: true
        show_icon: false
        show_state: false
        styles:
          card:
            - height: 50px
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 18; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 18
            entity_id: climate.eq_3_living_room
      - type: custom:button-card
        entity: climate.eq_3_living_room
        name: 20 °C
        show_name: true
        show_icon: false
        show_state: false
        styles:
          card:
            - height: 50px
        state:
          - operator: template
            value: '[[[ return entity.attributes.temperature == 20; ]]]'
            color: rgb(255, 0, 0)
        tap_action:
          action: call-service
          service: climate.set_temperature
          service_data:
            temperature: 20
            entity_id: climate.eq_3_living_room

new challenge: add a bit of vertical spacing to entities in an embedded fold-entity-row card:

this doesnt happen on all embedded f-e-r cards oddly enough, maybe its because of the entity_pictures. and the lack of a secondary row.

  - type: entities
    title: Family tracked
    card_mod: *header_no_margin
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: Marijn
        padding: 0
        entities:
          - device_tracker.unifi_me
          - device_tracker.ping_iphone_me
          - device_tracker.life360_me
          - device_tracker.me_app
          - device_tracker.me
          - device_tracker.owntracks_me
          - device_tracker.calltheboss_me_bt

Still Id like to add spacing, like:


which btw is an auto-entities card expanding a group.

or, a regular entities with the exact same list:

can that be done?


wait, the secondary doesnt help:

now I definitely need a card_mod change…
btw, ofc I tried to do without the padding: 0 but thats doesnt help.

Sorry about all the confusion here.
Hui-element is supposed to be transparent to card-mod. I.e. styling hui-element should be as if styling the element inside it.

I think I’ve managed to fix that for 1.1.2, but there are lots of edge cases…

image

- type: entities
  entities:
    - type: section
      label: Default internal styling
      card_mod:
        style: .divider { background-color: red; }
    - type: custom:hui-element
      row_type: section
      label: Hui-element internal styling
      card_mod:
        style: .divider { background-color: green; }
- type: entities
  entities:
    - type: section
      label: Default styled from card
    - type: custom:hui-element
      row_type: section
      label: Hui-element styled from card
  card_mod:
    style:
      hui-section-row $: .divider { background-color: blue; }
      hui-element $: .divider { background-color: orange;}

Seems that you applied a style to a wrong element - rotation is not centered, there is a shift.

Cannot react on this, know nothing about card-mod-themes…

Same on my setup, strange.

yes, ofc I noticed that, thought it might be the icon not being perfectly centered. Its the same in Chrome. And the code is the exact code you use…

Yesterday was the 2nd time I experimented with layout-card - it is better to discuss these issues in a corresponding thread.

That is why I wrote that this is not the best solution…
I do not know how to align controls automatically.

1 Like

on the coloring of the template-entity-row entity’s icon:
for the sake of experiment (and see if the code itself is corrrect) I changed to:

              @keyframes coloring {
                0% {
                  background: red;
                }
                17% {
                  background: orange;
                }
                34% {
                  background: yellow;
                }
                51% {
                  background: green;
                }
                68% {
                  background: lightblue;
                }
                85% {
                  background: blue;
                }
                100% {
                  background: violet;
                }

which looks like:
Nov-19-2021 15-10-31
in Safari, and

Nov-19-2021 15-13-21
in Chrome.

which could proof to be useful as a way around the issue…

Thank you, I will :slight_smile:
As a first feedback, I can say that the solution for the width issue was using layout_type: custom:grid-layout. This also does not require me to define the width.

This is an old issue.
Now I am using this style in my setup for each row:

                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

See the difference here:

type: horizontal-stack
cards:
  - type: entities
    entities:
      - type: section
        label: persons
      - entity: person.ildar
      - entity: person.mama
      - entity: person.papa
  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
    card_mod:
      style:
        fold-entity-row:
          $:
            div#items hui-text-entity-row:
              $: |
                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

image

Earlier this style worked too but stopped working (the issue):

  - type: entities
    entities:
      - type: custom:fold-entity-row
        head:
          type: section
          label: persons
        padding: 0
        open: true
        entities:
          - entity: person.ildar
          - entity: person.mama
          - entity: person.papa
        card_mod:
          style:
            div#items hui-text-entity-row:
              $: |
                hui-generic-entity-row {
                  margin-top: 0px;
                  margin-bottom: 8px;
                }

Update (20.11.21):
The “tight vertical spacing” problem is solved in fold-entity-row ver. 2.0.12
:star_struck: :star_struck: :star_struck: :star_struck:

Test exactly this code and tell me about the difference please:

type: entities
entities:
  - type: custom:template-entity-row
    entity: sun.sun
    name: name
    secondary: some value
    state: state
    icon: mdi:fan
    card_mod:
      style:
        div#wrapper: |
          state-badge {
            animation: rotation 0.5s linear infinite, resizing 1s linear infinite alternate, coloring 8s linear infinite alternate;
          }
          @keyframes rotation {
            0% {
              transform: rotate(0deg);
            }
            100% {
              transform: rotate(360deg);
            }
          }
          @keyframes resizing {
            0% {
              --mdc-icon-size: 10px;
            }
            25% {
              --mdc-icon-size: 15px;
            }
            50% {
              --mdc-icon-size: 20px;
            }
            75% {
              --mdc-icon-size: 26px;
            }
            100% {
              --mdc-icon-size: 32px;
            }
          }
          @keyframes coloring {
            0% {
              color: red;
            }
            17% {
              color: orange;
            }
            34% {
              color: yellow;
            }
            51% {
              color: green;
            }
            68% {
              color: lightblue;
            }
            85% {
              color: blue;
            }
            100% {
              color: violet;
            }
          }

qwsder

Icon is coloring (but I have Not customized sun.sun, so not trouble with custom-ui expected :wink: )
Nov-19-2021 16-28-59

the exact card-mod on a boolean (which I have customized) remains without result

But again is not centered (((((((((
There is smth strange with your setup, my friend…
My proposal is - create a CLEAN test setup and check how it works…

will do, and just fired up Firefox as a 3d browser.

On the Folds and vertical spacing:
to give you an idea though, I have 262 fold-entity-rows, and only this card gives me a headache…
I have them populated with auto-entities cards, or listed entities, what have you. given the fact there is now error in the inspector at all on this config, debugging is very difficult.

Figured it out in themes

  card-mod-theme: noctis-grey
  
  card-mod-more-info-yaml: |
    ha-more-info-history:
      $: |
        .header > a, a:visited {
          color: var(--secondary-text-color) !important;
          font-size: 12px;
        }
    ha-more-info-logbook:
      $: |
        .header > a, a:visited {
          color: var(--secondary-text-color) !important;
          font-size: 12px;
        }  

Not that agressive anymore

image

But it is only working here, but not within the tabs like

image

Any hint?

Hello @thomasloven! Thank you very much for the feedback.
Yes, navigation for hui-element became a bit confusing - but I managed to rebuild all my code, it looks fine again!

Please let me know if you find something that doesn’t work. It’s a bit rickety with timing issues right now.

Thomas, now I got only these issues about card-mod:

Thank you again for your valuable work!

P.S. I am creating a post explaining using card-mod for hui-element for different row types as well as using them inside decluttering template with mod-card. This post will be added into the consolidation post.

Styling hui-element card:

This post is about using hui-element card to represent a row inside an Entities card:

  • section
  • sensor-entity
  • number-entity (slider or box)
  • toggle-entity
  • input-select-entity
  • input-text-entity
  • weather-entity
  • buttons
  • conditional row

Here they are (updated 04.03.22 for “chips” buttons and new HA2022.3 design):

Code for the card
type: entities
entities:
  - type: custom:hui-element
    row_type: section
    label: section
  - type: custom:hui-element
    row_type: sensor-entity
    entity: input_number.test_number
    name: sensor-entity
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number
    name: number-entity (slider)
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number_2
    name: number-entity (box)
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: toggle-entity
  - type: custom:hui-element
    row_type: input-select-entity
    entity: input_select.test_value
    name: input-select-entity
  - type: custom:hui-element
    row_type: input-text-entity
    entity: input_text.test_text
    name: input-text-entity
  - type: custom:hui-element
    row_type: weather-entity
    entity: weather.home_met
    name: weather-entity
  - type: custom:hui-element
    row_type: buttons
    entities:
      - entity: sun.sun
        show_name: true
      - entity: sun.sun
        show_name: true
      - entity: sun.sun
        show_name: true
  - type: custom:hui-element
    row_type: conditional
    conditions:
      - entity: input_boolean.test_boolean
        state: 'on'
    row:
      entity: sun.sun
      name: conditional
Why using "hui-element" for rows is very useful? Look at some examples if you do not know yet.
  1. Using a slider or a toggle row inside Picture elements card.
  2. Using section row inside stack-in-card to separate areas.
  3. Making a decluttering template for any row with predefined options & styling.

There are 4 methods of styling hui-element rows:

  1. Using :host - to style a particular row.
  2. Using long DOM navigation - to style a particular row.
  3. Using long DOM navigation from the parent Entities card or Picture elements card level - to style a particular row or all rows.
  4. Using long DOM navigation from the parent mod-card level - to style a row inside a decluttering template.

Using :host - to style a particular row:
Note: the hui-element card is a kind of transparent element - all styles go “directly to the row”.

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored row
    card_mod:
      style: |
        :host {
          color: red;
        }
  - type: custom:hui-element
    row_type: section
    label: section
    card_mod:
      style: |
        :host {
          --divider-color: magenta;
        }
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
    card_mod:
      style: |
        :host {
          --switch-unchecked-button-color: yellow;
          --switch-checked-button-color: red;
        }

image


Using long DOM navigation - to style a particular row:
Note: the hui-element card is a kind of transparent element - all styles go “directly to the row”.

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
    card_mod:
      style:
        hui-generic-entity-row:
          $: |
            .info {
              color: red;
            }
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
    card_mod:
      style:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__track {
                    background-color: yellow !important;
                    border-color: red !important;
                  }
  - type: custom:hui-element
    row_type: section
    label: section
    card_mod:
      style: |
        .divider {
          background-color: cyan !important;
        }
  - type: custom:hui-element
    row_type: number-entity
    entity: input_number.test_number
    name: Colored state
    card_mod:
      style: |
        hui-generic-entity-row .flex .state {
          color: magenta;
        }

изображение


Using long DOM navigation from the parent Entities card or Picture elements card level - to style a particular row or all rows:

Section:

type: entities
entities:
  - entity: sun.sun
  - type: custom:hui-element
    row_type: section
    label: section
  - entity: sun.sun
  - entity: sun.sun
  - type: custom:hui-element
    row_type: section
    label: section
  - entity: sun.sun
  - entity: sun.sun
card_mod:
  style:
    .card-content hui-element:
      $: |
        .divider {
          background-color: cyan !important;
        }

image

Sensor:

type: entities
entities:
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
  - type: custom:hui-element
    row_type: sensor-entity
    entity: sun.sun
    name: Colored name
card_mod:
  style:
    .card-content hui-element:
      $:
        hui-generic-entity-row:
          $: |
            .info {
              color: red;
            }

image

Toggle:

type: entities
entities:
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean
    name: Colored toggle
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean_2
    name: Colored toggle
  - type: custom:hui-element
    row_type: toggle-entity
    entity: input_boolean.test_boolean_3
    name: Colored toggle
card_mod:
  style:
    .card-content hui-element:
      $:
        hui-generic-entity-row:
          ha-entity-toggle:
            $:
              ha-switch:
                $: |
                  .mdc-switch .mdc-switch__track {
                    background-color: yellow !important;
                    border-color: red !important;
                  }

image


Using long DOM navigation from the parent mod-card level - to style a row inside a decluttering template:

Slider:
Template:

decl_entity_row__slider_xxx:
  card:
    type: custom:mod-card
    card:
      type: custom:hui-element
      row_type: number-entity
      entity: '[[SENSOR]]'
      name: '[[VALUE_NAME]]'
    card_mod:
      style:
        hui-element:
          $: |
            hui-generic-entity-row {
              color: [[VALUE_COLOR_TEXT]];
              --paper-item-icon-color: [[VALUE_COLOR_ICON]];
            }

Using the template:

type: entities
entities:
  - type: custom:decluttering-card
    template: decl_entity_row__slider_xxx
    variables:
      - SENSOR: input_number.test_number
      - VALUE_NAME: "cyan name, magenta icon"
      - VALUE_COLOR_TEXT: cyan
      - VALUE_COLOR_ICON: magenta

изображение

Input-select:
Template:

  decl_entity_row__input_select_xxx:
    card:
      type: custom:mod-card
      card:
        type: custom:hui-element
        row_type: input-select-entity
        entity: '[[INPUT_SELECT]]'
        name: '[[VALUE_NAME]]'
      card_mod:
        style:
          hui-element:
            $:
              hui-generic-entity-row:
                $: |
                  state-badge {
                    color: '[[VALUE_COLOR]]';
                  }

Using the template:

type: entities
entities:
  - type: custom:decluttering-card
    template: decl_entity_row__input_select_xxx
    variables:
      - INPUT_SELECT: input_select.test_value
      - VALUE_NAME: xxxxxx
      - VALUE_COLOR: magenta

изображение


More examples are described here.

4 Likes

Hello,

Anyone could tell me if it is possible to apply a conical gradient to a mdi:checkbox-blank-circle icon ?
Need to represent a “multicolor” button.

Thanks !

Hello,
I have a some question, maybe there I can found a solution.
Firstly, sorry for my english. I home you can understand me.

Im using my own frontend theme, but with frontend update since 2021.11 I got some problem with view of elements.
Seems like more-info dialogs and select menu updated and uses same color source (–mdc-theme-surface).
On my screenshow I show where I have problems.
I just want to leave black transparent color on more-info and browser-mod-popup background (rgba(26,26,26,0.5)), but I want to change color of selection menu in actions/condition of automations and automation menu in automation list.
But if I change --mdc-theme-surface, color change applies for all this elements (including background color of more info, what i dont want to do).

Please, help me, is it possible use card-mod to change mdc-select background color, but leave black background color of dialogs?