Styling custom:numberbox-card
:
code
type: entities
entities:
- type: section
label: colored icon (2 options)
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
:host {
--paper-item-icon-color: red;
}
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
state-badge {
color: cyan;
}
- type: section
label: colored text
- type: custom:numberbox-card
entity: input_number.test_parrots
secondary_info: last-changed
card_mod:
style: |
.grid-content.grid-left {
color: red;
}
.grid-content.grid-right {
color: magenta;
}
.grid-content.grid-left .secondary {
color: cyan;
}
- type: custom:numberbox-card
entity: input_number.test_parrots
secondary_info: default color
card_mod:
style: |
.grid-content.grid-left {
color: red;
}
.grid-content.grid-left .secondary {
color: initial;
}
- type: section
label: colored buttons, value & unit
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padr {
color: red;
}
.body .padl {
color: cyan;
}
.body .cur-num {
color: orange;
}
- type: section
label: colored value & opaque unit (diff.colors)
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .cur-num {
color: orange;
}
.body .cur-unit {
color: cyan;
opacity: 1;
}
- type: section
label: spacings
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padr {
padding-right: 32px;
}
.body .padl {
padding-left: 32px;
}
.body .cur-unit {
margin-left: 32px;
}
- type: section
label: Full width
- type: custom:numberbox-card
entity: input_number.test_parrots
icon: false
name: false
card_mod:
style: |
.body .cur-box {
display: grid;
grid-template-columns: 1fr 10fr 1fr;
place-items: center;
}
- type: section
label: Bordered row
- type: custom:numberbox-card
entity: input_number.test_parrots
name: Bordered row
border: true
card_mod:
style: |
:host {
--ha-card-box-shadow: 5px 5px 8px red, 10px 10px 8px green, 5px 5px 8px blue;
}
Changed āon-editā color:
Summary
type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .cur-num {
color: cyan;
}
.body .upd {
color: magenta;
}
.body .cur-unit {
color: red;
}
Vertically aligned buttons:
code
type: horizontal-stack
title: 1 column
cards:
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: start;
}
.body .padr {
padding-left: 0px;
}
.body .padl {
padding-left: 0px;
}
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: center;
}
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: end;
}
.body .padr {
padding-right: 0px;
}
.body .padl {
padding-right: 0px;
}
Vertical spacing for buttons:
code
type: horizontal-stack
title: 1 column, vertical spacing
cards:
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: center;
}
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: center;
}
.body .padl {
padding-bottom: 0px;
}
.body .padr {
padding-top: 0px;
}
- type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_parrots
name: false
icon: false
card_mod:
style: |
.body .cur-box {
display: grid;
place-items: center;
}
.body .padl {
padding-bottom: 32px;
}
.body .padr {
padding-top: 32px;
}
Horizontal alignment for buttons & values:
code
type: entities
entities:
- type: custom:numberbox-card
entity: input_number.test_number
name: Threshold 1
- type: custom:numberbox-card
entity: input_number.test_number_2
name: Threshold 2
- type: custom:numberbox-card
entity: input_number.test_number_3
name: Threshold 3
card_mod:
style:
numberbox-card:
$: |
ha-card .body .cur-num-box {
display: grid;
width: 50px;
text-align: center;
}
Custom secondary_info
:
Update 03.01.22: since ver. 3.2 it is possible to specify a plain text for secondary_info
, so this trick is not required any more - at least for making a custom secondary_info
. Note that conditional content in "secondary-info"
is still possible only by using card-mod & ā:beforeā method.
code
type: entities
entities:
- type: custom:numberbox-card
entity: input_number.wait_period_before_alarm_1_xiaomi_roborock_s50_mop_check
name: Threshold 1
secondary_info: last-changed
card_mod:
style: |
.grid-content.grid-left .info .secondary ha-relative-time {
color: transparent;
}
.grid-content.grid-left .info .secondary::before {
color: orange;
content: "Warning";
}
- type: custom:numberbox-card
entity: input_number.wait_period_before_alarm_2_xiaomi_roborock_s50_mop_check
name: Threshold 2
secondary_info: last-changed
card_mod:
style: |
.grid-content.grid-left .info .secondary ha-relative-time {
color: transparent;
}
.grid-content.grid-left .info .secondary::before {
color: red;
content: "Critical\A Danger";
white-space: pre;
}
How to disable buttons:
code
type: entities
title: Locked control
entities:
- entity: input_boolean.test_boolean
name: Lock input_number
- type: custom:numberbox-card
entity: input_number.test_parrots
tap_action: none
card_mod:
style: |
.body .padl {
{% if is_state('input_boolean.test_boolean','on') %}
color: var(--disabled-text-color);
{% endif %}
}
.body .padr {
{% if is_state('input_boolean.test_boolean','on') %}
color: var(--disabled-text-color);
{% endif %}
}
:host {
{% if is_state('input_boolean.test_boolean','on') %}
pointer-events: none;
{% endif %}
}
How to disable whole row (a case with a toggle button):
code
- type: custom:numberbox-card
entity: input_number.test_parrots
toggle_entity: input_boolean.test_boolean_2
card_mod:
style:
ha-entity-toggle $:
ha-switch $: |
.mdc-switch .mdc-switch__thumb input {
{% if is_state('input_boolean.test_boolean','on') %}
pointer-events: none;
{% endif %}
}
.: |
ha-switch {
{% if is_state('input_boolean.test_boolean','on') %}
--switch-unchecked-button-color: var(--disabled-text-color);
--switch-checked-button-color: var(--disabled-text-color);
{% endif %}
}
.: |
.padl {
{% if is_state('input_boolean.test_boolean','on') %}
color: var(--disabled-text-color);
{% endif %}
}
.padr {
{% if is_state('input_boolean.test_boolean','on') %}
color: var(--disabled-text-color);
{% endif %}
}
:host {
{% if is_state('input_boolean.test_boolean','on') %}
pointer-events: none;
color: var(--disabled-text-color);
--paper-item-icon-color: var(--disabled-text-color);
{% endif %}
}
.grid-content {
{% if is_state('input_boolean.test_boolean','on') %}
color: var(--disabled-text-color);
{% endif %}
}
Colored background:
By default the background is not transparent.
There are a few ways to make it transparent as well as to change a color:
code
type: entities
title: background
card_mod:
style: |
ha-card {
background: orange;
}
entities:
- type: section
label: default
- entity: sun.sun
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
label: colored background
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
ha-card {
background: pink;
}
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.grid {
background: pink;
}
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
:host {
--ha-card-background: pink;
}
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
ha-card {
--ha-card-background: pink;
}
- type: section
label: transparent background
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
ha-card {
background: transparent;
}
Changing a size of āplusā & āminusā icons:
May be achieved by specifying an "--mdc-icon-size"
variable.
To decrease the size for both icons:
code
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body {
--mdc-icon-size: 10px;
}
To decrease the size for one icon only:
code
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padr {
--mdc-icon-size: 8px;
}
To increase the size a user must be aware of top & bottom padding - otherwise the row may be higher than other rows; the rowās height should not be higher than 40px - i.e the iconsā height should not be higher than 40px.
Check this example:
code
type: horizontal-stack
cards:
- type: entities
entities:
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padr {
--mdc-icon-size: 8px;
}
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padl {
--mdc-icon-size: 8px;
}
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padl {
--mdc-icon-size: 40px;
}
- type: section
- type: entities
entities:
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
Here is how to fix the rowās height by setting zero "padding-top"
& "padding-bottom"
:
code
type: horizontal-stack
cards:
- type: entities
entities:
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padr {
--mdc-icon-size: 8px;
}
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padl {
--mdc-icon-size: 8px;
}
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padl {
--mdc-icon-size: 40px;
padding-top: 0px;
padding-bottom: 0px;
}
- type: section
- type: entities
entities:
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
- type: custom:numberbox-card
entity: input_number.test_parrots
- type: section
Another solution (simpler & more elegant) was provided by the author of this card here:
scale both icons:
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body ha-icon {
transform: scale(2);
}
scale one icon:
- type: custom:numberbox-card
entity: input_number.test_parrots
card_mod:
style: |
.body .padl {
transform: scale(2);
}
This method does not require changing paddings!
More examples are described here.