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?
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:
all_lights:
sequence:
service: group.set
data:
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
script:
create_all_group:
alias: Create group of all domain entities
sequence:
service: group.set
data:
object_id: "{{ group }}"
entities: >-
{{ states[domain] | map(attribute="entity_id") | join(", ") }}
automation:
- alias: Create All Lights Group on Startup
trigger:
platform: homeassistant
event: start
action:
- service: script.create_all_group
data:
domain: light
group: all_lights
- service: script.create_all_group
data:
domain: cover
group: all_covers
Lovelace
type: button
tap_action:
action: navigate
navigation_path: /lovelace/svetla
show_icon: true
show_name: true
entity: group.all_lights
hold_action:
action: call-service
service: light.turn_off
service_data: {}
target:
entity_id: all
icon: 'mdi:lightbulb-group-outline'
name: Světla
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
Not really. Default behavior is toggle on tap. And I don’t want to turn on all the lights
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