🔋 Lovelace: Battery state card

Hi there - thanks for the card! I’m using a wiser heating integration which has recently changed which means I now have entities directly for battery percentage - i.e. the state is the actual percentage. I think because this card searches for certain attributes (battery_level being the important one likely) what’s happening is the card displays not the percentage but what it finds as battery_level, and in this integration this is actually a string like “One third”. I can see in HA that the state is the battery percentage on the entity.

type: custom:battery-state-card
title: Battery Status
entities:

  • entity: sensor.wiser_itrv_bathroom_battery
    name: Bathroom Radiator
    secondary_info: battery_level

So for the above example I used to user an attribute: battery_percent and this would force the card mod to show the percentage. I’m removed this and now I see “One third” for both primary and secondary which is obviously not what I want. How do I force the card mod to display just the state value? Thanks :slight_smile:

For reference this used to work with the older integration:

  • entity: sensor.wiser_itrv_purple_room
    name: Purple Radiator
    attribute: battery_percent
    secondary_info: battery_level

Is there a way to actually hide the battery state values (or alternatively only show them as secondary info)? I want to gain some more space for the actual name of the entity and the battery level as such is indicated by the color so I don’t need to see the exact percentages:

image

No, currently it is no possible. But I like this idea, can you please create a feature request on github?


state is the actual percentage. I think because this card searches for certain attributes (battery_level being the important one likely) what’s happening is the card displays not the percentage but what it finds as battery_level, and in this integration this is actually a string like “One third”

You are right, card currently prioritizes higher the “battery_level” attribute over the state. This needs to be fixed. If you have a github account please create a bug.

I haven’t used card_mod at all so I cannot help.

1 Like

Sorry I didn’t mean to confuse - I meant this card not card_mod. I’ll raise an issue :slight_smile:

Hey All love t his card but can anyone explain to me why sometimes the entities come back with Unknown? I have gone into the companion app on those devices and made sure the sensors are enabled, but I still get this from time to time. Is it the config ? Below is my config. Any help is appreciated.

Thanks

I see that this is a card preview when you add it from UI. The unknown states can appear at the beginning when the card config is changed. You need to wait little bit for Home Assistant to update the state.

If you see such behaviour after you add the card and refresh the page then something is wrong. Please check in the DeveloperTools the actual states for your entities. Maybe something wrong is with the integration and the state is actually not there.

Hi @maxwroc, thanks for your effort on this, nice card!
I have just now discovered it and gave it a try: result looks good.

I had a few minor issues:

  • The card does not show up under the card picker.
    After adding a manual card and adding the yaml code, I got to see the preview.
    Refreshing the browser and restarting HA didn’t bring any change.
  • Adding ‘secondary_info: last_changed’ did not reveal anything until the card was saved.

But even so a good job/nice card! :+1:

The card does not show up under the card picker

Yes, you are right. Card will show up in the card picker in v3.0 I think. To add it you need to chose “manual” option of adding the card.

Adding ‘secondary_info: last_changed’ did not reveal anything until the card was saved

When you modify config in card picker you need to wait for the state refresh otherwise you won’t see the data. So you don’t have to save/add the card but just need to wait little bit longer sometimes. More and more people ask about that kind of issues so I will think how to solve it (I have one idea)

I found the problem, I had the entity state pulled wrong. Fixed that and it worked Thank you @maxwroc

FYI This is now fixed in v2.1.1

UPDATE:
Found Use of separate entities for charging state at card config level · Issue #314 · maxwroc/battery-state-card · GitHub which basically asks for exactly what I’m looking for. I’ll cross-link this post there, maybe it’s helpful.

Use-Case:
I use it as a card, entities coming from a group. I now want to add charging-state (according to GitHub - maxwroc/battery-state-card: Battery state card for Home Assistant and GitHub - maxwroc/battery-state-card: Battery state card for Home Assistant).

Problem:
The charging state information is neither part of the entity state nor of the entity attributes. Instead it is part of another entities state (at least they share some part of the entity id), e. g.:

  • battery level (part of used group): sensor.phone_abc_battery_level
  • charging state: sensor.phone_abc_battery_state

I do not want to manually name the entities in the card configuration (because this doesn’t scale for the lots of entities within my group) but keep the group definition.

  - entity: sensor.phone_abc_battery_level
    charging_state: # uses other entity state value
      entity_id: sensor.phone_abc_battery_state
      state: "Charging"

Question:
Is there currently a way to cross-reference the corresponding charging state entities to the battery level entities coming from the group?

If not/feature request:
Could we implement such a “cross-linking”, e. g. based on the entity id name? This way we could use a group as entity and use the “uses other entity state value” part already existing.

Full current card definition:

type: custom:battery-state-card
entities:
  - entity: group.batterystate_devices
title: đŸ“± GerĂ€te
secondary_info: last_updated
tap_action: more-info
sort_by_level: asc
collapse: 7
filter: 0
round: 0
unit: '%'
color_thresholds:
  - value: 20
    color: red
  - value: 45
    color: yellow
  - value: 100
    color: green
bulk_rename:
  - from: ' Battery Level'
    to: ''
  - from: ' AkkufĂŒllstand'
    to: ''
1 Like

Such functionality will come in v3.0 so please stay tuned. I cannot give you any ETA currently, sorry

2 Likes

How do I install this without HACS?

Hi,

I really love this card for the info that it provides at a glance really good work.
I am new to HA and I have read this thread and also your instructions on the repo.
I was able to setup a basic card the way that I want (only have a few devices)
what I am trying to achieve is when a device is charging the percentage value to change to charging

this is my card code

type: custom:battery-state-card
title: Battery Monitor
color_gradient:
  - '#ff0000'
  - '#ffff00'
  - '#00ff00'
entities:
  - entity: sensor.doorbell_battery_level
    name: Door Bell
  - entity: sensor.note_10_pro_battery_level
    name: Note 10 Pro
    charging_state:
      entity: binary_sensor._note_10_pro_is_charging
  - entity: sensor.ipad_battery_level
    name: iPad

i have tried a few different setups but they all change the icon to have a lightning symbol but this does not show charging in the location and does not change back to normal when i unplug

on HACS,
go to frontend and search battery-state-card and install the repo.
then you will be able to setup the card using manual card in your dashboard and paste in the code that you want.

@davinci Installation process without HACS is exactly the same as for any other custom cards and it is covered in the docs for the battery-state-card as well: GitHub - maxwroc/battery-state-card: Battery state card for Home Assistant

1 Like

what I am trying to achieve is when a device is charging the percentage value to change to charging

It’s not possible to do it. Column with the battery level always contains the main entity state. (I guess the screenshot in the docs confused you).

The only thing which you can do is to display a custom text (when charging is in progress) as the “secondary info” (under entity name).

and does not change back to normal when i unplug

Please check if the entity state (indicating charging in progress) actually changes. Usually it isn’t updating right away - there is a delay.

thank you for this info.
with the binary sensor it updates quickly but i did wait a little for the update.
as soon as i add the below the icon changes even when the device is not charging

    charging_state:
      entity: binary_sensor._note_10_pro_is_charging

I have the file, but it is unknown.

I made a ui-lovelace.yaml with this code inside:

resources:
  - url: /local/battery-state-card.js
    type: module

After that I tried to add it in visual edit as custom item:

Configuration errors detected:

* Custom element not found: battery-state-card

The configuration might be wrong, but it isn’t described exactly how to do it.