maxwroc / battery-state-card

Battery state card for Home Assistant
MIT License
875 stars 38 forks source link

Icons show question mark and no colour #657

Closed B0ndo2 closed 8 months ago

B0ndo2 commented 9 months ago

Icons show question mark and no colour

Expected behavior The icons should have colours based on battery level

YAML configuration


type: custom:auto-entities
card:
  type: custom:battery-state-card
  title: Batteries
  sort_by_level: asc
  collapse: 5
  tap_action: more-info
  color_thresholds:
    - value: 10
      color: '#ff0000'
    - value: 50
      color: '#fa9e0a'
    - value: 100
      color: '#00ff00'
filter:
  include:
    - entity_id: sensor.*_battery
sort:
  method: state
  numeric: false
  ignore_case: true
  reverse: true
  ip: false

image

Version 3.1.5

maxwroc commented 9 months ago

What integration gives you these entities?

Can you please paste the entity and its attributes (screenshot) from the Home Assistant Developer Tools?

I think that the reason why the battery level was not correctly recognized is that entity state contains the "%" which is not prefixed with space

B0ndo2 commented 9 months ago

Do you mean this ? image

The card was working properly previously but stopped working after updating today (both the card and HA supervisor)

maxwroc commented 9 months ago

Can you please add to your config the following:

default_state_formatting: false

Please tell me if this helps and if so what is your locale settings in HA

B0ndo2 commented 9 months ago

That removed the question mark but all the icons now are green regardless of the threshold (I changed the 50% threshold to 60% to get a different colour)

image

papperone commented 9 months ago

I have some problem since last version, it was working with all colors according to value, now only battery icon with question mark immagine

B0ndo2 commented 9 months ago

I have some problem since last version, it was working with all colors according to value, now only battery icon with question mark immagine

Adding this in the card config fixed for me for the question mark but the colours are still the same for all levels default_state_formatting: false

badnetmask commented 9 months ago

The default_state_formatting: false worked for me as well. My locale config is US/English/US customary.

tomlut commented 9 months ago

Just noticed this as well. I'm on the February beta release though and thought it may be due to this:

https://developers.home-assistant.io/blog/2024/01/30/ha-state-icon-properties-changes/

bdormael commented 9 months ago

same issue here since beta 2024.2 (Feb release)

midiwidi commented 9 months ago

I had the same problem (icon with a question mark and no color). "default_state_formatting: false" fixed both problems for me. It also fixed an issue with sorting. Without "default_state_formatting: false" the order was 100%,100%,17%,40%,69%,94% and with it is correct 17%,40%,69%,94%,100%,100%. Sounds to me as if the entity state (battery level) is interpreted as a string instead of a number and can therefore not be mapped to the right symbol and color or sorted correctly..

tomlut commented 9 months ago

Yeah it fixed it for me too.

maxwroc commented 9 months ago

@midiwidi yes this is the exact problem. I have assumed that the formatted state which comes from HA will always be in the format of [value] [unit] but it looks like the space is gone in many cases after 2024.2 release, now the logic fails to parse the returned state. I need to think whether this extraction of the state make sense... it has caused soooo many problems/bugs

@tomlut the change to ha-state-icon should not have any impact as this card uses ha-icon element only

maxwroc commented 8 months ago

Should be fixed now in v3.1.6