🔋 Lovelace: Battery state card

Ok new to this card!
Love it !
Only thing i’m missing

How do you guys make notifications or alarms to smartphone once battery level is low…

@carsten_h please take a look at this website

https://maxwroc.github.io/lovelace-card-tester/?key=5f0f9127c1edc4661757cb97

You can test my card against various configurations and HA entity states. Note that entities are being matched there based on various conditions (as in your case). Additionally there is a filter to exclude the ones with 100% state.

FYI this uses the actual card code released in v1.4.0.

In such specific scenarios I won’t be able to help (without access to your HA) as there can be plenty of random reasons why this doesn’t work. But if you find the repro on this website then I will be able to tell where is the problem for sure.

If you find the repro please click share button on the bottom, copy the link and paste it here.

Thanks

1 Like

I am away from home now and only have an iPhone here. When I look at the page I only see a black page with config, Home Assistant state and a field for an URL. It is not really clear to me what to do there?

It looks like external js code didn’t load. This page is in the early stage of development and I have tested it so far only on Chrome (PC). Sorry about that. Please let me know what is the result once you get home and be able to check it on something else then mobile device.

I have a VM with Windows10 running on my NAS at home. When I start it there I see the configuration for the card in the top window and the state of some Home Assistant (not mine) in the lower window.
What should I do there?

Look at the states editor. You have the json there with collections of entity states. I’m not sure how familiar you are with json format but there are individual entieies between [ ] chars divided by commas. You can copy and paste one and adjust it to the one which is missing in your case. I have tested it with dachboden one you gave and everything worked as expected.

Please give it a try. It updates while you are editing the state or config.

This worked for me

card:
  attribute: battery_level
  sort_by_level: asc
  title_position: left
  type: 'custom:battery-state-card'
filter:
  exclude:
    - entity_id: switch.garage
  include:
    - attributes:
        battery_level: <=100
type: 'custom:auto-entities'

How would you exclude all device_tracker? As they are slow to update iPhone battery levels.
Should this not work? For me it’s not

        filter:
          include: 
            - name: entity_id
              value: "*_battery_level"
            - name: attributes.device_class 
              value: battery
          exclude: 
            - name: entity_id
              value: "device_tracker*"

Hi again @maxwroc

I really like you card, but it is not behaving like I want it to…
This is my config and I simply cannot see my wrongdoing:

      - type: custom:battery-state-card
        title: Batterier
        sort_by_level: asc
        color_gradient:
          - "#ff0000" # red
          - "#ffff00" # yellow
          - "#00ff00" # green
        charging_state:
          attribute: # whenever one of below attributes is matching
            - name: "Battery State"
              value: "Charging"
            - name: "is_charging"
              value: true
          state: # or if entity state matches one of the following
            - "charging"
            - "Charging"
        entities: []
        filter:
          include: 
            - name: entity_id
              value: "*_battery_level"
            - name: attributes.device_class 
              value: battery
          exclude: 
            - entity_id: "device_tracker*"
#            - device_tracker.martins_iphone
#            - device_tracker.martins_iphone_2
#            - device_tracker.natasja_apple_watch
#            - device_tracker.natasja_iphone
#            - device_tracker.natasja_iphone_2
#            - device_tracker.natasjas_iphone
        collapse:
          - group_id: group.door.sensors_battery
            name: 'Dørsensorer (min: {min}%, count: {count})' # special keywords in group name
            secondary_info: 'Batteri niveauer {range}%' # special keywords in group secondary info
            icon: 'mdi:door'
                        
          - group_id: group.motion.sensors_battery
            name: 'BevĂŚgelsessensorer (min: {min}%, count: {count})'
            secondary_info: 'Batteri niveauer {range}%'
            icon: 'mdi:run-fast
         
          - group_id: group.temp.sensors_battery
            name: 'Temp.sensorer (min: {min}%, count: {count})'
            secondary_info: 'Batteri niveauer {range}%'            
            icon: 'mdi:thermometer' 

          - group_id: group.switches_battery
            name: 'Kontakter (min: {min}%, count: {count})'
            secondary_info: 'Batteri niveauer {range}%'            
            icon: 'mdi:light-switch' 

          - group_id: group.equipment_battery
            name: 'Udstyr (min: {min}%, count: {count})' 
            secondary_info: 'Batteri niveauer {range}%'            
            icon: 'mdi:cellphone-iphone'    

When I remove the entire “collapse” part I get this:


So it’s working fine, it’s my config, no doubt.

Thanks in advance

You are using auto-entities card which shouldn’t be necessary to achieve same results but it can be alternative if someone is not able to do it via my card filters (I think though if you are not able to do the same with battery card filters you won’t be able to do it via auto-entities)

I think I have noticed potential bug but I need to debug it and check what is the exact root cause. This may be the reason why something was not working for @carsten_h.

Will let you guys know (probably over the weekend).

Ah, that is great! I can test it at the end of next week when I am back at home.

Sounds great, thanks for letting us know :slight_smile:

Is it just me or does this card always put question marks in the icons for the batteries and then you have to refresh the page each time you go to it to make that go away?

image

Couple minutes later the same without changing the page. Refresh and:

image

No refresh, at all time it’s same picture: No question marks.

batteries

Ok that is the weirdest bug I’ve seen so far related to my card :slight_smile: And it is hard for me to imagine that it could be caused by the card itself especially that the values are rendered correctly as well as icon color. So it seems like the wrong icon is being rendered by HA (at least that is the only explanation I can find now).

Please let me know if anyone else experiences the same

Does it ALL the time for me. I can reproduce it all day. Nothing in the standard HA logs.

I have found a bug which was causing that filters which were not having “value” and “operator” property (in such cases the “exists” operator should be used automatically) were not working (throwing error). I have fixed that issue in v1.4.1 please check and let me know.

Martin in your case the below example which you have pasted is wrong:
image

But the previous one is correct:

type: "battery-state-card"
title: Filters
sort_by_level: "asc"
filter:
  include: # filters for auto-adding
    - name: entity_id # entities which id ends with "_battery_level"
      operator: matches
      value: "*_battery_level"
    - name: attributes.device_class # and entities which device_class attribute equals "battery"
      value: "battery"
    - name: attributes.battery_level
  exclude:
    - name: entity_id
      value: "device_tracker.*"

I have tested it with the below entity:

  "device_tracker.my_iphone": {
    "entity_id": "device_tracker.my_iphone",
    "state": "Home",
    "attributes": {
      "friendly_name": "My iPhone",
      "battery_level": 14
    }
  }

It works here now without any problem. Now all my wanted devices are shown!

Thank you very much for this!