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

No worries jsut looking for clarification. You aren’t seeing this in the GUI editor?

  type: horizontal-stack
  cards:
    - type: custom:mushroom-template-card
      primary: |-
        {% set time = now().hour %}
        {% if (time >= 18) %}
          Jó estét, {{ user }}
        {% elif (time >= 12) %}
          Kellemes délutánt, {{ user }}
        {% elif (time >= 5) %}
          Jó reggelt, {{ user }}
        {% elif (time >= 8) %}
          Kellemes napot, {{ user }}
        {% else %}
          Jó éjszakát, {{ user }}
        {% endif %}
      secondary: >
        {% set alarm_state =
        states('alarm_control_panel.partition_area_1') %} {% if
        alarm_state == 'disarmed' %}
          A riasztó állapota: Hatástalanítva
        {% elif alarm_state == 'armed_away' %}
          A riasztó élesítve: Távol
        {% elif alarm_state == 'armed_night' %}
          A riasztó élesítve: Éjszakai
        {% else %}
          {{ alarm_state }}
        {% endif %}
      icon: mdi:home
      tap_action:
        action: navigate
        navigation_path: /dashboard-kezelfelulet/info
      picture: ''
      badge_color: >
        {% if is_state('alarm_control_panel.partition_area_1','disarmed')
        %}
          blue
        {% endif %}

        {% if
        is_state('alarm_control_panel.partition_area_1','armed_away') %}
          red
        {% endif %}

        {% if
        is_state('alarm_control_panel.partition_area_1','armed_night') %}
          green
        {% endif %}

        {% if
        is_state('alarm_control_panel.partition_area_1','armed_stay') %}
          orange
        {% endif %}
      badge_icon: mdi:shield-home
      icon_color: cyan
      multiline_secondary: true
      fill_container: true
      card_mod:
        style:
          mushroom-state-info$: |
            .container {
              align-items: end;
            }
          .: |
            ha-card {
              box-shadow: 5px 10px 5px -3px rgba(0,0,0,0.75) !important;
              width: 250px;
            }

Do you believe that many endifs are necessary or even proper? Does something like this work as well?

badge_color: |
      {% if is_state('alarm_control_panel.partition_area_1','disarmed') %}
        blue
       {% elif is_state('alarm_control_panel.partition_area_1','armed_away') %}
        red
      {% elif is_state('alarm_control_panel.partition_area_1','armed_night') %}
        green
      {% elif is_state('alarm_control_panel.partition_area_1','armed_stay') %}
        orange
      {% else %} 
       lime
      {% endif %}

If the AI was taken from you, would you actually know how to fix it? You are only as powerful as the machine that controls you…

The question was in this piece of code
read the question carefully

I’m not wasting another minute on you. :rofl: You missed the question…

1 Like

I can see the “card-mod” section in the RAW editor, but not in the GUI editor.

no need to write spam

Can you see this code if entered into an individual card?

image

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    primary: |-
      {% set time = now().hour %}
      {% if (time >= 18) %}
        Jó estét, {{ user }}
      {% elif (time >= 12) %}
        Kellemes délutánt, {{ user }}
      {% elif (time >= 5) %}
        Jó reggelt, {{ user }}
      {% elif (time >= 8) %}
        Kellemes napot, {{ user }}
      {% else %}
        Jó éjszakát, {{ user }}
      {% endif %}
    secondary: >
      {% set alarm_state = states('alarm_control_panel.partition_area_1') %} {%
      if alarm_state == 'disarmed' %}
        A riasztó állapota: Hatástalanítva
      {% elif alarm_state == 'armed_away' %}
        A riasztó élesítve: Távol
      {% elif alarm_state == 'armed_night' %}
        A riasztó élesítve: Éjszakai
      {% else %} 
        {{ alarm_state }}
      {% endif %}
    icon: mdi:home
    tap_action:
      action: navigate
      navigation_path: /dashboard-kezelfelulet/info
    picture: ''
    badge_color: |
      {% if is_state('alarm_control_panel.partition_area_1','disarmed') %}
        blue
       {% elif is_state('alarm_control_panel.partition_area_1','armed_away') %}
        red
      {% elif is_state('alarm_control_panel.partition_area_1','armed_night') %}
        green
      {% elif is_state('alarm_control_panel.partition_area_1','armed_stay') %}
        orange
      {% else %} 
       lime
      {% endif %}
    badge_icon: mdi:shield-home
    icon_color: cyan
    multiline_secondary: true
    fill_container: true
    card_mod:
      style:
        mushroom-state-info$: |
          .container {
            align-items: end;
          }
        .: |
          ha-card {
            box-shadow: 5px 10px 5px -3px rgba(0,0,0,0.75) !important;
            width: 250px;
          }

