Lovelace Battery Entity Card

This is my first time working with Lovelace. I created a card that is designed for displaying battery information for battery entities. Entity icon will display a color indicating the level, and the icons also show how far along the battery is. There are custom thresholds for the warning levels.

Feedback welcome!

25 Likes

This looks good, nice work. One thing that this other similar component does is provide notifications when levels gets to the thresholds set. Any chance of including something like this?

I don’t think notifications would be possible with this, as Lovelace cards really just touch the frontend interface. As far as I know, they can’t do anything with the backend such as creating notifications.

However, still learning the ropes of how Lovelace works, maybe I don’t know all the functionality yet.

I don’t mean to do the actual notification from the card, just call an existing notify service and send the entity details of which device is low.

I’m kind of just thinking out loud here… The custom card tracker card has a function to check for updates each day, so I wonder if that code could help work out how to do it?

1 Like

Use this script; and set an automation to run it every few hours. I run it every 6 hours. It will check all the devices battery level and send a notification if any under the threshold.

It works from the zwave domain and uses the attributes so no sensors need to be created.

#####################################
zwave_battery_check:
  alias: Zwave Battery Check

  sequence:
    - condition: template
      value_template: >-
        {%- set battery_alert_threshold = 40|int -%}
        {{ states.zwave | selectattr('attributes.battery_level', 'defined') | selectattr('attributes.battery_level','<', battery_alert_threshold ) | list | length >= 1 }}

    - service: script.notify_all_engines
      data_template:
        title: "ZWAVE Low Battery"
        who: "john"
        message: >-
          {%- set battery_alert_threshold = 40|int -%}
          {%- set low_batteries = states.zwave | selectattr('attributes.battery_level', 'defined') | selectattr('attributes.battery_level','<', battery_alert_threshold ) | map(attribute='name') | list | join(', ') -%}
          Low batteries in the following devices: {{ low_batteries }}

@cbulock Nice one. Thanks for sharing.

Got it up and working do you have example using multiple entities? I can’t seem to get it to work with more then one entity.

To include multiple entities, use battery-entity inside a regular entity card, e.g.

type: entities
entities:
  - type: 'custom:battery-entity'
    entity: sensor.aarlo_battery_level
  - type: 'custom:battery-entity'
    entity: sensor.courtyard_motion_battery
  - type: 'custom:battery-entity'
    entity: sensor.front_door_sensor_zigbee_battery
7 Likes

It’s possible to add entity dinamically?

For example adding a group of battery entities: " - group.battery_status"

Nice card!

Please consider also the possibility to use attributes for a sensor?

- type: custom:battery-entity
  entity: zwave.fib_smoke_sensor2.battery_level
2 Likes

why do you not create a sensor

  • platform: template
    sensors:
    battery_smoke 2:
    friendly_name: ‘Batterij smoke 2’
    value_template: ‘{{ states.zwave.fib_smoke_sensor2.battery_level }}’
    unit_of_measurement: ‘%’

Because creating sensors just to be able to display an attribute is nasty:

  1. Sensors require a restart to become active
  2. Sensors take some resources to keep updated
  3. With many devices maintaining those sensor configs is a PITA

Lovelace allows us to be dynamic and change without a reboot so we should use that functionality wherever possible.

Also as Lovelace is rendered on the client side it doesn’t add load to the host.

The only reason to create a sensor is if you want to use it as an automation trigger or a few other use cases.

Just say no to 100’s of template sensors :wink:

1 Like

The the auto-entities card should work to wrap this.

Here is mine based on custom monster card:

card:
  show_header_toggle: false
  title: Low Battery Devices
  type: entities
filter:
  exclude:
    - entity_id: sensor.some_sensor_name_here
    - entity_id: sensor.some_sensor_name_here
    - entity_id: sensor.some_sensor_name_here_etc
  include:
    - entity_id: '*battery*'
      state: < 25
    - attributes:
        battery: < 25
    - attributes:
        battery_level: < 25
show_empty: true
type: 'custom:monster-card'
5 Likes

@cbulock Hello! Thanks for your work! These are really cool cards! Is it possible to remove the color setting from the battery icons? I want my theme to be the same everywhere, but the green icons do not fit into my HA theme ))

Too bad that all the devices must be added manually. I would love this plugin with automatic detection of battery powered devices.

I think it is not so difficult. If you, of course, they are not 100-200 pieces)

you could always try a different method I have this (easily configured to only show batteries under a set %age).

- type: custom:vertical-stack-in-card
  title: Battery Status
  cards:
    - type: custom:auto-entities
      card:
        type: custom:bar-card
        attribute: battery_level
        unit_of_measurement: "%"
        severity:
        - value: 50
          hue: '0'
        - value: 75
          hue: '40'
        - value: 100
          hue: '120'
        title_position: left
        padding: 0px 15px 3px 15px
        saturation: 50%
        columns: 1
        height: 15px
        width: 60%
        card_style:
          box-shadow: 0 0
        bar_style:
          border-radius: 20px
        indicator_style:
          border-radius: 20px
      filter:
        include:
        - attributes:
            battery_level: "<=100"

It uses the attribute so you don’t need to create additional template sensors.
(I prefer the look of the card created by @cbulock though).

10 Likes
filter:
        include:
        - attributes:
            battery_level: "<=100"

Is this really that simple with lovelace? o.O
I’ve been trying to achieve that in pre-lovelace times, but eventually i gave up.

yeh, that filter belongs to the auto-entities card. Of course it doesn’t work if you have entities that use a different attribute name - I don’t have any. It could be tweaked, I’m sure.