New badges and card-mod customisation

hey Liquid

While you’re at it, could I tempt you to check 🔹 Card-mod - Super-charge your themes! - #2052 by Mariusthvdb?

Ive managed the badges nicely and they are customized the way I want, including borders box-shadows etc.

however, setting a box-shadow reveals the border of the section below the badges sharply when using the new scroll feature… without it, it is perfect.

Scrolling makes the section border quite visible directly under the box-shadowed badges.

please have a look if you can find the element we need to adjust to prevent that, I am not entirely sure which it even is, is it the section below, the set of badges…

2 Likes

Really nice work on the badges and the information you provided is robust!

It also helped me solve card-mod issues with Mushroom Template Badges.

I’ll definitely take a look!

1 Like

One method to consolidate…

card_mod:
  style:
    hui-entity-badge$:
      ha-badge$: |
        .badge {
          --card-mod-icon: {{'mdi:fan' if states(config.card.entity) |int(0) > 0 else 'mdi:fan-off' }};
          --card-mod-icon-color: {{'lime' if states(config.card.entity) |int(0) > 0 else 'grey' }};
           border: {{'1.5px solid lime !important' if states(config.card.entity) |int(0) > 0 else '1.5px solid grey !important' }};
            }
      .: |
        ha-state-icon {
          animation: {{ 'spin 1s linear infinite' if states(config.card.entity) |int(0) > 0 else 'none' }};
            }
         @keyframes spin {
           0% { transform: rotate(0deg);}
           100% {transform: rotate(359deg);}
            }
    .: |
      ha-card {
        background none; 
        border:none;
            }
1 Like

I’ve done a lot of searching and trying different things, but I haven’t been able to get card-mod to work with badges. It’s working fine for other elements on my dashboard.

Here’s the code to the top of the dashboard. Just some simple badges. I’d like to change the color and size of the name on each badge and I’d like to change the color of the border around the badges.

type: masonry
path: test
title: Test
cards: []
badges:
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: cover.ratgdov25i_1bdf3a_door
    name: L Garage
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: cover.ratgdov25i_1ba3c0_door
    name: M Garage
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    name: R Garage
    entity: cover.ratgdov25i_1ba3c8_door
    show_entity_picture: false
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: lock.side_door_lock
    name: Garage Lock
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: input_select.washing_machine_status
    name: Washer Status
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: input_select.dryer_status

Screenshot 2025-06-25 170308

I’ve also tried doing it with the mushroom badges template, but nothing seems to work. Any help would be appreciated.

2 Likes

Suggest to post a code with your attempts.

1 Like

Hi,

This certainly works, it gives you examples of a bit of everything : color, icon, border, animation, etc.

Hope it helps (this is the result of various explorations and tips from others in this thread)

type: masonry
path: test
title: Test
cards: []
badges:
  - type: custom:mod-card
    card:
      type: custom:mushroom-template-badge
      content: "{{ states.sensor.qcells_cloud_soc.state_with_unit }}"
      icon: >
        {% if states('sensor.qcells_cloud_battery_charge') | float(2) > 0 %} 
          mdi:battery-charging
        {% elif states('sensor.qcells_cloud_battery_discharge') | float(2) > 0 %} 
          mdi:battery-arrow-down
        {% elif states('sensor.qcells_cloud_soc') | float(2) < 11 %}  
          mdi:battery-10
        {%- else -%}  
          mdi:battery              
        {% endif %}
      color: >
        {% if states('sensor.qcells_cloud_battery_charge') | float(2) > 0 %} 
        Green
        {% elif states('sensor.qcells_cloud_battery_discharge') | float(2) > 0
        %}  DarkOrange
        {% elif states('sensor.qcells_cloud_soc') | float(2) < 11 %}   Red
        {%- else -%}   Green       
        {% endif %}
      entity: sensor.qcells_cloud_soc
      label: Solar Batt.
      tap_action:
        action: more-info
    card_mod:
      style:
        mushroom-template-badge:
          $: |
            ha-state-icon {
              {% if states('sensor.qcells_cloud_battery_charge') | float(2) > 0 %} 
                animation: pulse 2s ease-in-out infinite;
              {% elif states('sensor.qcells_cloud_battery_discharge') | float(2) > 0 %} 
                animation: pulse 2s ease-in-out infinite;
              {%- else -%}  
                animation: none;
              {% endif %}          
            }
            .badge::before {
              content: '';
              position: absolute;
              top: -1px;
              left: -1px;
              right: -1px;
              bottom: -1px;
              border: 3px solid var(--badge-color);
              border-radius: inherit;
              mask: conic-gradient(rgba(0, 0, 0, 1) 0% {{states('sensor.qcells_cloud_soc')}}%, rgba(0, 0, 0, 0) {{states('sensor.qcells_cloud_soc')}}% 100%);
            }


            @keyframes pulse {
              0% {
                transform: scale(1);
                opacity: 0.7;
              }
              50% {
                transform: scale(1.2);
                opacity: 1;
              }
              100% {
                transform: scale(1);
                opacity: 0.7;
              }
            }
        .: |
          ha-card {
            background: none;
            border: none;
              }

