Battery state card for Home Assistant
[![GitHub Release][releases-shield]][releases] [![GitHub All Releases][downloads-total-shield]][releases] [![hacs_badge][hacs-shield]][hacs] [![Community Forum][forum-shield]][forum] [![Buy me a coffee][coffee-shield]][coffee-link]
Battery state card for Home Assistant. It shows battery levels from connected devices (entities).
This card was inspired by another great card showing the battery states. I have decided to implement my own as there was no response for pull requests from author and I wanted to fix few things and also add couple new features.
Update to v4.X.X
The display entity data field has been renamed to entity. If you use display. prefix in filters (e.g. name: "display.platform"), update them to use entity. (e.g. name: "entity.platform"). The same applies to KString references like {display.name} — use {entity.name} instead.
The KString between function now uses an inclusive range. Previously between(2,6,30) would match values strictly between 2 and 6 (exclusive); now it matches values from 2 to 6 inclusive. If you relied on the exclusive behavior, adjust your thresholds accordingly.
The {charging} entity data field is now an object with text (string) and is_active (boolean) properties. If you use {charging} in secondary_info or other KStrings, update it to {charging.text}. You can also use {charging.is_active} to access the boolean charging state.
Default configuration is now shallow-merged with your custom config. Previously, specifying any custom config would discard all defaults. Now, default values (e.g. sort, filter, collapse, bulk_rename, colors, secondary_info) are applied for any properties you don't explicitly set. If you relied on the old behavior where defaults were fully replaced, you may need to explicitly override specific properties (e.g. filter: {} to disable the default filter).
Update to v3.X.X
Secondary info last_updated / last_changed values. Now these values has to be put in quotes and curly braces e.g. secondary_info: "{last_updated}"
Secondary info charging indication. Now the value has to be in curly braces e.g. secondary_info: "{charging}"
Sorting setting has changed. Now it is called sort (previously "sort_by_level") and it can define multiple levels of sorting.
Color settings are now in a single config entry colors ("color_thresholds" and "color_gradient" settings are not working any more)
Update to v2.X.X
When you want to use it as entity (e.g. in entities card) you need to use different type: custom:battery-state-entity instead of custom:battery-state-card.
Custom styles are not supported any more
The card comes with built-in defaults shown below. These defaults are shallow-merged with your custom config — any property you don't explicitly set will use its default value. To disable a default, override it explicitly (e.g. filter: {} to remove the default filter).
type: "custom:battery-state-card"
secondary_info: "{last_changed}"
filter:
include:
- name: "attributes.device_class"
value: "battery"
exclude:
- name: "entity_id"
value: "binary_sensor.*"
sort:
by: "state"
collapse: 8
bulk_rename:
- from: " Battery"
- from: " level"
colors:
steps:
- '#ff0000'
- '#ffff00'
- '#00ff00'
gradient: trueThe following config resets all the above defaults, you can use it as a base config if you want to fully configure the card on your own
type: "custom:battery-state-card"
secondary_info: null
filter: {}
sort: {}
collapse: 0
bulk_rename: []
colors: {}| Name | Type | Default | Since | Description |
|---|---|---|---|---|
| type | string | (required) | v0.9.0 | Must be custom:battery-state-entity |
| entities | list(Entity | string) | v0.9.0 | List of entities. It can be collection of entity/group IDs (strings) instead of Entity objects. | |
| title | string | v0.9.0 | Card title | |
| sort | list(Sort | string) | v3.0.0 | Sets the sorting options | |
| group | number | list(Group) | v1.0.0 | Number of entities to show. Rest will be available in expandable section (example). Or list of entity/battery groups (example) | |
| filter | Filters | v1.3.0 | Filter groups to automatically include or exclude entities (example) | |
| bulk_rename | list(Convert) | BulkRename | v1.3.0 | Rename rules applied for all entities (example) | |
| theme | string | v3.3.0 | Name of the theme to apply (must be installed in Home Assistant). (example) | |
| default_config_base | boolean | true |
v4.1.0 | Whether to use default config values (sort, collapse, colors, etc.) as a base for the card configuration. When set to false only user-specified settings are used. Useful when entities are managed externally (e.g. via auto-entities card). |
+common options (if specified they will be applied to all entities)
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
| type | string | v0.9.0 | Must be custom:battery-state-entity if used as entity row e.g. in entity-list card |
|
| entity | string | (required) | v0.9.0 | Entity ID |
| name | string | v0.9.0 | Entity name override | |
| icon | string | null | v1.6.0 | Icon override. Set to a custom icon (e.g. mdi:battery), use entity attribute (e.g. attributes.battery_icon), or set to null to use the entity's default icon |
|
| attribute | string | v0.9.0 | Name of attribute (override) to extract the value from. By default we look for values in the following attributes: battery_level, battery. If they are not present we take entity state. |
|
| multiplier | number | 1 |
v0.9.0 | If the value is not in 0-100 range we can adjust it by specifying multiplier. E.g. if the values are in 0-10 range you can make them working by putting 10 as multiplier. |
+common options (if specified they will override the card-level ones)
These options can be specified both per-entity and at the top level (affecting all entities).
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
| colors | ColorSettings | (see below) | v3.0.0 | Color settings |
| tap_action | TapAction | more-info | v1.1.0 | Action that will be performed when this entity is tapped. |
| state_map | list(Convert) | v1.1.0 | Collection of value mappings. It is useful if your sensor doesn't produce numeric values. (example) | |
| charging_state | ChargingState | v1.1.0 | Configuration for charging indication. (example) | |
| secondary_info | KString | v3.0.0 | Secondary info text. It can be a custom text with keywords (dynamic values) (example) | |
| round | number | v2.1.0 | Rounds the value to number of fractional digits | |
| unit | string | "%" |
v2.1.0 | Override for unit displayed next to the state/level value (example) |
| value_override | KString | v3.0.0 | Allows to override the battery level value. Note: when used the multiplier, round, state_map setting is ignored |
|
| non_battery_entity | boolean | false |
v3.0.0 | Disables default battery state sources e.g. "battery_level" attribute |
| default_state_formatting | boolean | true |
v3.1.0 | Can be used to disable default state formatting e.g. entity display precision setting |
| debug | boolean | string | false |
v3.2.0 | Whether to show debug output (all available entity data). You can use entity_id if you want to debug specific one. |
| respect_visibility_setting | boolean | true |
v3.3.0 | Whether to hide entities which are marked in the UI as hidden on dashboards. |
| unpack | boolean | false |
v4.0.0 | Whether to unpack entities that have an entity_id array attribute (e.g. sensor groups) into separate batteries. (example) |
| style | string | v4.0.0 | Custom CSS rules injected into the element's shadow DOM. Allows targeting inner elements (e.g. .name, .state, .icon). Can be used together with card-level theme. (example) |
This is a string value containing dynamic values. Data for dynamic values can be taken from entity properties, its attributes, other entity state/attributes, etc.
| Type | Example | Description |
|---|---|---|
| Charging state | "{charging.text}" |
Shows text specified in ChargingState |
| Entity property | "{last_updated}" |
Current entity property. To ensure relative time, use the reltime() function via "|" (see below). E.g.: "Changed: {last_updated|reltime()}" |
| Entity attributes | "Remaining time: {attributes.remaining_time}" |
Current entity attribute value. |
| Other entity data | "Since last charge: {sensor.tesla.attributes.distance}" |
You can use full "path" to the other entity data |
Keywords support simple functions to convert the values
| Func | Example | Description |
|---|---|---|
| round([number]) | "{state|round(2)}" |
Rounds the value to number of fractional digits. E.g. if state is 20.617 the output will be 20.62. |
| replace([old_string],[new_string]) | "{attributes.friendly_name|replace(Battery level,)}" |
Simple replace. E.g. if name contains "Battery level" string then it will be removed |
| multiply([number]) | "{state|multiply(10)}" |
Multiplies the value by given number |
| greaterthan([threshold_number],[result_value]) | "{state|greaterthan(10,100)}" |
Changes the value to a given one when the threshold is met. In the given example the value will be replaced to 100 when the current value is greater than 10 |
| lessthan([threshold_number],[result_value]) | "{state|lessthan(10,0)}" |
Changes the value to a given one when the threshold is met. In the given example the value will be replaced to 0 when the current value is less than 10 |
| between([lower_threshold_number],[upper_threshold_number],[result_value]) | "{state|between(2,6,30)}" |
Changes the value to a given one when the value is between two given numbers (inclusive). In the given example the value will be replaced to 30 when the current value is between 2 and 6 (including 2 and 6) |
| thresholds([number1],[number2],...) | "{state|thresholds(22,89,200,450)}" |
Converts the value to percentage based on given thresholds. In the given example values will be converted in the following way 20=>0, 30=>25, 99=>50, 250=>75, 555=>100 |
| abs() | "{state|abs()}" |
Produces the absolute value |
| equals([value],[result_value]) | "{state|equals(on,1)}" |
Changes the value conditionally - whenever the initial value is equal the given one |
| reltime() | "Changed: {last_changed|reltime()}" |
Converts date to relative time e.g. "1 minute ago" |
You can execute functions one after another. For example if you have the value "Battery level: 26.543234%" and you want to extract and round the number then you can do the following: "{attribute.battery_level|replace(Battery level:,)|replace(%,)|round()} %" and the end result will be "27"
| Name | Type | Default | Since | Description |
|---|---|---|---|---|
| by | string | (required) | v3.0.0 | Field of the entity used to sort ("state" or "name") |
| desc | boolean | false |
v3.0.0 | Whether to sort in descending order |
Note: you can simplif
No open issues yet, or sync has not completed.