Automatically add 'battery' entities to dashboard

Try integration:<your other integration identifier> and see what you get.
I’m wondering if it’s something to do with the entity being in 2 different integrations…

1 Like

I think that might be the problem in that custom:auto-entities seems to have an issue with the order that HA returns the integrations containing the entity.

If I change my filter to include integration: mqtt I only see 2 entities and in the previous screenshot, the majority of battery-notes entities are also in MQTT.

Confirmed - auto-entities seems to only see the first integration for the device, and may not be what the UI displays alphabetically?

Try integration: homematic(ip)_local (or it might be homematicip_local or maybe homematic_ip_local)

Pop this into dev tools, template to see your integration identifiers:

{% set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %}
{%- set ns = namespace(integrations = []) %}
{%- for device in devices %}
  {%- set ids = device_attr(device, 'identifiers') | list | first %}
  {%- if ids and ids | length == 2 %}
    {%- set integration, something_unique = ids %}
    {%- if integration not in ns.integrations %}
      {%- set ns.integrations = ns.integrations + [ integration ] %}
    {%- endif %}
  {%- endif %}
{%- endfor %}
{{ ns.integrations }}

If the other integration identifier lists them then use both:

include:
  - integration: battery_notes
      domain: binary_sensor
      attributes:
        device_class: battery
  - integration: <the other integration identifier>
      domain: binary_sensor
      attributes:
        device_class: battery

Another possibility is this note in auto-entities: Many integrations cannot be matched due to Home Assistant limitations
If this integration is one of those then your only choice is integration: battery_notes and if that does not list the missing ones then you’ll have to include them specifically by entity_id or by name

1 Like

@dbrunt You’ve found the reason! By integration identifier homematicip_local I can catch those devises:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - integration: homematicip_local
      domain: binary_sensor
      attributes:
        device_class: battery
    - integration: battery_notes
      domain: binary_sensor
      attributes:
        device_class: battery
  exclude: []

May I am going to raise an issue for auto-entities card.
Many thanks for your help, I really appreacate your support and persistence!

1 Like

Hey @hoca2023 , I know this post was a while ago but I found it was just what I was looking for. I’m pretty new to HA, so your Regex will also serve me well elsewhere.
A added a wee bit to your code to give the gauges some red, amber and green sections: -

‘type’ : “gauge”,
‘entity’ : state.entity_id,
‘name’: state.attributes.friendly_name|regex_replace(find=‘(:|)(Batterie|)(Battery|)(level|numeric|)’, replace=‘’, ignorecase=True),
‘needle’ : true,
‘severity’ : {
‘green’: 30,
‘yellow’: 10,
‘red’: 0
},

I’ll need to learn how to post properly formatted yaml, now :-/

Also know this post is old but have added a bit more to order items by low battery first

type: custom:auto-entities
card:
  type: grid
  title: Battery Status
  columns: 4
  square: false
card_param: cards
filter:
  template: |-
    {% set ns = namespace(x=[]) %}
    {% for e in states.sensor %}
      {% set ns.x = ns.x + [{
        "entity_id": e.entity_id,
        "name": e.attributes.friendly_name,
        "state": e.state | int(0)
      }] %}
    {% endfor %}

    {% for e in ns.x | sort(attribute='state') -%}
        {%- if (e.entity_id | regex_match("sensor.*battery*", ignorecase=True)) -%}
            {{
              {
                'type' : "gauge",
                'entity' : e.entity_id,
                'name': e.name|regex_replace(find='(:|)(Batterie|)(Battery|)(level|numeric|)', replace='', ignorecase=True),
                'severity': {
                  'green': 30,
                  'yellow': 10,
                  'red': 0
                },
                'card_mod' : {
                  'style': "ha-card > div {\n   font-size: 10px !important;\n}"
                },
                'options' : {
                  'entities': [
                    e.entity_id,
                  ], 
                }
              }
            }},
        {%- endif -%}
    {% endfor %}
  exclude:
    - entity_id: sensor.total_battery_energy_charged
    - entity_id: sensor.total_battery_energy_discharged
    - entity_id: sensor.battery_power_charging
    - entity_id: sensor.battery_power_discharging
sort:
  method: attribute
  attribute: battery
  reverse: false
  numeric: true