1 Like

Thank you! Using pieces of your code I got the border to change to black and 2px. I didn’t need all the other fancy stuff. :grin:

So this is what I have now:

type: masonry
path: test
title: Test
cards: []
badges:
  - type: custom:mod-card
    card:
      type: custom:mushroom-template-badge
      content: "{{states('cover.ratgdov25i_1bdf3a_door') | capitalize  }}"
      icon: |
        {% if is_state('cover.ratgdov25i_1bdf3a_door', 'closed') %}
          mdi:garage
        {% else %}
          mdi:garage-open
        {% endif %}
      color: grey
      entity: cover.ratgdov25i_1bdf3a_door
      label: L Garage
    card_mod:
      style:
        mushroom-template-badge:
          $: |
            .badge::before {
              content: '';
              position: absolute;
              top: -1px;
              left: -1px;
              right: -1px;
              bottom: -1px;
              border: 2px solid black;
              border-radius: inherit;
              #mask: conic-gradient(rgba(0, 0, 0, 1) 0% {{states('sensor.qcells_cloud_soc')}}%, rgba(0, 0, 0, 0) {{states('sensor.qcells_cloud_soc')}}% 100%);
            }
        .: |
          ha-card {
            background: none;
            border: none;
              }
  - type: entity
    show_name: true
    show_state: true
    show_icon: true
    entity: cover.ratgdov25i_1bdf3a_door
    name: L Garage

Screenshot 2025-06-25 181055

How do I change the size and color of the name?

Basically, I’m trying to make most things black because I’m using it on an 2-color eink screen and it shows up better as black instead of grey.

1 Like

Replace the last block with the following (I used green as a target color):

      ha-card {
        background: none;
        border: none;
        --secondary-text-color: green;
          }

1 Like

Thank you so much for your help! Only thing left is the font size. Do you know how to change that for both the name and the content (‘L Garage’ and ‘Closed’ in my screenshot.)?

I tried:

      ha-card {
        background: none;
        border: none;
        --secondary-text-color: black;
        --secondary-font-size: 20px;
          }

but it didn’t work.

2 Likes

I did some more searching and did a quick primer on CSS and figured out where to change the fonts. Now weather it’s “correct” or not, I don’t know, but it’s working. :grin:

Here’s the code in case someone else is searching.

