Template to return a list of entities

Heya! I need a list of entities for ZHA integration.
I used

{{ integration_entities('zha') }}

but this returns only entity id’s - how can I have id and friendly name in format:

entity_id1, friendly_name1
entity_id2, friendly_name2

entity_id10, friendly_name10

Something like this?

{% for entity in integration_entities('zha') -%}
  {{ entity }}, {{ state_attr(entity, 'friendly_name') }}
{% endfor %}
1 Like

omg! this is what I needed! Thank you!

so the script was happy for a long time till a recent update :frowning_face:

Migrate legacy File notify service for domain `file`
The File notify.print_export service is migrated, but it seems the old notify service is still being used.

A new notify entity is available now to replace each legacy notify service.

Update any automations or scripts to use the new notify.send_message service exposed with this new entity. When this is done, select Submit and restart Home Assistant.

and a file is just full of brackets


1517 lines of brackets

Are you hoping that we’ll be able to help without seeing your script?

1 Like

omg I thought I put it already :face_with_open_eyes_and_hand_over_mouth:

export:
  alias: print_entity_attributes
  sequence:
    - service: notify.print_export
      data_template:
        message: |
           {% for state in states %}{{ integration_entities('Zigbee Home Automation') }}
           {% endfor %}
  mode: single
  icon: mdi:cloud-print-outline
  

configuration.yaml:

- name: print_export
  platform: file
  filename: /config/www/export.txt
  timestamp: false

Bizarre. That iterates through every State object in the system, and for each one, prints the list of entities associated with “Zigbee Home Automation”. That list is empty, probably because that’s not the backend name of the integration.

Surely your message template should be as per @pjcrosier’s post above?

{% for entity in integration_entities('zha') -%}
  {{ entity }}, {{ state_attr(entity, 'friendly_name') }}
{% endfor %}

It was working just as I used it a few times.
Also, the integration name is correct

weird

It really wasn’t; not using that template, at least.

No it isn’t. The backend name is as in the URL when you go to the integration screen (I’m using FKB as I don’t have any ZHA stuff):

Try your template out in Developer Tools / Template:

that is even more bizarre! I already had there zha instead of Zigbee (…) nd it works perfectly fine! Thank you for pointing me in the right direction. But how on earth my script code has been changed? no idea :stuck_out_tongue:

1 Like

all works as expected

export:
  alias: print_entity_attributes
  sequence:
    - service: notify.print_export
      data_template:
        message: |
           {% for entity in integration_entities('zha') -%}
           {{ entity }}, {{ state_attr(entity, 'friendly_name') }}
           {% endfor %}
  mode: single
  icon: mdi:cloud-print-outline
1 Like