iobroker-community-adapters / ioBroker.hue

Control Philips Hue Bridge
http://www.iobroker.org
Apache License 2.0
43 stars 26 forks source link

Code error for Scene-operations main.ts line 489 #541

Open seb2010 opened 7 months ago

seb2010 commented 7 months ago

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.

foxriver76 commented 7 months ago

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

grafik

seb2010 commented 7 months ago

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

foxriver76 commented 7 months ago

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

seb2010 commented 7 months ago

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

seb2010 commented 7 months ago

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.

foxriver76 commented 6 months ago

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.

seb2010 commented 6 months ago

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:

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()}

foxriver76 commented 6 months ago

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.

seb2010 commented 6 months ago

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()}`);}
foxriver76 commented 6 months ago

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

seb2010 commented 6 months ago

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

seb2010 commented 4 months ago

@foxriver76 I created a PR for this