ioBroker.hue icon indicating copy to clipboard operation
ioBroker.hue copied to clipboard

Code error for Scene-operations main.ts line 489

Open seb2010 opened this issue 1 year ago • 12 comments

In the current source code of /src/main.js of commit aa7c8fb has a code-error in line 489 which prohibits changes of scenes for light-groups. The reference to the lightScene is not found. Current code const sceneObj = await this.getObjectAsync(${channelId}.scene_${commands.scene.toLowerCase()});

it needs to be changed at least to const sceneObj = await this.getObjectAsync(${this.namespace}.lightScenes.scene_${commands.scene.toLowerCase()});

or better with replacing "lightScenes" with the dynamic object-group-namespace.

seb2010 avatar Dec 13 '23 15:12 seb2010

I don't get it, feel free to create an PR. For me the scenes start properly

grafik

foxriver76 avatar Dec 13 '23 16:12 foxriver76

You are showing the scenes for a "room". I do not have rooms. Under the hue-instance I do see all objects listed (lights and lightgroups mixed). I am migrating from hue-extended, so I am not familiar with the regular and the legacy-data-structure yet. Do you use the legacy one? image I only see the scenes under hue.0.lightScenes

seb2010 avatar Dec 13 '23 16:12 seb2010

Legacy just adds a useless device object in between instance and first channel. So this should not make a difference.

Can you show me the light scenes folder

foxriver76 avatar Dec 13 '23 16:12 foxriver76

image To avoid confusion, I am on beta adapter-version 3.10.1

seb2010 avatar Dec 13 '23 16:12 seb2010

issue still persists after latest update to 3.10.2.

Your example above shows a scene-example for a group scene. When polling the Bridge info and creating the scene-objects, you do differntiate between group-scenes and global scenes (https://github.com/iobroker-community-adapters/ioBroker.hue/blob/0012c509c794526e23f18ae2571a4342c32878ec/src/main.ts#L2136). I am using global scenes, you are just handling group scenes in the code for the command-handling.

seb2010 avatar Dec 26 '23 22:12 seb2010

Sorry but what you are writing does not seem right from code perspective or you see something which I do not see. Group scenes are handled in a way that they are created at the corresponding group, else they are created at lightScenes.

https://github.com/iobroker-community-adapters/ioBroker.hue/blob/21194ae683ccb73b26bb2e03108ad1cbcc06f118/src/main.ts#L2161-L2190

And the state change handling is implemented for every dp starting with scene_ like the ones in your lightScenes channel does.

https://github.com/iobroker-community-adapters/ioBroker.hue/blob/21194ae683ccb73b26bb2e03108ad1cbcc06f118/src/main.ts#L256-L273

You should also see the corresponding log message Started scene: .... Please re-check, maybe something has changed with the scenes API but code-wise it looks correct.

foxriver76 avatar Jan 03 '24 07:01 foxriver76

Hi @foxriver76 : I think the misunderstanding is about how these scene get triggered.

I am NOT changing the state of a scene datapoint. I am issueing a command in order to set a certain scene to a group of lights. The scene is not defined as a group scene for this group, but as a global scene.

Following example for the data structure:

  • hue.0.Wohzimmer.* --> the light-group I want to control
  • hue.0.lightScenes.scene_tagesbeleuchtung --> the scene I want to set for the light
  • hue.0.Wohzimmer.command --> datapoint I am writing to with the value {"scene": "tagesbeleuchtung","transitiontime": 4}

This code here https://github.com/iobroker-community-adapters/ioBroker.hue/blob/21194ae683ccb73b26bb2e03108ad1cbcc06f118/src/main.ts#L490-L497 can only handle a scene handed over in the command, which is a scene within the scope of the light/group I want to change. It refers to ${channelId}.scene_${commands.scene.toLowerCase()}.

If you want to set a global scene, which is not defined in the scope of the light/group, but as a global scene under the lightScenes folder, you would need to refer to another namespace, which is ${this.namespace}.lightScenes.scene_${commands.scene.toLowerCase()}

seb2010 avatar Jan 08 '24 12:01 seb2010

Okay, maybe I do not fully understand which kind of scene this is. AFAIR there were scenes corresponding to a group and the Light Scenes which you can create and also define which lights are connected to the scene https://github.com/peter-murray/node-hue-api/blob/typescript/docs/scenes.md#createscene

So I am not aware how we can set a scene to lights not correlated to the specific scene by its configuration. But if you have a setup running, please feel free to create a PR.

foxriver76 avatar Jan 08 '24 13:01 foxriver76

I am afraid I do not know how PRs work and how to interact. If you want a quick fix, which still favours group-scenes over global scenes, new line 492ff would be:

 var sceneObj = await this.getObjectAsync(`${channelId}.scene_${commands.scene.toLowerCase()}`);
 if(sceneObj === null){sceneObj = await this.getObjectAsync(`${this.namespace}.lightScenes.scene_${commands.scene.toLowerCase()}`);}

seb2010 avatar Jan 08 '24 13:01 seb2010

And you have tested that this works as expected? ;-)

foxriver76 avatar Jan 08 '24 14:01 foxriver76

yes, but only by modifying the code directly in the node_modules folder :P

seb2010 avatar Jan 08 '24 14:01 seb2010

@foxriver76 I created a PR for this

seb2010 avatar Mar 26 '24 05:03 seb2010