šŸ”¹ Card-mod - Add css styles to any lovelace card

Hi all,
I am working on a picture-element card in HA where the whole heating system of the house should be displayed. I finished with this on my laptop and everything looks good in full screen. Here an example:

image

Nevertheless, if I rescale the window size, the size of the state-badge stay the same ā†’ they become to bigā€¦ How can I archive it that they also get defined their sizes in % of the window size?

image

I believe that this should be possible with card-mod, am I right?

My config up to now looks the following:

type: picture-elements
elements:
  - type: state-badge
    entity: sensor.node_1_input_1
    style:
      top: 15%
      left: 11%
      transform: translate(-50%,-50%) scale(0.7,0.7)
  - type: state-icon
    entity: binary_sensor.pumpe_solar_state
    style:
      top: 39.5%
      left: 26.5%
      transform: translate(-50%,-50%) scale(0.7,0.7)
image: /local/pictures/HeizungsĆ¼berblick.jpg

Check this.

Thanks for your fast answer :slight_smile:

Note that on a smaller viewport elements become BIGGER (respectively to the main image).
This may be solved by scaling elements differently on different viewports ("transform: translate(-50%,-50%) scale(diff_scale_value,diff_scale_value)").
Two ways may be used:
ā€“ the whole floorplan card is a decluttering-card - pass a scale value as a variable;
ā€“ use card-mod to set scales conditionally dependingly on a current viewport (use ā€œmediaqueryā€).

I already saw this but I couldnā€™t figure out what I have to do in order to solve my problemā€¦ How can I read out the window width and height in order to change the diff_scale_value accordingly?

  1. In my setup I gave up attempting to adjust scales dynamically and ended up with fixed scales for 3 resolutions (desktop, phone, tablet) - these scales are passed as variables into a decluttering template.

  2. To define scales dynamically - you may try using smth like (untested):
    Coeff = 100vh / 1920px - gives a ratio which is ā€œ1.0ā€ for a desktop, and is different for other clients;
    scale = some_default_scale * Coeff

How can I combine this (styling the entity icon)

        style:
          hui-generic-entity-row:
            $: |
              state-badge {
                {% if states('sensor.watchman_missing_entities') | int(0) > 0 %}
                  color: orange;
                {% endif %}
              }

with this (styling the entity value):

        style: |
          .state.entity {
            {% if states('sensor.watchman_missing_entities') | int(0) > 0 %}
              color: cyan;
            {% endif %}
          }

for one custom:multiple-entity-row type?
I donā€™t know how to syntactically mix both so one style: definition applies them all.

How to set the margin-top and margin-bottom for a custom:fold-entity-row?

It uses too much space, example:
grafik

This is not working unfortunately:

      - type: custom:fold-entity-row
        head:
          type: section
          label: Watchman Report
          style: |
            .divider {
              background-color: transparent !important;
              #margin-top: -15px !important;
            }
        padding: 0
        open: false
        entities:
          - ...
        card_mod:
          style:
            .: |
              ha-card {
                margin-top: -15px; # <-- not working
                margin-bottom: -15px; # <-- not working
              }

Always think first, that most probably a lot of users such questions before and go through some example from Ildar or in this thread. And you will directly see the answers.

e.g. above here

Unfortunately itā€™s not that easy. I tried all possible combinations. The referenced example unfortunately is not helpful in this context.

