lovelace-card-mod: 2024.8 style badge styling doesn't work

My Home Assistant version: 2024.8

My lovelace configuration method (GUI or yaml): GUI

What I am doing: using card mod in theme to style badges

What I expected to happen: style badges 😄

What happened instead: nothing

Minimal steps to reproduce: try anything in card-mod-badge-yaml:

  card-mod-badge-yaml: |
    .badge {
        padding: 2px 8px !important;
        border-radius: 0px !important;
    }

Doesn’t get attached to badge shadow root at all

Error messages from the browser console:

VM13847:1  Uncaught (in promise) SyntaxError: "undefined" is not valid JSON
    at JSON.parse (<anonymous>)
    at s.<anonymous> (card-mod.js:1:48199)
    at d (card-mod.js:1:2813)
    at Generator.<anonymous> (card-mod.js:1:4159)
    at Generator.next (card-mod.js:1:3242)
    at y (card-mod.js:1:8728)
    at a (card-mod.js:1:8931)
    at card-mod.js:1:8990
    at new Promise (<anonymous>)
    at s.<anonymous> (card-mod.js:1:8871)

Not sure if the error is relevant but I included it anyways.


By putting an X in the boxes ([]) below, I indicate that I:

  • Understand that this is a channel for reporting bugs, not a support forum (https://community.home-assistant.io/).

  • Have made sure I am using the latest version of the plugin.

  • Have followed the troubleshooting steps of the “Common Problems” section of https://github.com/thomasloven/hass-config/wiki/Lovelace-Plugins.

  • Understand that leaving one or more boxes unticked or failure to follow the template above may increase the time required to handle my bug-report, or cause it to be closed without further action.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 6
  • Comments: 18 (3 by maintainers)

Most upvoted comments

this is a full example of how card_mod (and its companion mod-card) are needed to style the new badges:

type: custom:mod-card
card:
  type: custom:hui-entity-badge
  entity: sensor.lightning_strikes_near_time
  color: rgb(231,92,9)
  hold_action:
    action: navigate
    navigation_path: /ui-overzicht/weer
visibility:
  - condition: numeric_state
    entity: sensor.lightning_strikes_near_time
    above: 0
card_mod:
  style:
    hui-entity-badge:
      $:
        ha-badge:
          $: |
            .badge {
              border: 2px solid var(--badge-color) !important;
            }
        .: |
          ha-state-icon {
            --mdc-icon-size: 24px;
            --card-mod-icon-color: var(--badge-color);
            animation: blink 2s ease infinite;
          }
          @keyframes blink {
            50% {opacity: 0.2;}
          }
          state-display {
            font-size: 14px;
            color: var(--badge-color);
          }
    .: |
       hui-entity-badge {
        --ha-card-background: rgb(18,46,129);
       }

or one using state-colors:

#badge alarm control panel
type: custom:mod-card
card:
  type: custom:hui-entity-badge
  entity: alarm_control_panel.ha_main_alarm
# visibility:
#   - condition: state
#     entity: alarm_control_panel.ha_main_alarm
#     state_not: disarmed
card_mod:
  style:
    hui-entity-badge:
      $:
        ha-badge:
          $: |
            {% set state = states(config.card.entity) %}
            .badge {
              border: 2px solid var(--state-alarm_control_panel-{{state}}-color) !important;
            }

it’s is not a bug as explained above, but a new element, and we needed to find the optimal way to touch all elements in the badge.

with that you should close the current issue, since the styling does work correctly, and if you require more, hop over to the community for support

@AdmiralStipe It is NORMAL to be inexperienced in smth. Suggest you to do 2 things: – wait - may be someone in Community will post smth useful – learn - on simple examples, check the link I provided (man, I never ever ever dealt with CSS, learned from zero - and issued tutorials, one by one - learned again - improved tutorials - and so on)

As for “nobody solved yet” - possible reasons are: – badges are not commonly used – people are consumers, not creators

yeah, I am still crossing my fingers Thomas can reintroduce the 3.5.0 features at some point. As a matter of fact, I never upgraded to 3.4.4 and still use 3.5.0 and all of its features. (mainly the removal of mod-card has simplified things a lot)

only thing that doesnt work anymore is card-mod settings to auto-entities cards, so I rewrote those configs.

cut it short: I do hope a future version brings back the features of 3.5.0, and at the same time would introduce support for the new hui-view-header, see https://community.home-assistant.io/t/card-mod-super-charge-your-themes/212176/1977?u=mariusthvdb

@mikosoft83 Maybe try something inspired by

  card-mod-view-yaml: |
    hui-masonry-view $:
      hui-view-badges $:
        ha-sortable:
          hui-badge:nth-child(n):
            hui-entity-badge $: |
              .badge {
                background-color: rgb(255,0,0) !important;
              }

image

Yes, I do somthing similar but I still reported this since the badge itself is exposed to card-mod theming.

same issue