Using template as source with flex-table-card

I’d like to use the template expression label_entities(‘EELIGHTS’) as the source for entities in flex-table-card. I’ve tried putting that expression in various places, including a {% for %} for the entities: include, but have no success as yet.

I have tried calling a script without success:

sequence:
  - variables:
      response: |-
        {% set ns = namespace(entities=[]) %}
        {% for e in label_entities('EELIGHTS') | expand %}
          {% set ns.entities = ns.entities + 
            [ 
              { 
                'name': e.name,
                'id': e.entity_id,
                'state': e.state,
                'setting': states('input_text.'+ (e.entity_id | replace('switch.', '')))
              }
            ]
          %}
        {% endfor %}
        {{ ns.entities }}
  - stop: done
    response_variable: response
alias: GetLights
description: ""

with the following in dashboard:

          - type: custom:flex-table-card
            entities: []
            action: script.getlights
            columns:
              - name: ID
                data: x.name
              - name: State
                data: x.state
              - name: Setting
                data: x.setting

Use your switch.tapo* include then add some excludes for the extra items.

I have this to just get the door open/close sensors.

entities:
  include:
    - binary_sensor.*door*
  exclude:
    - binary_sensor.*universal*
    - binary_sensor.*battery*
    - binary_sensor.*home_*
    - binary_sensor.*door_lock

I do not think that will produce a list, this does:

{{ label_entities('Television') | list  }}

Produces:


[
  "switch.switchlinc_relay_dual_band_1f_a6_c9",
  "switch.switchlinc_relay_dual_band_1f_bd_69"
]

Template editor can be very valuable to debug.

What I need to known is how to get some list such as that over to the flex-table-card?

Ok, super.

What I need to known then is how to get some list such as that over to the flex-table-card? I tried using a script but don’t know how to debug it further.

So, I should give up on using labels, or template, or script?

Never give up if it is something you want to do. :slight_smile:
The way I showed you will certainly cause more work if you end up adding more sensors that would be included in binary_sensor.door. You might have to add more excludes.

I don’t have time to look in depth right now. But, according to the script docs for stop, the response_variable must be key value pairs. Your are outputting a list.

If you look at the docs for flex-table-card, the list in the output of the script is created as the value of a key output.

Thanks for all the help. Got the script to work by nesting the array within an object in the response, and using the name of the object in the dashboard.

1 Like