type: masonry
path: test
title: Test
cards: []
badges:
  - type: custom:mod-card
    card:
      type: custom:mushroom-template-badge
      content: "{{states('cover.ratgdov25i_1bdf3a_door') | capitalize  }}"
      icon: |
        {% if is_state('cover.ratgdov25i_1bdf3a_door', 'closed') %}
          mdi:garage
        {% else %}
          mdi:garage-open
        {% endif %}
      color: grey
      entity: cover.ratgdov25i_1bdf3a_door
      label: L Garage
    card_mod:
      style:
        mushroom-template-badge:
          $: |
            .badge {
              --divider-color: black;
              --ha-card-border-width: 2px;
              .info {
                .label {
                  font-size: 12px;
                  --secondary-text-color: black;
                }
                .content {
                  font-size: 14px;
              }
            }        
        .: |
          ha-card {
            background: none;
            border: none;
          }

2 Likes

We had progress borders, we had progress backgrounds and we had animations. So I thought I’d try an animated background :smile:

image

The gif is of poor quality … looks much better in HA

        {% set rgb1 = 'rgb(from #6495ED r g b / 0.2)' %}

        .badge::before {
          content: '';
          position: absolute;
          top: -1px;
          left: -1px;
          right: -1px;
          bottom: -1px;
          border: 0px solid var(--badge-color);
          border-radius: inherit;
          background: linear-gradient(90deg,{{rgb1}} 0%,{{rgb1}} 40%,#ffffff,{{rgb1}} 60%,{{rgb1}} 100%);
          background-size: 250% 100%;
          mask: linear-gradient(to right, #ffffff {{perc}}%, transparent 0);
          animation: BackgroundGradient 3s ease infinite;
        }

        @keyframes BackgroundGradient {
          0% {background-position: 100% ;}
          100% {background-position: 0%;}
        }
2 Likes

Cool stuff :sunglasses:

Yeah, very pleased with the result. I added a tiny border and switched to ghostwhite for the animation and now it looks perfect.

trim.B31EB365-B51E-4CA2-833E-3DB2E873E072

card_mod for the mushroom template badge showing battery SoC visually (animated when charging - both the mask and background depend on SoC for consistent effect and speed)

        {% set perc = states('your_battery_sensor') | float(0)
        %}

        .badge::before {
          content: '';
          position: absolute;
          top: -1px;
          left: -1px;
          right: -1px;
          bottom: -1px;
          border-radius: inherit;
          
          {% if states('your_battery_sensor') == "Charging" %}

          {% set chargingcolor = '#20B2AA' %} 
          {% set chargingcolorlight = 'rgb(from ' + chargingcolor + ' r g b / 0.2)' %} 
          {% set chargingcolorverylight = 'rgb(from ' + chargingcolorlight + ' r g b / 0.05)' %}
          {% set animationcolor = '#F8F8FF' %}
          
          border: 0.5px solid {{ chargingcolor }};
          background: linear-gradient(90deg,{{chargingcolorlight}} 0%,{{chargingcolorlight}} 35%,{{chargingcolorverylight}} 47%, {{ animationcolor }},{{chargingcolorverylight}} 53%, {{chargingcolorlight}} 65%,{{chargingcolorlight}} 100%);
          animation: BackgroundGradient {{(2 * perc + 50) / 250 * 3}}s ease infinite;
          
          {% else %}

          {% set chargecolor = '#6495ED' %}           
          {% set chargecolorlight = 'rgb(from ' + chargecolor + ' r g b / 0.2)' %} 
          {% set opacityzero = 'rgb(from ' + chargecolor + ' r g b / 0)' %}
          
          border: 0.25px solid {{ chargecolor }};
          background: linear-gradient(to right, {{chargecolorlight}} 0%, {{chargecolorlight}} {{perc}}%, {{opacityzero}} {{perc}}%, {{opacityzero}} 100%) !important;
          
          {% endif %}

          background-size: {{2 * perc + 50}}% 100%;
          mask: linear-gradient(to right, white {{perc}}%, transparent 0);          
        }


        @keyframes BackgroundGradient {
          0% {background-position: 100% ;}
          100% {background-position: 0%;}
        }

1 Like

Are you still looking for this syntax? Not sure what exactly you were missing but this works for me. Now I plan to generalise this in an include so the alpha corrections and positions are calculated on the fly, depending on number of stops - I might have overdone it a little below :slight_smile: - and desired easing function (in, out or in-out):

btw, I got the idea for this crazy long gradient here Easing Gradients and have to admit, even on a small badge, the difference is noticeable so now applying this trick in other places (hence the need to turn this into an include …)

{% set gradientcolor = 'var(--badge-color)' %} 
{% set alpha = 0.5 %}
{% set startgradient = 0 %}
{% set endgradient = 100 %}

background: linear-gradient(90deg,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 1.000) | string + ' )'}} 0%, 
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 1.000) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 00.0 / 100}}%, 
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.925) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 09.5 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.857) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 17.7 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.781) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 24.7 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.701) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 31.0 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.620) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 36.8 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.538) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 42.3 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.455) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 47.6 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.373) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 52.9 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.291) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 58.2 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.212) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 63.7 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.138) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 69.5 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.070) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 75.8 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.019) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 91.2 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.000) | string + ' )'}} {{startgradient + (endgradient - startgradient) * 100 / 100}}%,
            {{'rgb(from ' + gradientcolor + ' r g b / ' + (alpha * 0.000) | string + ' )'}} 100%
          );
          

Gosh so frustrating, the 2024.8 update brought a shitload of “improvements” (what’s the opposite of that?) regarding the new badges. I only see downsides. Biggest ones:

  1. Consume significantly more space
  2. While at the same time being hardly readable (text size is so so small and not configurable!)
  3. Color only on icon, not for text or state
  4. No possibility to style them (colored borders, custom UoM)
  5. Config options like show_icon etc. only work in special view types, not in the masonry default

I don’t see any option AT ALL to regain what I had before with e. g.

Spent already 1.5 hours. Thanks HA team for “streamlining” stuff forcing people to put their year long hard work to the trash bin. /angry-mode-off


