Horus
December 15, 2021, 7:20pm
1
Hello,
I want to create a group that contains all lights plus some additional switches. I wonder how to mention all lights in the groups entities
section.
I found plenty of related tipps there: PSA: Turn on/off all lights in Home Assistant 0.104+ (group.all_* changes) but they all seem to focus how to use it in templates, not some “virtual” entities like group.all_lights
.
Use case is to have common switch and state for all lights + some switches.
Thanks!
1 Like
petro
(Petro)
December 15, 2021, 7:30pm
2
Use expand on the group inside a template, employing the methods used in the post you linked.
Horus
December 16, 2021, 8:13pm
3
Hey, could you elaborate a bit?
Do you suggest to create a group from a templated expression? How so? Groups don’t seem to support value_template or alike.
Or should I create a sensor and a switch from the template? I think I could do that, but would prefer to use a group.
Thanks!
petro
(Petro)
December 16, 2021, 8:22pm
4
Make the static group. Use the expand function (A home assistant function used to expand groups into state objects) inside a template. Then use the state objects to map the information that you want. I’m not sure what you mean by this
Or this
This however, does exactly what you claim PSA: Turn on/off all lights in Home Assistant 0.104+ (group.all_* changes) doesn’t do. It creates a group of all lights or all switches, and then you can turn on or off the groups.
Horus
December 19, 2021, 9:37am
5
I think we somehow misunderstanding each other…
I can have a group:
beleuchtung:
name: Licht
entities:
- light.esstisch_1
- light.esstisch_2
- light.esstisch_3
- light.esstisch_4
- [... all lights ...]
- switch.janus_1
This group gives me a state and a common switch for all the lights and for switch.janus_1
.
What I am trying to do is instead of writing every single light in the entities
list, is to use an expression for all lights.
Is that possible with a group? Or should I go with a Template Switch - Home Assistant ?
Thanks and sorry for the confusion!
petro
(Petro)
December 19, 2021, 10:57am
6
It’s covered in that thread, just not the main post
Do you have an automation running them on every startup?
Also could there be a way to select only the entity_id’s of the items that have a specific attribute? (like device_clase:motion)
Nevermind, here is how i did it: Create groups with the device_class i want, automation to set them up on startup and a binary sensor to show them to me as safety
script:
create_group_all_motion_sensors:
sequence:
- service: group.set
data_template:
object_id: "all_senso…
- alias: Create Beleuchtung Group
id: create_beleuchtung_group
trigger:
- platform: time
at: '00:00:00'
- platform: homeassistant
event: start
- platform: event
event_type: call_service
event_data:
domain: template
service: reload
action:
- service: group.set
data:
object_id: beleuchtung
entities: >
{{ expand(states.light, 'switch.janus_1') | map(attribute='entity_id') | list }}
4 Likes
scottg489
(Scott G.)
October 9, 2023, 2:09am
7
Thanks Petro! Although this feels a little hacky it works great.
Would it be possible to do something like this for a light group? Meaning, the domain would be light
rather than group, but still have it’s entities defined as a template rather than a static list of entities.
petro
(Petro)
October 9, 2023, 11:14am
8
I don’t believe it’s possible w/ new style groups.
1 Like