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

now that Ildar helped me out on adding a camera view as background of a card with

        ha-card {
          background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
          /*color: black;*/
          background-repeat: no-repeat;
          background-size: 100%;
        }

I was wondering if card-mod-theme could do the same for a View. according to Card mod Themes Ā· thomasloven/lovelace-card-mod Wiki Ā· GitHub we can set things for
card-mod-view, and maybe use the same? Ofc I did give it a try, but not sure of the syntax for that wasnt successful just yet.

Update

  card-mod-view: |
    hui-masonry-view {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

actually makes happen!

Dec-23-2021 14-55-25

as does:

  card-mod-view: |
    hui-masonry-view {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
      background-repeat: no-repeat;
      background-size: 100%;
    }

but youā€™d need a better stream than the 1 I test right now, showing a bit pixelatedā€¦

have to figure out the view-name for the custom:layout viewsā€¦ because right now I can only get it to work for the masonry-view, and not for vertical-view or horizontal-view created by that custom component.

  card-mod-view: |
    hui-masonry-view {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

    hui-horizontal-view {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

    hui-vertical-view {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

update2
found that:

    horizontal-layout {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

    vertical-layout {
      background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
    }

make it happen on the other views, probably also for grid-view, but I dont use that,so cant say for sure Doesnt work for Grid layout

trying to find a way to set a camera view on a single view, I found out that:

        paper-tab[aria-label='Weer & Klimaat'] {
          color: {{states('sensor.temperature_color_name')}};
          background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
        }

sets it to the tab in the menu bar. Pretty useless, but nice to know :wink:

this works too:

    {% if state_attr('sensor.browsermod_safari','path') == '/ui-overview/weer_klimaat' %}
      hui-masonry-view {
        background: url({{state_attr('camera.weerkaart_nl','entity_picture')}});
      }
    {% endif %}

but isnt yet what I am looking for

I need a little help I made a theme and 1 thing I canā€™t figure out.

Switches

switch-checked-button-color: rgb(138, 180, 248)
switch-checked-track-color: rgb(138, 180, 248)
switch-unchecked-button-color: rgb(172, 176, 185)
switch-unchecked-track-color: rgb(154, 160, 166)

These are my chosen colors for the switches but when I look at my theme the colors are displayed darker than chosen color.

Now I found out that home assistant applies a transparency and this makes my switch color darker.
how do i change this i already tried a few things with the card mod from hacs but i canā€™t figure it out i hope someone can help me.!!

1 = darker color
2 = the real choosen color
3 = the opacity makes color darker
Naamloos-2|690x388

This is the 1st my post here, can anyone give me a magical kick into the card-mod-themes?
Made a 1st try with this.
I got a themes file:

Custom Theme:
  ...........

  modes:
    light:
      ....
      secondary-text-color: rgb(166,166,166)
      ...

    dark:
      ...
      secondary-text-color: rgb(99,99,99)
      ...
      card-mod-view: |
        #columns .column > * {
          margin: 32px 16px;
        }

I am expecting larger margins (that was an example from Thomas).
And I see nothing(((
Dark theme is applied, variables are used.
What am I doing wrong?

Just added this:

      card-mod-theme: "Custom Theme"

does not help.

Did you start smaler (without dark, liht, ā€¦)?

  card-mod-theme: noctis-grey

  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: 32px 16px;
        }

is working here and might be a starting point.

just to be sure, begin with sluggifying your names:

custom-header:

  card-mod-theme: custom-header

and call that in you main theme.
Id start with a single mod, to see if anything is happening at all, as Arganto says above. Must admit several of the mods listed on the Githubs cookbook dont works for me either. Couldnā€™t get the

# https://github.com/thomasloven/lovelace-card-mod/wiki/Card-mod-Themes#classes
#  card-mod-row-yaml: |
#      ...
#      :host(.teal) {
#        background: teal;
#      }
#      :host(.purple) {
#        background: purple;
#      }

section to work as example for that.

Hop over to my Custom header theme Ā· GitHub gist to see what I could get working.

It could be card-mod doesnā€™t support seperate dark theming. Try putting that into the main theme, and setting the margin as a normal HA variable.

Mmm, how to do it?)))
I put this code right after themeā€™s title & then inside ā€œlightā€ section - no effect.

Custom Theme:

  card-mod-view: |
    #columns .column > * {
      margin: 32px 16px;
    }
Custom Theme:

  modes:
    light:

      card-mod-view: |
        #columns .column > * {
          margin: 32px 16px;
        }

Can I set card-mod for the default theme? If yes - how then?

Tried this with noctis theme (which does not have separate light & dark modes):

noctis:  

  card-mod-theme: noctis
  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: 32px 16px;
        }

No effect.
Surely after change I call the ā€œreload_themesā€ service.

Also, I wonder what is a meaning of this:

since this code is already placed inside some theme with a name?

Pardon, what do you mean?
I got some custom theme with light & dark modes (it is based on originally so called Google Dark theme, I replaced some variables and added some user-defined variables), and also I installed Noctis theme via HACS (just out if curiosity).
Both themes have lots of variables; I am not sure that any theme has a special variable for margins between cards.

Marius, I do not understand, what is a meaning of ā€œcustom-headerā€ in your example?

You should only need to put it once, outside of modes.

You can create a theme that doesnā€™t change anything but adds card-mod.

It sounds like thereā€™s a problem with your code.

It tells card-mod what to do, and it lets you create separate themes with styles you can tack on to another one.

You can create a variable, even if it isnā€™t included in HA. Then you could reference it like margin: var(--margin-in-dark-mode) in card-mod if you set it up like margin-in-dark-mode: 20px in your theme.

Which code exacltly? Themes are working = custom light & dark, noctis.
At least if I change some variable in any theme then I see effects in views.

This example I took from card-mod repository (put it inside Noctis):

noctis:  

  card-mod-theme: noctis
  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: 32px 16px;
        }

Suppose these ā€œcard-mod-view-yamlā€-like sections (which defining styles, I think) are placed below that ā€œcard-mod-theme: noctisā€ line.
All this code is placed inside some theme (but outside modes) - I guess that this code already belongs to this particular theme, it is strange for me that we need to specify a name again.
Also, if some theme is called ā€œtheme123ā€ - should that ā€œnameā€ line be "card-mod-theme: theme123" (i.e. same name)? And if the theme is called ā€œCustom Themeā€?
Update: seems that this line must be exactly the same as the themeā€™s name (i.e. "card-mod-theme: "Custom Theme"" )

Yes, I call them ā€œuser-defined variablesā€.
So, if I understood your post properly, I got this code:

noctis:  

  card-mod-theme: noctis
  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: var(--user-margin-between-cards);
        }
  user-margin-between-cards: 32px 16px

OMG! I do not understand what happened - but I succeeded with this old code (as well as with using variable, see above):

noctis:  

  card-mod-theme: noctis
  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: 64px 32px;
        }

and with my custom theme:

Custom Theme:

  card-mod-theme: "Custom Theme"
  card-mod-view-yaml: |
    hui-masonry-view:
      $: |
        #columns .column > * {
          margin: 32px 32px;
        }

My 1st small victory! (have no idea why it did not work earlierā€¦)
Anyway, do not understand the meaning of that "card-mod-theme: "Custom Theme"" - since it repeats the name of the theme.

This mod is just awesome!
Opened new horizons)))

As I have answered above. :joy:

And regarding the why of card-mod-theme, I think it is the mapping to the theme, so that it is applied to the selected one.

Did you have already investigated the wiki pages? Next to the link to your non-theme examples. There it is described the same way.

No no no, it was not working first ))) I have no idea why!

Oh, that was a real starting point, thank you.
Actually, I was not going to dig into card-mod-themes right NOW - I planned to start learning it a bit later.
But I needed to set a fixed width to the right sidebar - so I started thinking about card-mod-themes.

Good tutorial, btw.

this is the name of the card-mod theme. you create the card-mod-theme, like I posted:

custom-header:

  card-mod-theme: custom-header

and then in your actual theme, say Dark red, use that card-mod-theme:

frontend:
  themes:
    Dark red:
      card-mod-theme: custom-header
      rest of your theme settings

you can see it as an !include really.

you can ofc name it anything, the name here is used because it pertains to my custom header settings. This works for my Christmas theme:

Christmas:

  card-mod-theme: christmas-theme

which is declared like:

christmas-theme:
  card-mod-theme: christmas-theme
  <<: *main
  card-mod-card: |
    ha-card {
      overflow: hidden;
    }

(<<: *main is a huge section I repeated from another card-mod-theme)

having an issue myself currently with the dark mode (specifically on Maps), only being applied on my iPhone, and not on any other device: Maps dont follow modes: dark: consistently Ā· Issue #11027 Ā· home-assistant/frontend Ā· GitHub

How to set a fixed width for a conventional right sidebar:

  card-mod-view-yaml: |
    hui-sidebar-view:
      $: |
        .container div#sidebar {
          min-width: 400px;
        }

