🔋 Lovelace: Battery state card

I have a few Homematic IP window contacts and they do not give a percentage value.

These have “normal” what do I have to set in the state_map: so that these are displayed correctly?
I have tried something but nothing changes.

Okay i got it.

Check the groups documentation: GitHub - maxwroc/battery-state-card: Battery state card for Home Assistant

In every group you can specify the min level this way the batteries which level is below won’t be included in the group which means won’t be in the collapsed section.

But here the problem is that the group requires list of entities while you use filter.include. This can be a good feature ask. If you have a github account please create one.

For the binary sensors please look at the documentation there is an example (just in your case the “on” state would indicate battery low so let’s say 25% and “off” would be 100%)

Regarding your phone - without any data/info I cannot say anything - no idea why it doesn’t show up.

1 Like

just adding my config for a chip card that displays the amount of entities that have a battery percentage less than or equal to 10% that when clicked pops up with browser mod and displays all entities that have a battery percentage less than or equal to 10%. might be usefull for someone :slight_smile:

it currently takes out anything that it identifies as a phone battery - but that is done manually, so some adjusting is probably needed on the last 2 exclusions for anyone wanting to use this.

type: custom:mushroom-chips-card
    chips:
      - type: conditional
        conditions:
          - entity: input_boolean.batteries_low
            state: 'on'
        chip:
          type: template
          content: |-
            {{states.sensor
                        | selectattr('attributes.device_class', 'defined')
                        | selectattr('attributes.device_class', 'eq', 'battery')
                        | rejectattr('entity_id', 'in', integration_entities('mobile_app'))
                        | map(attribute='state')
                        | reject('in', ['unknown', 'unavailable'])
                        | map('int', -1) | select('le', 10)
                        | select('ge', 0)
                        | list | count
                       }}
          icon: mdi:battery-alert-variant-outline
          icon_color: red
          tap_action:
            action: fire-dom-event
            browser_mod:
              service: browser_mod.popup
              data:
                content:
                  type: custom:battery-state-card
                  title: Devices with Low Battery
                  sort_by_level: asc
                  filter:
                    include:
                      - name: entity_id
                        value: '*_battery_level'
                      - name: entity_id
                        value: '*_battery'
                      - name: attributes.device_class
                        value: battery
                    exclude:
                      - name: state
                        value: 10
                        operator: '>'
                      - name: state
                        value: 'Unknown'
                      - name: state
                        value: 'Unavailable'
                      - name: entity_id
                        value: 'sensor.ju*'
                      - name: entity_id
                        value: 'sensor.sm*'
3 Likes

For Homematic IP Battery.
Then I have something for you, but you have to create a sensor for each device, then you get that in % and can use a battery card.

      fernbediehnung_bat:
        friendly_name: "Fernbedienung"
        value_template: >-
          {% set voltage = states('sensor.fernbedienung_rolladen_ug_operating_voltage') | float %}
          {% if is_state('binary_sensor.fernbedienung_rolladen_ug_low_battery', 'on') %}
            0
          {% else %}
            {{ ((voltage - 2.1) / (3 - 2.1) * 100) | round(0) }}
          {% endif %}
        unit_of_measurement: "%"                          

Hi,

I want to show all batteries with charge level below a value from a number_input helper. Is that possible with this card?

You probably will need a combination of this card and config-template-card to achieve what you want.

I have tried 3 diffrent configurations , but secondary_info about charging status not show.

type: custom:battery-state-card
title: Battery level
entities:
  - entity: sensor.phone_battery_level
    name: Phone
    secondary_info: charging
    charging_state:
      attribute:
        name: is_charging
        value: true
      secondary_info_text: Charging in progress
type: custom:battery-state-card
title: Battery level
entities:
  - entity: sensor.phone_battery_level
    name: Phone
    charging_state:
      attribute:
        name: "is_charging"
        value: "yes"
type: custom:battery-state-card
title: Battery level
entities:
  - entity: sensor.phone_battery_level
    name: Phone
    charging_state: # uses sensor.mi_roborock state value
      state: "charging"
      icon: "mdi:flash"
      color: "yellow"

Without seeing the entity data it is hard to tell what you have done wrong. Does your entity exposes charging state via attribute or it’s state? Take a screenshot of the entity from dev tools (states) and paste it here

I want battery sign with charging sign when phone is on charging like picture below
Screen Shot 2023-05-10 at 22.05.04

1 Like

Hi,

I have a similar issue. I’m trying to display charging state as secondary info but it doesn’t show up. My phone has separate entities for battery level and battery state. Help is much appreciated!

type: custom:battery-state-card
title: Battery levels
entities:
  - entity: sensor.huawei_p20_battery_level
    name: Huawei P20
    secondary_info: charging
    charging_state:
      entity_id: sensor.huawei_p20_battery_state
      state: Charging

Hi,

I’m using your great card on different ways and now I want to make a list of long time not changed entities.

How can I use the last_changed attribute as the primary info instate of the entity state so the list could sort and filtered by last state changed?

Any ideas?

Sorry that it took a while but if you still haven’t solved the problem the below code should work. Since your charging state is on the other entity you need to let the card know what is this other entity ID, where to look for the value and which value indicates that the battery is charging (“charging”)

type: custom:battery-state-card
title: Battery level
entities:
  - entity: sensor.phone_battery_level
    name: Phone
    charging_state: 
      entity_id: sensor.phone_battery_state
      state: "charging"
      icon: "mdi:flash"
      color: "yellow"
1 Like

Currently it is not possible to sort via other battery properties. Although this option is implemented already in (not yet released v3)

BTW keep in mind that the last_changed attribute is reset on every HA restart so if you restart your HA often that kind of sorting might not be very useful.

1 Like

Thank you.

Sorry if this is a newbie question. I’ve got HACs installed, using Frigate, that card shows up under Cards in dashboard edit. I downloaded your battery card, v.2.1.1. The battery state folder and four files are included in the www folder, so I know it’s been downloaded.

How do I add this card to the dashboard please?

Like i.e.:
Lovelace → Add card → Manually

type: custom:battery-state-card
card_mod: null
style: |
  ha-card {
  background: WhiteSmoke;
  }
title: Battery levels Balcony Front
color_gradient:
  - '#ff0000'
  - '#ffff00'
  - '#00ff00'
entities:
  - entity: sensor.xiaomi_mijia_light_sensor_03_front_balcony_battery
    name: Light Sensor Front Balcony
  - entity: sensor.tuya_sntz007_contact_sensor_01_master_bedroom_balcony_door_battery
    name: Balcony Door Sensor Master Bedroom
  - entity: sensor.tuya_den_sntz007_contact_sensor_front_balcony_door_battery
    name: Door Sensor Front Balcony Door

shows as:

1 Like

Thank you. So if I understand it correctly, this provides a base card and you modify it with your own sensors, display variables etc?

Correct :slightly_smiling_face:

Hello,
is it possible to use the state_map with include?

The entities with *batterie* have Normal as value.

type: custom:battery-state-card
title: Batterie-Status
sort_by_level: asc
collapse: 10
tap_action: more-info
entities:
  - entity: sensor.lumi_lumi_sensor_magnet_aq2_battery
filter:
  include:
    - name: entity_id
      value: '*_battery*'
    - name: entity_id
      value: '*batterie*'
      state_map:
      - from: 'Normal'
        to: 100
      - from: 'Schwach'
        to: 25
  exclude:
    - name: entity_id
      value: sensor.*phone*

Do you mean !include? No, but you can use YAML anchors if it’s all in the same file.

I misunderstood the question. See the answer lower down. Sorry.