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?