Try this, hopefully it’ll provide you a starter.
You’ll need to have the following custom cards installed: -
If the battery is managed by Battery Notes you will see the battery type in parentheses after the name and the icon tap action will prompt for confirmation that you’ve replaced the battery.
If the battery is not managed by Battery Notes then the card behaves like the normal Tile card (i.e. will display more-info
)
type: custom:auto-entities
card:
type: vertical-stack
card_param: cards
filter:
exclude:
- state: unavailable
include:
- attributes:
device_class: battery
options:
type: custom:config-template-card
entities:
- this.entity_id
variables:
getBatteryLabel: |
() => {
let battery_label = states[this._config.entities[0]].attributes.friendly_name.replace(/(battery|level)/gi, '').trim()
let battery_type = states[this._config.entities[0] + "_type"]
if (battery_type) {
return `${battery_label} (${battery_type.state})`
}
return battery_label
}
getIconAction: |
() => {
let battery_button = states['button.' + this._config.entities[0].split('.')[1] + '_replaced']
let ret = {'action': 'more-info'}
if (battery_button) {
ret.action = 'call-service'
ret.confirmation = {'text': 'Battery replaced?'}
ret.data = {'entity_id': battery_button.entity_id}
ret.service = 'button.press'
}
return ret
}
card:
type: tile
entity: this.entity_id
icon_tap_action: ${getIconAction()}
name: ${getBatteryLabel()}
sort:
method: name
sort:
method: state
numeric: true