Snapshot_entities of a group separately from each other

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?

Thank you!

1 Like

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.

Regards,
Max

Any way we could convert this into a feature request? I’d love to be able to use snapshot_entities on groups.

2 Likes

@shadkianash unfortunately no, I gave up on this idea

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:

service: scene.create
data:
  scene_id: snapshot_woonkamer_current
  snapshot_entities: >-
    {{expand(state_attr('light.woonkamer', 'entity_id'))|map(attribute='entity_id')|list}}
9 Likes

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.

The script can be found here.

3 Likes

Hello, first thank you I was looking for this for some time.

I am quite new to templates.

Is there any possibility to also expand entities field in script? I tried myself but without luck.

Script:

alias: Lights partying on
fields:
  party_lights:
    selector:
      entity:
        multiple: true
        domain: light
    name: Lights
    required: true
sequence:
  - service: scene.create
    data:
      snapshot_entities: >-
        {{expand(state_attr('light.party_lights',
        'entity_id'))|map(attribute='entity_id')|list}}
      scene_id: beforeparty

And to add to all of this I am passing light group in the field.