Is it possible to get entity_id's from a group?

Is it possible to get all the entity_id’s inside a group? I tried:

{% set entity_ids = states.group.living_room.attributes.entity_id %}

and

{% set entity_ids = states('group.living_room.attributes.entity_id') %}

Anyone else have ideas how to accomplish this?

1 Like

Would a loop serve your needs?


{% for item in states.group.living_room.entity_id %}
{{ item }}
{% endfor %}

Remember that you can test these in the template dev tool.

Where is this dev tool? I’ve been bashing my head on the keyboards with these scripts because I cannot see the state of objects

1 Like

Bottom of the left sidebar of the UI. A template debugger, a list of states, a services/API tool… Take a look at this (specifically, “The dev tools are your friend”)

Thanks! Always wondered what that last page was. At first glance it doesn’t look like an editor.

in templating editor, writing “unknown” for

    {% for item in states('group.all_lights.attributes.entity_id') %}
       {{ item }}
    {% endfor %}

does anyone have any idea?

Use states.group.all_lights.attributes.entity_id

Is it possible to list all the entities of the group in service call?
Something like this (HA throws error):

script:
  test:
    sequence:
      service: camera.snapshot
      data_template:
        entity_id: "{% for item in states.group.cams.attributes.entity_id %}{{ item }},{% endfor %}"
        filename: "/Data/cams/{{ entity_id.name }}.jpg"

I’m not sure what you are trying to do there. Jinja is pretty limited with for loops with home assistant. Value templates typically require 1 output value. That basically makes using {{ value }} in a for loop useless.

For your case, you’ll need to create a separate script for each one of those cams. this is wrong now