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

Maybe someone could help me on this, as Iā€™m not very good with CSS. I have the rotating fan on a multiple-entity-row working now, but I want it to only rotate when the switch is on. How would I change this code for that to work? I believe I need to use a jinja template, but I will likely butcher the format and never get it right. TIA

type: entities
entities:
  - entity: sensor.plaato_keg_tap1_beer_left
    type: custom:multiple-entity-row
    name: Keezer
    icon: mdi:beer
    show_state: false
    card_mod:
      style:
        hui-generic-entity-row $: ''
        .: |
          div.entity:nth-child(4) state-badge {
            animation: rotation_2 0.5s linear infinite;
          }
          @keyframes rotation_2 {
            0% {
              transform: rotate(0deg);
            }
            100% {
              transform: rotate(359deg);
            }
          }
    entities:
      - entity: sensor.plaato_keg_tap1_percent_beer_left
        name: Tap 1
      - entity: sensor.plaato_keg_tap2_percent_beer_left
        name: Tap 2
      - entity: sensor.plaato_keg_tap4_percent_beer_left
        name: Tap 4
      - entity: switch.keezer_socket_1
        name: Fan
        icon: mdi:fan
        state_color: true
        tap_action:
          action: toggle
          haptic: success
        

Since you deleted unneeded part described here, you do not need ā€œ.: |ā€ part:

      style:
        hui-generic-entity-row $: |

There are loads of examples here with templates.

          some_element {
            {% if ..... %}
            some_property: some_value;
            some_property: some_value;
            {% else %}
            some_property: some_value;
            some_property: some_value;
            {% endif %}
          }
          div.entity:nth-child(4) state-badge {
            {% if is_state(xxxxxxxxxxx,'on') %}
            animation: rotation_2 0.5s linear infinite;
            {% endif %}
          }
1 Like

Hereā€™s what I have now based on your help. But, my rotation doesnā€™t startup after the switch is turned on. Where did I go wrong?


type: entities
entities:
  - entity: sensor.plaato_keg_tap1_beer_left
    type: custom:multiple-entity-row
    name: Keezer
    icon: mdi:beer
    show_state: false
    card_mod:
      style:
        hui-generic-entity-row $: |
          div.entity:nth-child(4) state-badge {
            {% if is_state('switch.keezer_socket_1','on') %}
            animation: rotation_2 0.5s linear infinite;
            {% endif %}
          }
    entities:
      - entity: sensor.plaato_keg_tap1_percent_beer_left
        name: Tap 1
      - entity: sensor.plaato_keg_tap2_percent_beer_left
        name: Tap 2
      - entity: sensor.plaato_keg_tap4_percent_beer_left
        name: Tap 4
      - entity: switch.keezer_socket_1
        name: Fan
        icon: mdi:fan
        state_color: true
        tap_action:
          action: toggle
          haptic: success

is missing

Likely not the right spotā€¦since the fan doesnā€™t spin. :sweat_smile: If you can get me past this one thing, Iā€™ll likely be set with all the other good examples you have out there. Iā€™m just stuck at a dead end now. Where am I screwing up?

type: entities
entities:
  - entity: sensor.plaato_keg_tap1_beer_left
    type: custom:multiple-entity-row
    name: Keezer
    icon: mdi:beer
    show_state: false
    
    card_mod:
      style:
        hui-generic-entity-row $: |
          div.entity:nth-child(4) state-badge {
            {% if is_state('switch.keezer_socket_1','on') %}
            animation: rotation_2 0.5s linear infinite;
            @keyframes rotation_2 {
              0% {
                transform: rotate(0deg);
              }
              100% {
                transform: rotate(359deg);
              }
            }
            {% endif %}
          }
    entities:
      - entity: sensor.plaato_keg_tap1_percent_beer_left
        name: Tap 1
      - entity: sensor.plaato_keg_tap2_percent_beer_left
        name: Tap 2
      - entity: sensor.plaato_keg_tap4_percent_beer_left
        name: Tap 4
      - entity: switch.keezer_socket_1
        name: Fan
        icon: mdi:fan
        state_color: true
        tap_action:
          action: toggle
          haptic: success

Looking back at other examples, I tried this but it still isnā€™t working. Any ideas?


type: entities
entities:
  - type: custom:multiple-entity-row
    entity: sensor.plaato_keg_tap1_beer_left
    name: Keezer
    icon: mdi:beer
    show_state: false
    entities:
      - entity: sensor.plaato_keg_tap1_percent_beer_left
        name: Tap 1
      - entity: sensor.plaato_keg_tap2_percent_beer_left
        name: Tap 2
      - entity: sensor.plaato_keg_tap4_percent_beer_left
        name: Tap 4
      - entity: switch.keezer_socket_1
        name: Fan
        icon: mdi:fan
        state_color: true
        tap_action:
          action: toggle
          haptic: success
    card_mod:
      style:
        hui-generic-entity-row $: |
          div.entity:nth-child(4) state-badge {
            {% if is_state('switch.keezer_socket_1', 'on') %}
              animation: rotation 1s linear infinite;
            {% endif %}
          }
          @keyframes rotation {
            0% {
              transform: rotate(0deg);
            }
            100% {
              transform: rotate(360deg);
            }
          }

