Auto Entities with Mushroom Cards - Replace String with templating

Hi,

I am currently overhauling my frontend with mushroom cards. They are absolutely great in my opinion. At the first page of my Dashboard I am showing lights, covers, music and windows depending on their state, with the auto entities card in combination with mushroom cards. For example, only Lights, which are turned on are displayed.

Now I am struggeling to remove parts of the names from the entities which are shown to make it even more clearly arranged. Ever cover entities friendly name starts with "Rollo ", and i want to remove that Part, to have only the location in the name and not this prefix.

Here is the code I am using right now:

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    title: |-
      {% if is_state('cover.rollo_alle', 'open') %}
      Folgende Rollo sind geöffnet:
      {% else %}
      {% endif %}
  - type: custom:mushroom-chips-card
    chips:
      - type: conditional
        conditions:
          - entity: cover.rollo_alle
            state: open
        chip:
          type: entity
          entity: cover.rollo_alle
          name: Alle
          content_info: name
          icon_color: blue
      - type: conditional
        conditions:
          - entity: cover.rollo_wohnraum
            state: open
        chip:
          type: entity
          entity: cover.rollo_wohnraum
          icon_color: blue
          name: Wohnraum
          content_info: name
    alignment: center
  - type: custom:auto-entities
    card:
      square: false
      columns: 2
      type: grid
    card_param: cards
    filter:
      include:
        - domain: cover
          state: open
          options:
            type: custom:mushroom-cover-card
            show_position_control: true
            show_buttons_control: true
      exclude:
        - entity_id: cover.rollo_alle
        - entity_id: cover.rollo_wohnraum
    show_empty: true

And this is the result:

My approach is to template the name of the Mushroom Cards entities like this:

type: custom:mushroom-cover-card
            name: {{state_attr('this.entity_id', 'friendly_name')|regex_replace(find='Rollo ', replace='', ignorecase=False) }}
            show_position_control: true
            show_buttons_control: true

But this is not working. If i remove the template and type for example “name: hello”
it looks like this:


So the princiiple of renaming is working.

Maybe any of you guys already has a solution or an idea what to do.

Thanks

It’s been quite a while since I’ve used auto-entities, but you could try this:


filter:
  template: |-
    {% for x in states.cover %}
      {% if x.state == 'open' %}
      - type: custom:mushroom-cover-card
        entity: {{ x.entity_id }}
        name: {{ state_attr(x.entity_id, 'friendly_name') |replace('Rollo','') }}
        show_position_control: true
        show_buttons_control: true
      {% endif %}
    {%- endfor %}

Thanks for your hint. Its now another result, but still not working:

Ah, I see. Works a little bit different:


type: custom:auto-entities
card:
  type: grid
  columns: 2
  square: false
card_param: cards
filter:
  template: |-
    {% for x in states.cover -%}
      {%- if x.state == 'open' -%}
        {{
          {
            'type': 'custom:mushroom-cover-card',
            'show_position_control': true,
            'show_buttons_control': true,
            'entity': x.entity_id,
            'name': state_attr(x.entity_id, 'friendly_name')|replace('Rollo ', '')

          }
        }},
      {%- endif -%}
    {%- endfor %}

4 Likes

You are my hero! Thank you so much!!!