Based on the states checking you used in the other post both filters AI added are not needed. The states are already in lowercase and do not have spaces.

        background: url('/local/images/moon/{{states('sensor.moon_phase')}}.png');

Does exactly the same in your case :wink:

3 Likes

I see this:

type: horizontal-stack
cards:
  - type: custom:mushroom-template-card
    primary: |-
      {% set time = now().hour %}
      {% if (time >= 18) %}
        Jó estét, {{ user }}
      {% elif (time >= 12) %}
        Kellemes délutánt, {{ user }}
      {% elif (time >= 5) %}
        Jó reggelt, {{ user }}
      {% elif (time >= 8) %}
        Kellemes napot, {{ user }}
      {% else %}
        Jó éjszakát, {{ user }}
      {% endif %}
    secondary: >
      {% set alarm_state = states('alarm_control_panel.partition_area_1') %} {%
      if alarm_state == 'disarmed' %}
        A riasztó állapota: Hatástalanítva
      {% elif alarm_state == 'armed_away' %}
        A riasztó élesítve: Távol
      {% elif alarm_state == 'armed_night' %}
        A riasztó élesítve: Éjszakai
      {% else %}
        {{ alarm_state }}
      {% endif %}
    icon: mdi:home
    tap_action:
      action: navigate
      navigation_path: /dashboard-kezelfelulet/info
    picture: ''
    badge_color: |
      {% if is_state('alarm_control_panel.partition_area_1','disarmed') %}
        blue
      {% endif %}
      {% if is_state('alarm_control_panel.partition_area_1','armed_away') %}
        red
      {% endif %}
      {% if is_state('alarm_control_panel.partition_area_1','armed_night') %}
        green
      {% endif %}
      {% if is_state('alarm_control_panel.partition_area_1','armed_stay') %}
        orange
      {% endif %}
    badge_icon: mdi:shield-home
    icon_color: cyan
    multiline_secondary: true
    fill_container: true

Probably you are facing a known issue “cardmod code not shown in Editor”.
Happens with SOME cards.
Check github, the issue is registered.

Btw, I do not suggest using storage-mode for main dashboards, only for testing.

1 Like

I didn’t notice the “endif” errors, thanks for pointing that out.

Can someone please help me changing the color for the expander card? For some reason it’s white and my browser but for this card only it shows up blue on my iPhone.

type: custom:expander-card
gap: 0.6em
padding: 1em
clear: false
title: Expander
overlay-margin: 2em
child-padding: 0.5em
button-background: transparent

I just want card mod to force the icon white nothing seems to work

try a bit tidied up:

      {% set alarm = states('alarm_control_panel.partition_area_1') %}
      {% set color = {'disarmed':'blue','armed_away':'red','armed_night':'green',
                      'armed_stay':'orange'} %}
      {{color.get(alarm,'yellow')}}

note Ive added a default ‘yellow’, in case the alarm panel is in a state not defined in your color scheme

1 Like

Köszönöm! Minden egyszerűsítést szívesen fogadok.

Can someone help me correct this code? This worked fine in version 3.2.1 but every version after, it doesn’t… strange thing is, one out of three times it works as expected, but mostly does not. In edit mode it shows as I want it though.

cardmod

On top, the edit mode as it should be. Bottom is what it looks like in normal mode. Just for clarification, the + sign should be aligned right.

    card_mod:
      style:
        hui-horizontal-stack-card $: |
          div#root > :first-child {
            width: 66%;
            flex: auto; 
          }
          div#root > :last-child {
            width: 34%;
            flex: auto;
            display: flex;
            justify-content: flex-end;
          }

Try/use this instead:

    card_mod:
      style:
        hui-horizontal-stack-card:
          $: |
            div#root > :first-child {
              width: 66%;
              flex: auto; 
            }
            div#root > :last-child {
              width: 34%;
              flex: auto;
              display: flex;
              justify-content: flex-end;
            }
1 Like

Thanks so much Liquid_cooled!

That was it! Spent way too much time trying to figure this one out, much appreciated!!

I have tried everything to get this little arrow to change colors on Expander-Card. Ad you can see it’s red on the edit screen. But as soon as I hit save, no card_mod changes show up. Yes I have cleared cache and tried browser and phone


pic2

type: custom:expander-card
gap: 0.6em
padding: 1em
clear: false
title: Expander
overlay-margin: 2em
child-padding: 0.5em
button-background: transparent
expanded: false
card_mod:
  style:
    .: |
      :host {
        --icon-primary-color: red;
        --secondary-background-color: rgba(0,0,0,0.5);
        --ha-card-background: rgba(0,0,0,0.5);
      }