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

1st post → link at the bottom titled ā€œfantasticā€ → auto-entities

Thanks for the indeed fantastic collection of references. I went through it and found similar posts. I edited my template and changed it to this:

type: custom:auto-entities
card:
  type: entities
  title: Critical Battery Status
filter:
  template: >
    {% for entity in states.sensor if entity.attributes.device_class ==
    'battery' and area_name(entity.entity_id) and entity.state|float < 60 %}
      {{
        {
          'entity': entity.entity_id,
          'secondary_info': 'last-changed',
          'card_mod': {
            'style': {
              '.': '.ha-card { --paper-item-icon-color: red; }',
            }
          }
        }
      }},
    {% endfor %}

The icon is still in HA-blue and not getting recolored to red.

Means - this is what you expect, right?

type: entities
title: ...
entities:
  - entity: xxx
    secondary_info: last-changed
    card_mod:
      style: |
        .ha-card { --paper-item-icon-color: red; }

But the style is wrong, can you see ?)

Unrelated to card-mod:

  1. Use ā€œdefaultā€:
entity.state|float(default=0)
  1. Should be properly converted to a list - use ā€œ-ā€:
...  < 60 -%}
...
{%- endfor %}

Besides, what a reason to use ā€œā€“paper-item-icon-colorā€ if all battery-level sensors have colored icons by default? Probably listing problematic entities (< 60%) would be enough. Just add

sort:
  method: state
  numeric: true

on a auto-entities-card level, not on filter level.

Hello
I just started playing with card_mod for glance card.
I was able to :

  • resize the card height
  • resize the font size

But i’d like to center the text and strangely the area where the text is do not follow the card size

let me explain with image :

font size 30px
image

font size 80px
image

I’d like the text to be big and to occupies the whole space, does anyone know how ?

He’s the yaml

show_name: false
show_icon: false
show_state: true
type: glance
entities:
  - entity: sensor.poele_on_last_fill_2
    card_mod:
      style: |
        :host {
           font-size: 80px;
           height: 69px;
        }

thx a lot

I tried playing with the Wrapped value example, but I cant get it to work

Ps : glance is not an obligation, i just want the visual, but glance is the one I reached the closest to my needs.

There are examples for Glance, you have already been advised.

yep, thx a lot for that, but I don’t understand how to get it to work.
If you could point me to the right direction that would be lovely :slight_smile:

Take any example for Glance card & start playing)

didn’t think off that !
thx a lot :slight_smile:

1 Like

Can someone please help me? I have a camera that has a double feed because it has a stable camera and a rotating one. However the feed comes out as one video. How can I use card-mod to crop the upper half of the image?

Please elaborate. Attaching a picture would be useful.

Good evening,

I’ve read Ildar’s posts, and tried the tricks for getting iframes to resize. I have a card, weather-radar-card. While it’s no longer maintained, it works for now, and I like it better than some less interaction ideas like grabbing animated GIFs from the NWS or embedding their radar page on my dashboards.

Thing is, I cannot figure out how to control the height of this card. I saw elsewhere in this thread (from searching) that it’s not possible to ā€œbreak intoā€ iframes, for security reasons, but it seems like there should be a way to control the height of this card through the tricks for iframes that already exist.

The ā€œthreadā€ that I tried, but could not make work, was:

card_mod:
   style: |
      style: |
        div#mapid iframe  {
          transform: scale({{states("NUMBERS")|float / 100|float}});
          transform-origin: 0 0;
          width: 100000px;
          height: 100000px;
        }

Where NUMBERS is where I tried lots of values, none of them changed the output at all. It MUST be possible to force this card to be an arbitrary width / height; I just want it to be wider than it is tall.

[sneaky edit]

I’d also use this:

This NWS site in an website / iframe card

but the ā€œcontrol boxesā€ take up too much space and I don’t want them, or would like to force them to be smaller, and the above code doesn’t seem to work when they’re in an iframe card, either.

Is it what you want? )

Good evening, and thanks for responding. I appreciate it.

The reason I rejected that is because it starts cutting off the bottom of the card when you do that. In other words, it clips the content instead of scaling the - for lack of a better term - viewport while leaving the controls intact.

Increasing a size of a map itself imho cannot be done w/o entering it’s internal structure - which is prohibited.

This particular one is impossible then, eh?

Imho - impossible.
Would be glad to be wrong.

That’s what I figured, but I appreciate you chiming in. I really did try before asking!

Is there some sort of card that I could shoehorn the radar-card into that would have the desired effect?

Do not think so (may be just do not know it).

I am having trouble getting my senors to data value to change color to red if the humidity is below 30% and above 70% and temperature in red if temps go below 59F and above 70F but the ymal code i put is not working correctly to trigger the color changes this is one of 3 cards i want the trigger done on but its not working correctly i do have bot the card mod and the other card mod resources installed

type: entities
entities:

  • entity: sensor.museum_attic_southeest_humidity_level
    name: Humidity level
    style: |
    :host {
    –paper-item-icon-color:
    {% if states(ā€˜sensor.museum_attic_southeest_humidity_level’) | float < 30 or >70 % > ā€˜red’ %}
  • entity: sensor.museum_attic_southeest_temperature
    name: Temperature
    title: Museum - Attic Near Stairwell
    state_color: true

I would suggest you to follow forum rules when posting a code (formatting) and use punctuation marks, do not get me wrong. And use Dev tools → Template for testing your templates, they are wrong. Docs for templating.