Hello! I’m trying to build a script that saves and then restores states of my lights, there is a very useful feature in the scene.create service called snapshot_entities, but it seems like it can’t expand groups. This means it simply does not support snapshotting states of group members independent from each other.
So if I try to snapshot a group:
- service: scene.create
data_template:
scene_id: before
snapshot_entities:
- group.living_room
It saves the state of the group, but not of the each member of it.
For example: I have my ceiling light switched off and my floor light switched on. I create a scene with the script from above. This group includes both of those lights. Then I apply a different scene for some time, and when I restore the initial state both bulbs in the group get the same state - the state of the floor light(which was also the state of the group).
Is it possible to snapshot stetes of all members of a group separately, recursively extracting them from the group?
I was able to fix this by turning my lights into a group of the domain “light” instead of just a regular group.
In my case, in my configuration.yaml I have:
light:
- platform: group
name: All Lights
entities:
- light.bathroom
- light.bathroom_overhead_left
- light.bathroom_overhead_right
- light.bedroom
So if you do that for your living_room lights, you can use - light.living_room instead of - group.living_room and it should work because it’s part of the light domain.
Thanks for your answer, but unfortunately it didn’t work even if my lights are grouped with the light platform. When I try to restore the scene saved with scene.create it switches on all group members despite the fact, that only one light was switched on before saving. I assume it just saves on for the whole group, instead of saving state of each separate light.
Hi Gleb, I’m trying to do something like you said here but in my case, I’m trying to save the state of a group of switches. I’m wondering if your were able to solve this.
Hey all, I had the same problem with using light groups in the snapshot_entities data field. I noticed it retrieved and saved the “average” of the lights in the group. So if the group contains three lights, of which one is turned off, one is turned yellow and the last one is blue, the created scene would turn on all the lights in the group to green.
I was able to fix this by using a template which expands the light group to a list, enabling the scene.create to snapshot all the enities in the light group individually. The service call looks like this:
Thank you very much for sharing this template! It was exactly what I needed!
I use the scene.screate in a script that flashes all my phillips hue lights when the security alarm rings. First it creates a snapshot of the state of all the lights in my home. Then, it will repeat a flashing action until the alarm turns off again. Finally, the light states restore to the state they were before.