šŸ”‹ Lovelace: Battery state card

Thansk Maks, looks like itā€™s working. Will try a bit more but after I cleared my browser cache it seemed good. Now to find my iPhone and see if it still happens.

1 Like

Nice! All seems to be working here as intended now, thank you for managing to track it down :slight_smile:

1 Like

just wanted to show my config for " Low battery Card "

type: 'custom:battery-state-card'
title: Low Battery
show_empty: false
sort_by_level: asc
entities: null
filter:
  include:
    - name: entity_id
      value: '*_battery'
    - name: attributes.device_class
      value: battery
  exclude:
    - name: entity_id
      value: '*.state'
    - name: state
      value: Good
    - name: state
      value: 25
      operator: '>'
bulk_rename:
  - from: Battery

Hide card if empty.
Sort Ascending (lowest battery top)
Include / list all devices with battery in its ā€˜entity idā€™ or ā€˜device classā€™
Exclude any ā€œbattery stateā€ entities, and Good Health states, ( ā€˜Goodā€™ battery health, charging/discharging state)
Exclude any battery level above 25% remaining.
Rename all devices to remove the word ā€˜batteryā€™

Capture

3 Likes

Is it possible to use state_map with a filter?

Iā€™m trying to do a wildcard to include all my nest protects battery health sensors, then use a state map to convert the ā€œokā€ and ā€œreplaceā€ states to 100 and 25 respectively. However, this isnā€™t working:

filter:
  include:
    - name: entity_id
      value: '*_nest_protect_battery_health'
      state_map:
        - from: Ok
          to: 100
        - from: Replace
          to: 25

This unfortunately isnā€™t applying the state map and instead I get this:

State map belongs to the ā€œcommon settingsā€ so it can be used in entity or card (to be applied for all entities). You cannot specify state_map for filter. I think in your case the card-level settings will work as expected

type: 'cusom:battery-state-card'
state_map:
  - from: Ok
    to: 100  
  - from: Replace
    to: 25
filter:
  include:
    - name: entity_id
      value: '*_nest_protect_battery_health'
1 Like

How do you do a bulk rename with a case insensitive search? Iā€™ve tried trailing the regex with i but it isnā€™t working for me.

bulk_rename:
  - from: "/(battery health)/i"
    to: ''

I got it to work with this instead but the trailing ā€œiā€ shouldā€™ve worked and is more flexible?

bulk_rename:
  - from: '/([b|B]attery [h|H]ealth)/'
    to: ''

Separately, I wonder if by default, it should be case insensitive?

Oh yeah that is true - I have a silly way of detecting whether it is a regex pattern or not (regexp flags wonā€™t work). I will fix it - I have created a task to track it https://github.com/maxwroc/battery-state-card/issues/159

Thanks for reporting it!

1 Like

What is the right way to use this to show a card that only has battery levels less than some percentage (e.g. 30)? When I try to include entities based on state filter, using <30, itā€™s going across all entities and not just battery level sensors. So Iā€™m trying to figure out how to combine both a entity ID filter then apply a state level filter.

Is there a way to do 2 levels of sorting? By battery level, and by entity name?

E.g. I have sorting by battery level right now ascending, but look at the sort of the entity names:

Furthermore, is there a way to sort by entity name at all when using wildcard includes? (regardless of battery level)

hereā€™s my card right now:

type: 'custom:battery-state-card'
title: Low Batteries
tap_action: more-info
bulk_rename:
  - from: Battery Level
    to: ''
filter:
  include:
    - name: entity_id
      value: '*_battery_level'
  exclude:
    - name: entity_id
      value: '*_battery_state'
    - name: entity_id
      value: '*_iphone*'
    - name: entity_id
      value: '*_mac_internal*'

which generates the following:

FYI the bug with regexp filters not respecting flags is fixed now in v1.6.0

Is there a way to do 2 levels of sorting? By battery level, and by entity name?

No it is not possible now, sorry. If you want to have such option please create issue on github - maybe Iā€™ll add it next time (especially when more people would be interested in that kind of functionality).

Iā€™m thinking nowā€¦ maybe it make sense to add sorting by name (when val is the same) as a default behavior whenever user used filters?

FYI If you have tried 1.6.0 youā€™ve probably realized that the regex bug is still there. I have released accidentally the previous version of the card code. It is fixed now (added new release 1.6.1 with correct code :wink: )

That behavior you describe makes sense to me. I canā€™t imagine why someone would want it not sorted by name after the primary sort

Thanks!!

You sure this is fixed? This still isnā€™t working for me

bulk_rename:
  - from: '/(battery health)/i'
    to:

Bulk rename doesnā€™t support regex. You were reporting problem with filter and this one is fixed (let me know if that is not the case).

I have created two issues to cover the stuff you were suggesting:

Oh sorry I was confused as I mentioned the bulk rename issue earlier: šŸ”‹ Lovelace: Battery state card - #92 by tmchow

In re reading the thread I see where it was a bit confusing in the sequence of convos. No worries.

Dear maxwroc,

thank you very much for this wonderful card!

I have been using it for quite a while now without any problems. Just recently, after the upgrade to the latest version, the secondary_info disappeared. So I downgraded to the previous version, but the secondary_info is still missing.

Where there any major changes or do I miss something really important?

Thanks in advance and kind regards!

Iā€™m glad to hear that you like it. Please give me some more details, like exact version of the card and HA, additionally paste your card config.

There was an issue with secondary info which was fixed in 1.6.2 (released yesterday). The problem was only with showing last-changed/updated time.

The exact reason of missing text was that translations have changed in recent HA releases and I had to switch to the new ones. So the fix for the new HA probably broke the older one (let me know if that is your case).

Dear maxwroc,

thank you very much for your reply.

A couple of minutes ago I shut down my Home Assistant virtual machine in order to make a backup. Once finished, I restarted Home Assistant and now the secondary_info is shown again. Whatā€™s really weird is that a ā€œnormalā€ restart within Home Assistant did not fix the problem because I have tried that several times yesterday. However, a complete reboot seems like to have the problem fixed.

Kind regards!

1 Like

Hi @maxwroc,

Congratulations on your great work! Iā€™ve been using your card for several months already and Iā€™m happy camper! I recently needed to switch the configuration of my RFXTRX hub and now I keep detecting rfxtrx devices constantly. Guess what? those new devices make a mess of my card and I frequently find things like this:

Screen Shot 2020-12-08 at 17.23.53

As per your documentation, I believe I canā€™t filter out these results

Note: Include filters should rely on static entity properties. E.g. you should not add include filter which checks the state property. Include filters are processed only once - when page is loaded (to minimize perf impact).

Any chance I could remove the Unavailable devices?

thanks

Hi,
Udklip1
Is there a way to round the battery level ?