Creating a scene using call_service or run_sequence

I can’t find anyone trying to do the same in AppDaemon, so lemme show what I’ve tried so far:

self.call_service("scene/create",
                              scene_id=self.get_scene_id(),
                              snapshot_entities=self.get_lights())
self.call_service("scene/create", data={
                'scene_id': self.get_scene_id(),
                'snapshot_entities': self.get_lights()})
self.call_service("scene/create", service_data={
                'scene_id': self.get_scene_id(),
                'snapshot_entities': self.get_lights()
            })
self.run_sequence([{
                'scene/create': {
                    'data': {
                        'scene_id': self.get_scene_id(),
                        'snapshot_entities': self.get_lights()}}}])
self.run_sequence([{
                'scene/create': {
                    'scene_id': self.get_scene_id(),
                    'snapshot_entities': self.get_lights()}}])

where scene_id() returns a string, and get_lights() returns a list of strings.
All of the above throws BadRequest… Any idea what to do?

I’m dumb, scene names can’t contain dots . . .

I’m struggling with the same problem. Can you post the code how you got it to work?

        data =  {
            "scene_id": "scene.testscene",
            "name": "scenetest",
            "entities": {"light.signify_netherlands_b_v_lct015_light_9":{"state": "on", "rgb_color": [200, 0, 5]}}
        }
        
        self.call_service("scene/create", **data)

I get this error:
2023-05-20 23:58:22.420075 WARNING HASS: Error calling Home Assistant service default/scene/create
2023-05-20 23:58:22.421753 WARNING HASS: Code: 400, error: 400: Bad Request

Any help is much appreciated! I’ve been struggling with this all day and not gotten any further

Yes, the id can’t be “scene.xxx” just the name of the scene, in this case “testscene” (ID must not contain “.”)

Great you’re still here :wink: Unfortunately that does not solve the problem, I still get the same error if I remove the dot. I can call the service to turn on a light, so the problem must be how the data formatted.

I can’t find any documentation about how to use call_service, which would be really helpful. Which of the formatting options above did you use?

This is how the data passed in the call_service function looks:

{'scene_id': 'testscene', 'name': 'scenetest', 'entities': {'light.signify_netherlands_b_v_lct015_light_9': {'state': 'on', 'rgb_color': [200, 0, 5]}}}

When using “call_service” the parameters need to be called the same as if you’d call the service in YAML. So instead of “entities” it’s “snapshot_entities”.

  def save_scene(self):
        self.call_service("scene/create",
                    scene_id=self.get_scene_id(),
                    snapshot_entities=self.get_lights())

.

I really appreciate your help! I think snapshot_entities is if you want to take a snapshot of the current states and I want to create the scene just with code.

I got it solved now! I installed Node Red and created a call service node to create the scene - it also failed, but it provided details about what caused the problem and it was the “name” variable - apparently you can’t give the scene a name, instead it uses the scene_id for both name and entity_id.

What I’m trying to achieve is have a bunch of lists of RGB codes and then dynamically create scenes for all rooms in the house where each light will get a color randomly picked from the scene color list and the scene will be different every time the script runs.

I hope I don’t run into more trouble - else I will write again. Thanks!