Correct Syntax for Auto Entities Template including Multiple-Entity-Row

Hi,

I have the following sensor with this formatted output:

Now I want to reformat this in the auto entities card but I only get so far:

How is the correct formatting looking after line 13 ‘state_header’: “Status”,

2 Likes
'state_header': "Status",
'secondary_info': {
  'attribute': "game"
},
'entities': [{
  'attribute': "viewers",
  'name': "Viewers"
}],

…thanks so much! Now I can use this syntax on some other spots as well. Works perfectly!

I have an addition issue. I only want to show the “game” attribute if it is defined and not “none” or “undefined”. How could I add that check to the IF Syntax?

    filter:
      template: |-
        {% for state in states.sensor -%}
          {%- if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) -%}
            {{
              {
                'entity': state.entity_id,
                'name': state.attributes.friendly_name.split('#')[0],
                'type': "custom:multiple-entity-row",
                'secondary_info': {
                  'attribute': "game"
                },
              }
            }},
          {%- endif -%}
        {%- endfor %}

I do not really understand why sometimes there is a “{%” and sometimes it comes with an additional Minus Symbol like this “{%-”

Simply put I would like to parse out the game if set else just the name:

if (game = set) {
 {
  'entity': state.entity_id,
  'name': state.attributes.friendly_name.split('#')[0],
  'type': "custom:multiple-entity-row",
  'secondary_info': {
  'attribute': "game"
  },
} else {
  'entity': state.entity_id,
  'name': state.attributes.friendly_name.split('#')[0],
}

I have this snippet from previous efforts:

{% set game = state_attr('state.entity_id', 'game') %}
{{ game if game is not none else ' ' }}

But my combination efforts so far have not been successful:

    filter:
      template: |-
        {% for state in states.sensor -%}
          {%- if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) -%}
            {%- if state_attr('state.entity_id', 'game') is not none  -%}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                  'secondary_info': {
                    'attribute': "game"
                  },
                }
              }},
            {%- else -%}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                  },
                }
              }},
          {%- endif -%}
        {%- endfor %}

So what works syntax-wise is this:

        {% for state in states.sensor %}
          {% if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) %}
            {% if state_attr(state.entity_id, 'game') is not none %}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                  'secondary_info': {
                    'attribute': "game"
                  },
                }
              }},
            {% endif %}
          {% endif %}
        {% endfor %}

But not if I add the “else” part:

        {% for state in states.sensor %}
          {% if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) %}
            {% if state_attr(state.entity_id, 'game') is not none %}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                  'secondary_info': {
                    'attribute': "game"
                  },
                }
              }},
            {% else %}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                }
              }},
            {% endif %}
          {% endif %}
        {% endfor %}

IT WORKS! After many trial end errors … this is the correct syntax:

      template: |-
        {% for state in states.sensor -%}
          {%- if state.entity_id | regex_match("sensor.discord_user_", ignorecase=False) -%}
            {%- if state_attr(state.entity_id, 'game') is not none -%}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                  'secondary_info': {
                    'attribute': "game"
                  },
                }
              }},
            {%- else -%}
              {{
                {
                  'entity': state.entity_id,
                  'name': state.attributes.friendly_name.split('#')[0],
                  'type': "custom:multiple-entity-row",
                }
              }},
            {%- endif -%}
          {%- endif -%}
        {%- endfor %}
1 Like

Very interesting topic. Funnily, this is the only one I could find where great auto-entities and multiple-entity-row are mixed. Exactly what I was looking for for such a long time.

So… how to get a sensor value of another sensor (instead of the attribute in this case) than the one initially filtered for, which only matches by name?

I want to have the state of a switch entity together with the current power usage entity, looking like this (created manually):

          - type: custom:multiple-entity-row
            entity: switch.plug_eg_kuche_kuhlschrank
            name: Küche Kühlschrank
            toggle: true
            state_color: true
            show_state: true
            secondary_info: last-changed
            entities:
              - entity: sensor.plug_eg_kuche_kuhlschrank_current_consumption
                name: Aktuell
            state_header: ''
            column: false

As you can see the entities only have parts of their name in common:
switch.plug_eg_kuche_kuhlschrank
sensor.plug_eg_kuche_kuhlschrank_current_consumption

Luckily it’s always “sensor” instead of “switch” plus “_current_consumption” as suffix. Can I make a similiar template for auto-entities out of that?

Find my test example for multiple-entity-row in the auto-entities thread.

1 Like

Unfortunately it’s impossible to find your exact post in that huge well-grown topic.

Too bad there‘s no link in the OP to a collection of your implementations (like in the card-mod topic).

Also mess around with the combination of these two custom cards. What I dont understand that the settings for the multiple-entity-row card is definded in the include filter of the auto-entities card. As far as I understand the the include filter just defines which entities should be used in this card. Nevertheless I tested the marked solution without any success. Can someone provide more information how to use these two cards together?

Hi! I have the same problem! Did you solve it in any way?

No, unfortunately I did not so far.
And I don’t have the time currently to further look for a solution :frowning_face:

1 Like

After a lot of fiddling around I found a solution. Which is simply to have a properly json formatted array, e.g put the commas between array elements and not behind the last element

          ...
          template: |-
              {% set ids = states.climate | rejectattr('entity_id', 'is_hidden_entity') %}
              {% set x = namespace(count=0) %}
              [
              {% for e in ids %}
              {% if x.count > 0 %},{% endif %}
              {% set x.count = x.count + 1 %}
              {{ {
                  'entity': e.entity_id,
                  'type': 'custom:mushroom-climate-card',
                    }
                  }
                } }}
              {% endfor %}
              ]

How is this related to multiple-entity-row?

Hey ya’ll,

Necroing a thread here but seems like this info is few and far between. I’m trying to do something along these lines as well but my template isn’t parsing correctly, and I’m not sure why - its very similar to ya’lls above -

type: custom:auto-entities
card:
  type: vertical-stack
card_param: cards
filter:
  template: >-
    {% set STATES = states.image | selectattr('entity_id', 'in',
    integration_entities('planta'))  -%}
    {%- for STATE in STATES -%}
      {{ 
        { 
          'type': 'custom:decluttering-card',
          'template': 'planta_bubble_card',
          'variables': {
            'image_entity': STATE.entity_id,
            'watering_entity': null,
            'misting_entity': "sensor." ~ STATE.entity_id.split("image.")[1] ~ "_scheduled_misting",
            'fertilizing-entity': null,
            'repotting_entity': null,
            },
          } 
        }},
    {%- endfor %}

The null values on the various entities can be ignored, it just leaves a default date when that’s whats passed.

Anyway, the issue isn’t really with the content of the cards - it actually is just reading each part of the array individually instead of reading the array as a single card -

You can see, it fills in the entity list as ‘{’‘type’‘:’, then ‘’‘custom:decluttering-card’‘’, then ‘’‘template’‘’:', etc

  1. There was no need to “necroing» since this should have been asked in the main auto-entities thread. Your question is not related to THIS thread.
  2. Note that “variables” must be a list, in your template it is a dict.
  3. As for the main issue: paste a whole code into Dev tools - Template and you will see what is wrong.