Just leave this:

      style: |
        div.entity:nth-child(4) state-badge {

That did it! Thanks. Putting final code here that works for spinning fan in multiple-entity-row cardā€¦


type: entities
entities:
  - type: custom:multiple-entity-row
    entity: sensor.plaato_keg_tap1_beer_left
    name: Keezer
    icon: mdi:beer
    show_state: false
    entities:
      - entity: sensor.plaato_keg_tap1_percent_beer_left
        name: Tap 1
      - entity: sensor.plaato_keg_tap2_percent_beer_left
        name: Tap 2
      - entity: sensor.plaato_keg_tap4_percent_beer_left
        name: Tap 4
      - entity: switch.keezer_socket_1
        name: Fan
        icon: mdi:fan
        state_color: true
        tap_action:
          action: toggle
          haptic: success
    card_mod:
      style: |
        div.entity:nth-child(4) state-badge {
          {% if is_state('switch.keezer_socket_1', 'on') %}
            animation: rotation 1s linear infinite;
          {% endif %}
        }
        @keyframes rotation {
          0% {
            transform: rotate(0deg);
          }
          100% {
            transform: rotate(360deg);
          }
        }

You do realize, that you have to support the correct answer by sending @Ildar_Gabdullin a home brewn beer, donā€™t you? :rofl: :rofl:

Thanks for sharing the final code. :slight_smile:

2 Likes

Please tell me how to duplicate css rules for identical elements.
Iā€™ll explain with an example.


I have mushroom-template-chip. For the first, the rules were created. How can I make it so that they are also created for the second mushroom-template-chip ?

1st post ā†’ link at the bottom ā†’ important notes about navigation

Thanks a lot. I figured it out)

So I have been able to completely change my dashboard with animations and icon color changes now. Thanks Ildar_Gabdullin! Iā€™ve seen a lot of text alignment changes, but I donā€™t see anything specific to collapsable-cards. Is it possible to reposition the text to align to the right using card-mod?

I have not provided examples since not using this card.
You may find out how to style this card and then post your tutorials here.

I was just about to edit my post with my first tryā€¦ here it is, but itā€™s not aligning the text to the right. Iā€™m trying to move the ā€œUpstairs Thermostatā€ text so it aligns to the rightā€¦ just to the left of the carrot.

  - type: custom:collapsable-cards
    title: Upstairs Thermostat
    buttonStyle: 'font-size: 14px;'
    card_mod:
      style: |
        ha-card div { align-items:right; }

This is a real noob question, and I know I must be missing something really simple, but I am failing to get a background image to a card when using a local file.

Iā€™ve tried using a url to an image on the web (eg. http://wwwā€¦), and that works fine. So it must be something about my local path Iā€™m getting wrong. Am running HA on a Raspberry Pi.

Here is my code, and also a screenshot of the file location

Any help would be greatā€¦ am pulling my hair out on something I know must be staring me in the face!

card_mod:
  style: |
    ha-card {
      background-repeat: no-repeat;
      background-image: url('/config/images/calendar.png');
      background-size: 100% 100%;
    }

Wrong.
Place your ā€œimagesā€ folder into ā€œwwwā€ folder, then use ā€œ/local/images/ā€¦ā€

1 Like

Ofcourse! Thank you, Iā€™ve been trying all sorts of things, and completely forgot about the www folder!

Thanks again, all working.

Hoping someone can point me in the right direction on this one, everything I try so far fails.

I want to have some buttons that show data from two sensors. Currently the only way I can see to do it is have two buttons in a vertical stack, and then somehow remove the border between them, making it visually look like one button.

Anyone got any thoughts on how this could be achieved? Basically, remove the gap between two cards in a vertical stack.

My current code:

square: true
columns: 4
type: grid
cards:
  - type: vertical-stack
    cards:
      - type: custom:button-card
        icon: mdi:water
        entity: sensor.water_softener_salt_level
        show_name: false
        show_state: true
      - type: custom:button-card
        icon: mdi:water
        entity: sensor.water_softener_water_used_today
        show_name: false
        show_state: true
        show_icon: false
  - type: vertical-stack
    cards:
      - type: custom:button-card
        icon: mdi:car-sports
        entity: sensor.model_y_battery_sensor
        show_name: false
        show_state: true
      - type: custom:button-card
        entity: sensor.model_y_range_sensor
        show_name: false
        show_state: true
        show_icon: false
  - type: vertical-stack
    cards:
      - type: custom:button-card
        icon: mdi:car-estate
        entity: sensor.model_y_battery_sensor
        name: xx %
        show_name: true
        show_state: false
      - type: custom:button-card
        entity: sensor.model_y_range_sensor
        name: xxx mi
        show_name: true
        show_state: false
        show_icon: false
  - type: vertical-stack
    cards:
      - type: custom:button-card
        entity: sensor.speedtest_download
        show_name: false
        show_state: true
      - type: custom:button-card
        entity: sensor.speedtest_upload
        show_name: false
        show_state: true
        show_icon: false

Note: The third column is currently a holder for a future vehicle, hence the code as it is.

you could probably use a custom:button-card with a grid, to show those 2 values vertically on 1 button. Did you check the grid options in advanced styling?
it would make it a button-card question though :wink: so check that thread too

1 Like