Remove string from entities name in auto-entities card

Hi,

I’m using a simple auto-entities card to show the batteries level of different sensors.

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - entity_id: sensor.*battery_level*
        - entity_id: sensor.*battery_numeric*
      exclude:
        - entity_id: sensor.gm1903_battery_level
    sort:
      method: state
      numeric: true

So I get a card with all my sensors and their level of battery.
But the name on each line is the name of the entity containing obviously “Battery level” or “Battery numeric”.

Is there a way to remove the “Battery level”, “Battery numeric” of each entities in the card ?
I know I could add each entities manually and force the name.
But, the purpose of the auto-entities in this case, is to avoid forgetting to add a newly added sensor battery level.
Something with regex somewhere ? card-mod ?

Thx
amans

  1. These questions should be asked in a dedicated auto-entities thread (already present). No need to create 100500 new threads about the same. Also, chances of getting a right answer is higher.
  2. In short - use a “template” option to specify a “name” dynamically stripped of useless text.

Hi,

I didn’t think it was specifically auto-entities related.
For those who could be interrested by the template (Could probably be improved) :

type: grid
columns: 1
square: false
title: Batteries
cards:
  - type: custom:auto-entities
    card:
      type: entities
      show_header_toggle: false
      state_color: false
    filter:
      template: |-
        {% for state in states.sensor -%}
          {%- if (state.entity_id | regex_match("^sensor.*_battery($|_level$|_numeric$)", ignorecase=False)) and ("gm1903_battery_level" not in state.entity_id) -%}
            {{
              {
                'entity': state.entity_id,
                'name': state.attributes.friendly_name|regex_replace(find='(:|)(Battery|)(level|numeric|)', replace='', ignorecase=True)
              }
            }},
          {%- endif -%}
        {%- endfor %}
    sort:
      method: state
      numeric: true
1 Like

Hi @amans
I’m trying to get my head around this, can you maybe help me out?

From my NAS I get these sensors:

So I tried making a card like this:

type: custom:auto-entities
filter:
  include:
    - entity_id: sensor.private_cpu_temperature
    - entity_id: sensor.private_temperature_drive*
  filter:
    template: |-
      {% for state in states.sensor -%}
        {%- if (state.entity_id | regex_match("^sensor.private_temperature_drive_", ignorecase=False)) -%}
          {{
            {
              'entity': state.entity_id,
              'name': state.attributes.friendly_name|regex_replace(find='Private Temperature ', replace='', ignorecase=True)
            }
          }},
        {%- endif -%}
      {%- endfor %}
card:
  type: custom:apexcharts-card
  header:
    show: true
    title: NAS
    show_states: true
    colorize_states: true
  graph_span: 7d
  apex_config:
    legend:
      show: false
  all_series_config:
    stroke_width: 1
    type: line
    curve: smooth
    group_by:
      duration: 6h
      func: avg

But it still shows the normal full name:

1 Like