maxwroc/battery-state-card

After upgrading to 2024.2.0 HA, display card is not acting correctly

MichaelStruck opened this issue · 24 comments

Describe the bug

Based on this configuration that has work well on my dashboard:
type: custom:battery-state-card
title: Low/Unavailable Batteries
sort_by_level: desc
color_gradient:

  • '#ff0000'
  • '#ffff00'
  • '#00c000'
    bulk_rename:
  • from: Power
    to: ''
  • from: ': Battery level'
    to: ''
  • from: ': Battery'
    to: ''
    entities:
  • entity: group.battery_items
    show_entity_picture: false
    tap_action:
    action: more-info
    filter:
    exclude:
    • name: state
      value: 25
      operator: '>'

After the 2024.2.0 update from HA, the card this code is attached to does NOT hide, and reveals all of the batteries regardless of their value (they should only show when <25%. The list of batteries is in the group (group.battery items). Based on another bug report, all of the batteries show the exclamation point:

image

How to reproduce
Use the code above, create a dashboard card, compare 2024.1.6 to 2024.2.0 HA

Expected behavior
Expect the card to not appear when batteries are >25%

YAML configuration
type: custom:battery-state-card
title: Low/Unavailable Batteries
sort_by_level: desc
color_gradient:

  • '#ff0000'
  • '#ffff00'
  • '#00c000'
    bulk_rename:
  • from: Power
    to: ''
  • from: ': Battery level'
    to: ''
  • from: ': Battery'
    to: ''
    entities:
  • entity: group.battery_items
    show_entity_picture: false
    tap_action:
    action: more-info
    filter:
    exclude:
    • name: state
      value: 25
      operator: '>'

please paste here your card config

image

Dev console errors
No errors

Screenshots
above

Version
3.1.5

Worked in 2024.1.6

the same here after update HA to 2024.2.0

rgnet5 commented

Seeing the same after 2024.2.0. Not respecting exclude filter:
exclude:
- name: state
value: 30
operator: '>'
Show all batteries with a ? Icon

same here

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: 4
bulk_rename:

  • from: ' Battery'
  • from: ' level'
    colors:
    steps:
    • '#ff0000'
    • '#ffff00'
    • '#00ff00'
      gradient: true

Exact same issue here as well. I use color gradients, if that helps.

I have got an entities card with the following config

type: entities
entities:
  - entity: sensor.jphone_battery_level
    type: custom:battery-state-entity
    name: Battery
    thresholds:
      - value: 25
        color: "#8fffe1"
      - value: 40
        color: "#8fbbff"
      - value: 70
        color: "#978fff"
      - value: 100
        color: "#fe8fff"
    color_gradient:
      - "#ff0000"
      - "#ffff00"
      - "#00ff00"
    charging_state:
      entity_id: sensor.jphone_battery_state
      state: Charging

This is what I see

image

Almost same
Screenshot_20240208-105504~2

type: custom:battery-state-card
title: Батарейки
sort: state
entities:
  - entity: sensor.knopka_battery
    name: Кнопка светильника в коридоре
  - entity: sensor.datchik_vlazhnosti_i_temperatury_battery_state
    name: Датчик ВиТ
    state_map:
      - from: high
        to: 100
      - from: medium
        to: 50
      - from: low
        to: 20
  - entity: sensor.datchik_vlazhnosti_i_temperatury_bez_ekrana_battery_state
    name: Датчик ВиТ без экрана
    state_map:
      - from: high
        to: 100
      - from: medium
        to: 50
      - from: low
        to: 20
  - entity: sensor.datchik_protechki_za_striralkoi_battery
    name: Датчик протечки за стриралкой
  - entity: sensor.datchik_dvizheniia_vkhod_battery
  - sensor.pixel_6_pro_battery_level
  - entity: sensor.roborock_s7_battery
    name: Roborock S7
  - input_number.tetestovyi_polzunok

Adding this to card config helped in my case:

default_state_formatting: false

@MEKadan

Adding this to card config helped in my case:

default_state_formatting: false

Added this to my card and it addressed the issue for mine.

RedNo7 commented

for me, it is not respecting colours or collapse.

- type: custom:battery-state-card
  title: 'Low Batteries'
  sort:
    by: "name"
  collapse:
    - name: 'x{count} at {min}% min'
      min: 40
  colors:
    steps:
      - "#ff0000" # red
      - "#ffff00" # yellow
      - "#00ff00" # green
    gradient: true
  bulk_rename:  # note: "to" is not required if you want to remove string
    - from: " Battery"
    - from: " Level"
  charging_state:
    state: # or if entity state matches one of the following
      - "Charging"
  filter:
    include:
      - name: entity_id
        value: "sensor.*battery*"
    exclude:
      - name: entity_id
        value: "*count*"
      - name: entity_id
        value: "*state*"
      - name: entity_id
        value: "*double*"

Screenshot 2024-02-08 at 11 19 11

edit:
default_state_formatting: false fixed it for me as well 👍

It's a dupe of #657 But keeping it open for now to avoid creating more duplicated items.

Apparently something has changed in the HA 2024.2. Looks like the HA default state formatting returns the value combined with the unit and without the space between.

I confirm that using the mentioned setting should mitigate the problem.

@MEKadan

Adding this to card config helped in my case:
default_state_formatting: false

Added this to my card and it addressed the issue for mine.

Work for me too.

I have the issue as well after updating to HA 2024.2.2.
Adding default_state_formatting: false corrected the issue but you don't want to create a new card with it or the new card disappears from view but is still in the yaml for the dashboard.

default_state_formatting: false

resolved this for me as well.

Adding this to card config helped in my case:

default_state_formatting: false

Worked for me as well. Thank you!

same here:

type: custom:battery-state-card
title: Batteries
sort:
  by: state
collapse:
  - name: Temp sensors more than 4%
    min: 4
    entities:
      - sensor.office_temp_sensor_1_battery
      - sensor.office_temp_sensor_2_battery
      - sensor.office_temp_sensor_3_battery
      - sensor.kitchen_temp_sensor_1_battery
      - sensor.kitchen_temp_sensor_2_battery
      - sensor.utility_room_temp_sensor_1_battery
      - sensor.dining_room_temp_sensor_1_battery
      - sensor.living_room_temp_sensor_1_battery
      - sensor.adam_bedroom_temp_sensor_1_battery
      - sensor.olivia_bedroom_temp_sensor_1_battery
      - sensor.kids_bathroom_temp_sensor_1_battery
      - sensor.staircase_boiler_temp_sensor_battery
      - sensor.parents_bedroom_temp_sensor_1_battery
      - sensor.parents_bathroom_temp_sensor_1_battery
  - name: More than 20% - SAFE
    min: 20
bulk_rename:
  - from: Battery Level
  - from: battery low
  - from: battery
filter:
  include:
    - name: entity_id
      value: '*battery_level'
    - name: entity_id
      value: '*battery'
    - name: attributes.device_class
      value: battery
state_map:
  - from: 'off'
    to: 100
  - from: 'on'
    to: 10

IMG_8045

Adding this to card config helped in my case:

default_state_formatting: false

worked for me as well !

same issue to me as well, tried default_state_formatting: false but didn't fix the issue though.

Same issue with this card, after 2024.2.0 update.
Adding default_state_formatting: false looks like fix it

Default state formatting works, but I think the native code should be revised to work properly without that.

Exactly the same on HA 2024.2.1...Including that default_state_formatting: false still fixes it.

Should be fixed now in v3.1.6

is 3.1.6 released ?

Sometimes I close the issue just before the release so if it's not yet available please wait up to 1-2 days. Now 3.2.0 is available

I can report that it's fixed !
THANK YOU !