maxwroc/battery-state-card

V2 broke - no card displayed

xstrex opened this issue · 10 comments

Describe what is wrong
V2 not working

Not using entities card, and don't think I have any custom styles, though no card did displayed.

YAML configuration

type: custom:battery-state-card
sort_by_level: desc
bulk_rename:
  - from: Battery Level
    to: sensor
  - from: Battery
  - from: battery
  - from: Heartbeat
  - from: sensor
  - from: Internal
state_map:
  - from: 'off'
    to: 100
  - from: 'on'
    to: 10
  - from: Unavailable
    to: Offline
filter:
  exclude:
    - name: state
      value: Unavailable
    - name: state
      value: 80
      operator: '>'
collapse:
  - name: Plant Sensors
    secondary_info: 'Battery levels (min: {min}%, {max}%)'
    icon: mdi:leaf
    entities:
      - sensor.moneytree_battery
      - sensor.pearls_battery
      - sensor.pothos_battery
      - sensor.spider_battery
      - sensor.succulent_battery
      - sensor.prayer_battery
  - name: Motion & Leak Sensors
    secondary_info: 'Battery levels (min: {min}%, {count})'
    icon: mdi:percent
    entities:
      - binary_sensor.front_door_heartbeat
      - binary_sensor.patio_door_heartbeat
      - binary_sensor.kitchen_heartbeat
      - binary_sensor.barthroom_heartbeat
      - sensor.motion_battery
      - binary_sensor.zw_003_low_battery
entities:
  - entity: sensor.newt_battery_level
    secondary_info: charging
    name: Roomba
    tap_action:
      action: more-info
  - entity: sensor.macbook_internal_battery_level
    secondary_info: charging
    charging_state:
      entity_id: sensor.macbook_internal_battery_state
      state: Charging
    tap_action:
      action: more-info
  - entity: sensor.macbook_pro_internal_battery_level
    secondary_info: charging
    charging_state:
      entity_id: sensor.macbook_pro_internal_battery_state
      state: Charging
    tap_action:
      action: more-info
  - entity: sensor.jon_iphone_battery_level
    secondary_info: charging
    charging_state:
      entity_id: sensor.jon_iphone_battery_state
      state: Charging
    tap_action:
      action: more-info
  - entity: sensor.jon_ipad_battery_level
    secondary_info: charging
    charging_state:
      entity_id: sensor.jon_ipad_battery_state
      state: Charging
    tap_action:
      action: more-info
  - entity: sensor.sonos_roam_battery
    secondary_info: charging
    charging_state:
      entity_id: binary_sensor.sonos_roam_power
      state: 'on'
    tap_action:
      action: more-info

Screenshot

Version
2.1.1

Since you are writing about "v2" I assume you haven't updated the card for a while... but the thing is that v2 is available for about 7 months already and no one reported any major problems so I assume there must be something specific in your case.

Can you please check if there are any errors in the dev console in your browser (you can open it by pressing F12)?

I assume you do have some of the entities which battery level is below 80%, right? If not then your "exclude" filter will hide all of them and the card will disappear

Correct, I have been running this for some time now, without issue, then went to look at it the other day, and found the entire card was missing. Yet the yaml shows up in the editor just fine. And yes I have a few devices under 80% that are not chowing up.

I'll check the browser.

Interesting; so I tried removing and re-adding the component, same result. I Tried going through the options, or blocks of options one by one to see what might be causing it.

For some reason, the entire above config works, exactly as it should, when I remove this block.

filter:
  exclude:
    - name: state
      value: Unavailable
    - name: state
      value: 80
      operator: ">"

I also tried removing each state item, and the entire thing fails, so it's not one, or the other, but a function of the filter:. Not sure what yet, but I hope this helps.

I have this same issue. It appears the "exclude" filter does not work properly. I have a similar configuration with a bunch of entities defined and if I try to exclude any, they all go away.

Seems there's a type issue. I'll see if I can dig a little deeper.

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'state')
    at Ut.getValue (battery-provider.ts:91:22)
    at Ut.isValid (battery-provider.ts:68:26)
    at battery-provider.ts:334:28
    at Array.forEach (<anonymous>)
    at Pt.processExcludes (battery-provider.ts:329:37)
    at Pt.<anonymous> (battery-provider.ts:174:14)
    at Generator.next (<anonymous>)
    at tslib.es6.js:76:71
    at new Promise (<anonymous>)
    at e (tslib.es6.js:72:12)

It appears to be an issue with undefined entities being passed to it. There probably needs to just be a check for undefined entities and have them removed. I was trying to fix it myself, but Chrome's Overrides are not working in Dev Tools. Without that working, Chrome just pulls the file from the internet, so I can't test any changes.

Thanks for the investigation it helps a lot. I'm marking this as a bug

Hi,
I have the same issue. Is this on the roadmap to be fixed or should I figure out a workaround?
Thanks

TBH I dont have time recently to work on this card. If you think you might be able to solve this somehow please give it a try and let us know. Contributing to the code is always welcome