UPDATE: I went the long long loooong way (with spending in total almost 6 hours of a rainy weekend day) and migrated all badges to card-mod with mushroom template badge.

So far I could achieve almost every function I had before like

  • colored borders
  • larger state font size
  • dynamic styling (icon, border and text colors) based on entity/attributes states

Comparison:

  1. Before until 2024.7
  2. New default badges (optimized, directly after migration they were ugly as hell)
    grafik
  3. Final custom solution
    3.1 Normal state
    grafik
    3.2 Error/outage simulation
    grafik

As you can see one last part is missing: styling the whole badge background (yellow) in case of an outage. Currently I only managed to target certain parts of the badge (label and state). Is there a solution for this?
→ Edit: solved now too with --card-background-color: yellow; in .badge. Screenshot updated.

So one more custom component (Mushroom cards) instead of relying on the default which is a bit meh, but the advantages of the core default were just too big. No dynamic styling, way too small state font size, not even colored borders etc. etc. etc… Happy for now.

1 Like

Hi, I am trying to customise the style of the mushroom-template-badge.
The only way (so far) is to wrap in custom: mod-card e.g.

type: custom:mod-card
card:
  type: custom:mushroom-template-badge
  content: |-
    {% if is_state('light.stairled_hk', 'on') %}
      On
    {% else %}
      Off
    {% endif %}
  entity: light.stairled_hk
  icon: mdi:led-strip-variant
  label: Stair LED
  color: |-
    {% if is_state('light.stairled_hk', 'on') %}
      amber 
    {% endif %}
card_mod:
  style: |

    ha-card {
       background-color:none;
       border-radius: 30px;
       {% if is_state('light.stairled_hk', 'on') %}
       border: solid 4px #FF9800;
       {% else %}
       border:solid 4px #303446;
       {% endif %}
     }

I get a little red dot in top left corner when the light is “ON”?

  1. How did you get card_mod to work on the mushroom-template-badge badge(for background colour) in your 3.2 example.
  2. IF you have done the same as me, do you get a red dot?

I’m new to this forum, so go gentle with me.

Welcome to the forum :slight_smile:

No red dots for me.

The background is done with this in the .badge section: --card-background-color: yellow;

card_mod:
  style:
    mushroom-template-badge:
      $: |
        .badge {
          {% if not (states('sensor.power_current_consumption_total') | is_number) -%}
          --divider-color: red;
          --ha-card-border-width: 3px;
          --card-background-color: yellow;
          {% else %}
          --divider-color: #ff5722;
          #--ha-card-border-width: 2px;
          {% endif %}
          .info {
            .label {
              #font-size: 12px;
              {% if not (states('sensor.power_current_consumption_total') | is_number) -%}
              --secondary-text-color: red;
              #background-color: yellow;
              {% else %}
              {% endif %}
            }
            .content {
              font-size: 15px;
              {% if not (states('sensor.power_current_consumption_total') | is_number) -%}
              color: red;
              #background-color: yellow;
              {% else %}
              #color: #ff5722;
              {% endif %}
          }
        }
    .: |
      ha-card {
        background: none;
        border: none;
      }

Note to myself read whole post LOL

Just read a previous post and realised what i was doing wrong, just as you posted. Like you said this stuff can get frustrating, especially when you are me and you don’t like to read lol

Thanks for sharing, i will have a go now.

UPDATE: success but still getting red dot??
Further UPDATE: the dot has gone. It was the remnants of a failed attempt which was causing the dot.

Screenshot 2025-07-27 150007

type: custom:mod-card
card:
  type: custom:mushroom-template-badge
  content: |-
    {% if is_state('light.stairled_hk', 'on') %}
      On
    {% else %}
      Off
    {% endif %}
  entity: light.stairled_hk
  icon: mdi:led-strip-variant
  label: Stair LED
  color: |-
    {% if is_state('light.stairled_hk', 'on') %}
      amber 
    {% endif %}
card_mod:
  style:
    mushroom-template-badge:
      $: |
        .badge {
            {% if is_state('light.stairled_hk', 'on') %}
            --ha-card-border-width: 1px;
            --ha-card-border-color: var(--amber-color);
            --ha-card-background: rgba(255, 193, 6, 0.3);         
            {% endif %}
          }
          .info {
              .label {
                font-size: 12px;            
              }
              .content {
                font-size: 15px;
            }
          }
      .: |
        ha-card {
          background: none;
          border: none;
        }

Ok, just have to do the rest now…another day i reckon.

use config.entity in that template, and you can just c&p the card_mod to all the others… :wink: