diff --git a/src/matter/clusters/Base.ts b/src/matter/clusters/Base.ts index 5f4a527e..f657b1ed 100644 --- a/src/matter/clusters/Base.ts +++ b/src/matter/clusters/Base.ts @@ -71,8 +71,14 @@ class Base { clusterId: number, currentValue: any | undefined = undefined, ): Promise { + let _id; // create onOff - const _id = `controller.${jsonNodeId.replace(/"/g, '')}.states.${id}`; + if (id.includes('.')) { + _id = `controller.${jsonNodeId.replace(/"/g, '')}.${id}`; + } else { + _id = `controller.${jsonNodeId.replace(/"/g, '')}.states.${id}`; + } + let stateObj = await this.adapter.getObjectAsync(id); if (!stateObj) { stateObj = { diff --git a/src/matter/clusters/LevelControl.ts b/src/matter/clusters/LevelControl.ts index e22656b4..c46a4b0e 100644 --- a/src/matter/clusters/LevelControl.ts +++ b/src/matter/clusters/LevelControl.ts @@ -75,18 +75,22 @@ class LevelControl extends Base { if (!state || state.ack) { return; } - await cluster.moveToLevel({ - level: state.val as number, - transitionTime: 0, - optionsMask: { - executeIfOff: true, - coupleColorTempToLevel: false, - }, - optionsOverride: { - executeIfOff: false, - coupleColorTempToLevel: false, - } - }); + try { + await cluster.moveToLevel({ + level: state.val as number, + transitionTime: 0, + optionsMask: { + executeIfOff: true, + coupleColorTempToLevel: false, + }, + optionsOverride: { + executeIfOff: false, + coupleColorTempToLevel: false, + } + }); + } catch (e) { + this.adapter.log.error(`Cannot set ${id}: ${e.message}, stack: ${e.stack}`); + } }; await this.subscribe(id, levelHandler); } diff --git a/src/matter/clusters/OnOff.ts b/src/matter/clusters/OnOff.ts index 02ff2cef..4da5993e 100644 --- a/src/matter/clusters/OnOff.ts +++ b/src/matter/clusters/OnOff.ts @@ -17,7 +17,7 @@ class OnOff extends Base { const features = await cluster.getFeatureMapAttribute(); // create onOff const id = await this.createState( - 'booleanState', + 'onOff', { name: 'Boolean state', type: 'boolean', @@ -41,10 +41,14 @@ class OnOff extends Base { if (!state || state.ack) { return; } - if (state.val) { - await cluster.on(); - } else { - await cluster.off(); + try { + if (state.val) { + await cluster.on(); + } else { + await cluster.off(); + } + } catch (e) { + this.adapter.log.error(`Cannot set ${id}: ${e.message}, stack: ${e.stack}`); } }; await this.subscribe(id, onOffHandler);