hui-generic-entity-row: must not have a pipe (|) in the style: | line before, while .state.entity { does. So how do you combine those.


Update:
found the solution.

        style:
          .: |
            .state.entity {
              {% if states('sensor.watchman_missing_entities') | int(0) > 0 %}
                color: cyan;
              {% endif %}
            }
          hui-generic-entity-row:
            $: |
              state-badge {
                {% if states('sensor.watchman_missing_entities') | int(0) > 0 %}
                  color: orange;
                {% endif %}
              }

Donā€™t understand it (cause this DOM navigation stuff is just complicated as f*** :laughing:) but itā€™s working.

It is helpful, because it is the same. Instead of pipe use.: pipe for the pipe one. So you have to and can combine as in this given example.

I found this out on the 2nd reading too (updated my last post), thx :slight_smile:

Now Iā€™m only looking for a second probably ā€œno-brainerā€

Hi guys,
Iā€™ve just updated to the latest version and now my padding on my cards no longer work.

type: horizontal-stack
title: Sensor Switch
cards:
  - type: custom:mushroom-entity-card
    entity: switch.kitchen_sensor
    layout: vertical
    name: Kitchen
  - type: custom:mushroom-entity-card
    entity: switch.livingroom_sensor
    layout: vertical
    name: Living
    fill_container: false
  - type: custom:mushroom-entity-card
    entity: switch.hall_sensor
    layout: vertical
    name: Hall
  - type: custom:mushroom-entity-card
    entity: switch.landing_sensor
    layout: vertical
    name: Landing
  - type: custom:mushroom-entity-card
    entity: switch.utility_sensor
    layout: vertical
    name: Utility
style: |
  h1.card-header {
     padding-top: 11px;
     padding-bottom: 8px;
     line-height: 12px;
   }

could someone please tell me what Iā€™m missing?

I would really appericate the help

Hello!
I tried many hours to make the header (Neue Filme) in height smaller, but it isnā€˜t working! Can someone please give me a tip?!
Here is the code! Thanks a lot!

type: vertical-stack
cards:
  - type: custom:mini-media-player
    entity: media_player.spotify_stefan
    volume_stateless: false
    toggle_power: false
    group: false
    info: scroll
    name: Stefan, Michi & Elina
    source: full
    power_state: true
    background: '"/local/spotify4.jpg"'
    artwork: full-cover
    hide: null
    power: true
  - type: custom:upcoming-media-card
    title: Neueste Filme
    entity: sensor.emby_latest_movies
    image_style: fanart
    title_size: small
    line1_size: small
    line2_size: small
    line3_size: small
    line4_size: small
    flag: false
    card_mod:
      style: |
        ha-card.type-custom-upcoming-media-         card {    
          line-height: 2px;     
          background-size: 100%;    
        }

Is it possible to show

  • secondary_info: brightness when entity state is ON and
  • secondary_info: last-changed when entity state is OFF

for a custom:slider-entity-row?

(see Allow secondary_info with custom attribute when state is off Ā· Issue #240 Ā· thomasloven/lovelace-slider-entity-row Ā· GitHub for an unsuccesful feature request - last bet really is on card-modā€¦)

Have you considered an alternative variant:

  • place a conventional input_number slider into a custom:secondaryinfo-entity-row;
  • specify a different secondary_info for different cases.

Iā€™ve scoured every corner of this thread (and others) and cannot find anything. Can someone help me with this? Iā€™m trying to change the colour of the background behind the title and cards of the Horizontal Stack. Iā€™ve attached my attempt which does not work. Iā€™ve also tried ā€œbackgroundā€ in place of color, with no success.
Any ideas?

Another issue that I canā€™t seem to find a solution for. I would like to increase the size of the fonts for the Weather Forecast lovelace card. Managed to increase the day line and the low temp forecast line, but canā€™t seem to figure out how to increase the high temp line.
Please helpā€¦ ?
Screenshot attached.
Thanks again.

1st post ā†’ link at the bottom ā†’ styles for vertical-stack (same for horizontal-stack).

Well that would be ā€œusing another toolā€, I prefer ā€œcustomizing (styling) a toolā€ tbh :slight_smile:

Thanks a lot for the promt help. I just came to test this and it works perfect. Is there also a way to remove the rounding of the upper corners? Is there a way to move the icons closer to the camera image?

Where can I find the full documentation of card-mod, it is a great HA addon but I didnt find any documentation for it (other then this forum).

The doc for card-mod can be found here and this is a useful tool for navigating the dom structure.

As for removing the rounded borders, you should look into the CSS border-radius property. For the space, youā€™ll have to use your browserā€™s dev tools to find where that comes from in order to reduce it.