About old-style badges.
We can NOT use card-mod to style badges (neither old-style badges, nor new ones).
(ok, we can do it by using card-mod-theme which is TOO cumbersome and not as flexible as it could be; but this thread is not about themes)
The only place where we can style them - a custom badge-card.
There is a post about this card.
After 2024.8 it became a bit different:
Assume we have a card:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
- entity: sensor.xiaomi_cg_1_co2
To style a whole card - we used a mod-card :
type: custom:mod-card
card:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
- entity: sensor.xiaomi_cg_1_co2
card_mod:
...
To style a particular badge - we defined card-mod code below a particular entity (same what we could do for badges w/o badge-card):
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
- entity: sensor.xiaomi_cg_1_co2
card_mod:
...
(unrelated to card-mod) And we were able to customize a ānameā (also was supported for badges w/o badge-card):
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
- entity: sensor.xiaomi_cg_1_co2
name: xxxxxx
And same about changing an icon.
Now, after 2024.8:
- To show an old-style badge - we need to use āhui-state-badge-elementā:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- We still can use mod-card to style a whole card:
type: custom:mod-card
card:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
card_mod:
style:
badge-card:
$: |
div#badges {
--label-badge-background-color: cyan;
}
- We can NOT style a particular badge like we used to:
(update: we CAN with this fix)
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
card_mod: #does NOT work
style: |
ha-state-label-badge {
color: red;
}
We have to style from the cardās level (cumbersome):
type: custom:mod-card
card:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
card_mod:
style:
badge-card $:
hui-state-badge-element:nth-child(2) $:
ha-state-label-badge $:
ha-label-badge $: |
.badge-container .label-badge .label span {
border-style: dashed;
border-color: green;
color: white;
background-color: magenta;
font-size: 12px;
}
.badge-container .label-badge .value {
font-size: 8px;
}
.badge-container .label-badge {
border-radius: 20% !important;
border-style: dotted;
border-width: 10px
}
.badge-container .title {
color: orange;
}
.: |
ha-label-badge {
--label-badge-background-color: yellow;
--label-badge-text-color: red;
--label-badge-red: cyan;
--ha-label-badge-title-width: 170px;
--ha-label-badge-title-font-size: 8px;
--ha-label-badge-size: 100px;
}
- (unrelated to card-mod) We cannot use the ānameā option to change a displayed name (like for still supported badges in Picture elements card - probably that āhui-state-badge-elementā thing came from that card).
To change a name we have to use same way we use for Picture elements:
type: custom:mod-card
card:
type: custom:badge-card
badges:
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
- entity: sensor.xiaomi_cg_1_co2
type: custom:hui-state-badge-element
card_mod:
style:
badge-card $:
hui-state-badge-element:nth-child(2) $:
ha-state-label-badge $ ha-label-badge $ .badge-container: |
.title {
color: transparent;
line-height: 0px !important;
}
.title::before {
color: var(--primary-text-color);
content: "New name\A";
line-height: normal;
}
As for changing an icon - this might be possible by card-mod but too cumbersome.