Update 06.12.24: the code used to have a ā€œwidth: -webkit-fill-available;ā€ line - but now I do not see it needed. Let me know if the code does not work as expected.

2 Likes

OMG, one more excited post:
just yesterday started learning this mod - now I think card-mod-themes is one of greatest fundamental features in HA frontend like decluttering-card.
Thank you, @thomasloven !

All I want to do is add a clock to the header. This was easy with CCH but for some reason Iā€™m having trouble using Card-mod. I added this to the end of my theme (Github Dark Theme)

card-mod-theme: "Github Dark Theme"
  # Header
  card-mod-root-yaml: |
    mwc-icon-button[slot="trigger"] > ha-svg-icon {
      display: none;
    }

    mwc-icon-button[slot="trigger"]::after {
      font-size: 22px;
      height: 20px; 
      width: 100px;
      margin-left: 0px;
      margin-right: 0px;
      content: "{{ states('sensor.time') }}";
      position: absolute;
      top: 14px;
      right: 0px;
    }

I also added this to my sensor.yaml

- platform: time_date
  display_options:
    - "time"
    - "date"
    - "date_time"
    - "date_time_utc"
    - "date_time_iso"
    - "time_date"
    - "time_utc"
    - "beat"

The instructions of how to add this to a theme seem a little confusing to me so any help would be appreciated.

I guess that code is now outdated since HA changed a structure of a page.
Try the code below.
I changed a DOM path (did not touch height, width & position).

  card-mod-root-yaml: |
    ha-button-menu ha-icon-button $ mwc-icon-button: |
      ha-svg-icon {
        display: none;
      }
      mwc-icon-button::after {
        font-size: 22px;
        height: 20px; 
        width: 100px;
        margin-left: 0px;
        margin-right: 0px;
        content: "{{ '13:34:21' }}";
        position: absolute;
        top: 14px;
        right: 0px;
      }

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

Or you may have this button still displayed:

  card-mod-root-yaml: |
    ha-button-menu ha-icon-button $: |
      mwc-icon-button::before {
        font-size: 22px;
        height: 20px; 
        width: 100px;
        margin-left: 0px;
        margin-right: 30px;
        content: "{{ '13:34:21' }}";
        position: absolute;
        top: 14px;
        right: 0px;
      }

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

2 Likes

trying to change the icon of a tab is about the only thing left I like to establish in replacing my Custom Header from the old days. Please help me figuring this out.

We can change the color of a tab with:

        paper-tab[aria-label='Home'] {
          color: {{'red' if states('sensor.count_alerts_notifying') > '0'}};
        }

but adding an icon line there wont work, inspector says the icon is inherited from ha-tabs, and shows a yellow exclamation mark.

If I try and do something like:

/* Set the color of the currently selected tab indicator. */
        ha-tabs {
          --paper-tabs-selection-bar-color: black !important;
          --paper-tab[aria-label='Home summary'] {
            ha-icon: mdi:help !important;
          };
        }

nothing happens, except for the tab indicator being colored black.

same for:

        paper-tab[aria-selected='Home'] > ha-svg-icon {
          icon: mdi:help !important;
        }

Hope someone can assist me in finding the correct item in inspector to set an iconā€¦

this works for me:

        /* Optionally set a replacement template text. */
        ha-button-menu::before {
          content: "{% if states('sensor.browser_mod_safari') not in ['unknown','unavailable'] %}{{states('sensor.custom_header_template')}}{%endif%}";
          color: var(--text-primary-color);
          visibility: visible;
          position: relative;
          top: 24px;
          white-space: nowrap;
        }

Looking for this?
ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

      paper-tab[aria-label='test'] ha-icon::after {
        margin-left: 10px;
        content: "xxxxxxxxxxxxxxx";
      }

Just specify an icon for the tab settings.

Good, easy & simple))

dont think so, I want to replace the icon set in the view, with a state dependent icon.

for example this is what we do in the regular Views:

title: Home
icon: mdi:home
path: home

in Custom Header we did:

tab_icons:
  settings_motion: >-
    {%- if states('binary_sensor.motion_sensors_all') == 'on' -%}mdi:motion-sensor
    {%- else -%}mdi:motion-sensor-off
    {%- endif -%}

which in a card-mod-theme would become something like:

        paper-tab[aria-label='Home'] ha-icon {
          icon:  {{'mdi:motion-sensor' if states('binary_sensor.motion_sensors_all') == 'on' else 'mdi:motion-sensor-off'}}
        }

ofc this doesnt workā€¦