Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
seb2010 opened this issue Dec 13, 2023 · 12 comments
Open

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

seb2010 opened this issue Dec 13, 2023 · 12 comments
Labels

Comments

@seb2010
Copy link
Contributor

seb2010 commented Dec 13, 2023

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
Copy link
Member

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

grafik

@seb2010
Copy link
Contributor Author

seb2010 commented Dec 13, 2023

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
Copy link
Member

foxriver76 commented Dec 13, 2023

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
Copy link
Contributor Author

seb2010 commented Dec 13, 2023

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

@mcm1957 mcm1957 added the bug label Dec 15, 2023
@seb2010
Copy link
Contributor Author

seb2010 commented Dec 26, 2023

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 (

if (scene.type === 'GroupScene') {
).
I am using global scenes, you are just handling group scenes in the code for the command-handling.

@foxriver76
Copy link
Member

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.

ioBroker.hue/src/main.ts

Lines 2161 to 2190 in 21194ae

if (!sceneChannelCreated) {
objs.push({
_id: `${sceneNamespace}.lightScenes`,
type: 'channel',
common: {
name: 'Light scenes'
},
native: {}
});
sceneChannelCreated = true;
}
this.log.debug(`Create ${scene.name}`);
objs.push({
_id: `${sceneNamespace}.lightScenes.scene_${scene.name
.replace(/[\s.]/g, '_')
.replace(this.FORBIDDEN_CHARS, '')
.toLowerCase()}`,
type: 'state',
common: {
name: `Scene ${scene.name}`,
role: 'button',
type: 'boolean',
read: false,
write: true
},
native: {
id: sceneId
}
});

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

ioBroker.hue/src/main.ts

Lines 256 to 273 in 21194ae

if (dp.startsWith('scene_')) {
try {
// it's a scene -> get a scene id to start it
const obj = await this.getForeignObjectAsync(id);
const groupState = new v3.lightStates.GroupLightState();
if (!obj) {
throw new Error(`Object "${id}" is not existing`);
}
groupState.scene(obj.native.id);
await this.api.groups.setGroupState(0, groupState);
this.log.info(`Started scene: ${obj.common.name}`);
} catch (e: any) {
this.log.error(`Could not start scene: ${e.message || e}`);
}

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
Copy link
Contributor Author

seb2010 commented Jan 8, 2024

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

ioBroker.hue/src/main.ts

Lines 490 to 497 in 21194ae

if (typeof commands.scene === 'string') {
// we need to get the id of the scene
const sceneObj = await this.getObjectAsync(`${channelId}.scene_${commands.scene.toLowerCase()}`);
if (sceneObj?.native) {
sceneId = sceneObj.native.id;
}
}

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
Copy link
Member

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
Copy link
Contributor Author

seb2010 commented Jan 8, 2024

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
Copy link
Member

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

@seb2010
Copy link
Contributor Author

seb2010 commented Jan 8, 2024

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

@seb2010
Copy link
Contributor Author

seb2010 commented Mar 26, 2024

@foxriver76 I created a PR for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants