Automatically add 'battery' entities to dashboard

I have a tab on lovelace in which I display all my battery entities using the ‘gauge’ widget, so I can check it and see at a glance if there are any batteries which need replacing. I have to manually update this, but that got me to thinking - is there a way that I could have anything with ‘battery’ in it automatically added to that screen?

I did this using two custom cards:

type: custom:auto-entities
card:
  type: grid
  columns: 4
card_param: cards
filter:
  include:
    - entity_id: sensor.*battery*
      options:
        type: custom:config-template-card
        entities:
          - this.entity_id
        card:
          type: gauge
          entity: this.entity_id

Auto entities from Thomas is awesome and gets a list of entities that meets the defined criteria (in this case with battery in the name although you need to change that to meet your configuration) and passes these into the card defined. However it works best with the entities card as it passes a list of entities in; by using the config-template-card you can get round that challenge.

I’m sure others have found smarter ways to do it but this works quite well for my use case. In all honestly I can’t fully remember how I got this working fully but it would have been through lots of reading on the forums and loads of trial and error!

3 Likes

Thanks - that’s exactly what I needed! Actually got it to work really nicely without a template (I might have missed what extras that would bring me though?).

This is my config for it:

type: custom:auto-entities
card:
  type: grid
  columns: 6
card_param: cards
filter:
  include:
    - entity_id: sensor.*battery*
      options:
        type: gauge
        min: 0
        max: 100
        severity:
          green: 50
          yellow: 30
          red: 15
        entities:
          - this.entity_id
3 Likes

If you’re open to a totally different solution this highly configurable custom battery card works great.

2 Likes

I have a bunch of entities that are ‘battery’ related but aren’t actual percentages. So this code only shows things with ‘battery’ and % as it’s unit. (I’ve also added an auto sorting thing so that the lowest percentages are the top)

type: custom:auto-entities
card:
  type: grid
  columns: 4
card_param: cards
filter:
  include:
    - entity_id: sensor.*battery*
      attributes:
        unit_of_measurement: '%'
      options:
        type: custom:config-template-card
        entities:
          - this.entity_id
        card:
          type: gauge
          entity: this.entity_id
sort:
  method: state
  numeric: true