šŸ”‹ Lovelace: Battery state card

Hello

I am unable to get tap action to work. When I hover over with my mouse it changes the cursor, but when i click (or tap on my phone) nothing happens. Any thoughts?

type: 'custom:battery-state-card'
title: Batteries
sort_by_level: desc
entities:
  - entity: sensor.schlage_door_lock_battery
    name: Front Door
    tap_action: more-info

Hey, please try to follow the example from doc/readme. It should be:

    tap_action:
      action: more-info

It is a very common mistake so I will think about adding the support for setting the string instead of object

That worked, thanks!

Hey, Iā€™m happy to inform you guys that the bugs which were there for a long time are fixed now!

@jriker1 @davefi @Marco_Lupieri The question mark bug should be gone in v1.5.0 :slight_smile:

@Zkaning Collapsed view / expanding groups should work as well now on iOS devices

Please let me know if you still can repro one of these issues!

1 Like

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!