Button card for multiple entities

Hi, my idea is use button card for all lights. When some light is on, button should be “active/highlighted”. But how can I setup multiple entity for button?

1 Like

Use group if you are mixing entities (light, switch, etc)

Or light group if they are all lights and retain the light functions.

Then use entity ID of the group to when creating the button. If any item in the group is on the button will show the on state. If you turn it off everything in the group turns off. Same result when you turn the group on, everything turns on.


@silvrr thanks for reply. Is there some simple way how to create a light group for all light entities? I’m using

- service: light.turn_off
  entity_id: all

for turn off all the lights. And when any light from group is on the group is marked as on? Or they all have to be on?

I am not aware of a way to auto generate a group of all lights on your instance.

Your service call will depend on which type of group you use.

If you use the generic Group option your entity ID will be group.something where as if you use the Light Group the entity id will be light.something

For the generic group I would use

- service: homeassistant.turn_off
  entity_id: group.something

For the light group I would use

- service: light.turn_off
  entity_id: light.something

Yes, as noted earlier, if any entity in the group is on, the group will indicate as on.

You can create groups dynamically based on a template using the not-really-documented group.set. You can see an example of how it’s used here.. You can also go into DevTools->Services, type group.set and see the items that can go in the data: block.

Here’s an example of creating a group of all light entities:

      service: group.set
        object_id: test_group
        entities: >-
          {{ states.light|map(attribute="entity_id")|join(", ") }}

That’s a script.

For next generation. Final solution:

Create a group of all entities in domain

    alias: Create group of all domain entities
      service: group.set
        object_id: "{{ group }}"
        entities: >-
          {{ states[domain] | map(attribute="entity_id") | join(", ") }}

  - alias: Create All Lights Group on Startup
      platform: homeassistant
      event: start
      - service: script.create_all_group
          domain: light
          group: all_lights
      - service: script.create_all_group
          domain: cover
          group: all_covers


type: button
  action: navigate
  navigation_path: /lovelace/svetla
show_icon: true
show_name: true
entity: group.all_lights
  action: call-service
  service: light.turn_off
  service_data: {}
    entity_id: all
icon: 'mdi:lightbulb-group-outline'
name: Světla
1 Like

this is not a true solution really. If you have created the group, you can simply toggle the group (the button entity), and don’t need any other service data.
It does the trick alright, because this hold action works even without the group :wink:

Not really. Default behavior is toggle on tap. And I don’t want to turn on all the lights :slight_smile:

what I was saying really is that you explicitly posted about creating the group first, but then, in the action, don’t use that group…

If you want the group only for lighting up the Buttons you can use this in a template to test:

{{ states.light |selectattr('state','eq','on') |list|count == 0}}

and do away with those startup automations. It has the advantage to be dynamic (the template is updated on state changes) while the automation only checks on startup