Hi all,
I’m attempting to modify existing drivers / write a new one to get this working as well with @johan_bendz great Tuya pro app.
I’m struggling to set sub-device capability to on or off. I’ve tried a few things, but can’t seem to get it to play nice - so I must be missing something.
Similar to the other thread, the device can send on/off to the various gangs (1 main device on switch 1 and 4 sub-devices (switches 2 to 5)), but can’t deal with the responses. The setCapabilityValue seems to set all the gangs to “on” or all to “off” instead of the respective one.
Any help / guidance on this would be appreciated - @robertklep or anyone else if you can let me know what I’m doing incorrectly, I can keep at it!
Many thanks!
'use strict';
const { debug, Cluster } = require('zigbee-clusters');
const TuyaSpecificCluster = require('../../lib/TuyaSpecificCluster');
const TuyaSpecificClusterDevice = require("../../lib/TuyaSpecificClusterDevice");
const TuyaOnOffCluster = require('../../lib/TuyaOnOffCluster');
const {getDataValue} = require('./helpers');
Cluster.addCluster(TuyaSpecificCluster);
Cluster.addCluster(TuyaOnOffCluster)
class wall_switch_5_gang_tuya extends TuyaSpecificClusterDevice {
async onNodeInit({ zclNode }) {
await super.onNodeInit({ zclNode });
this.printNode();
// debug(true);
if (!this.isSubDevice()) {
await zclNode.endpoints[1].clusters.basic.readAttributes('manufacturerName', 'zclVersion', 'appVersion', 'modelId', 'powerSource', 'attributeReportingStatus')
.catch(err => {
this.error('Error when reading device attributes ', err);
});
}
//
const { subDeviceId } = this.getData();
this.log('Sub device ID:', subDeviceId);
// Register capability listeners for the sub-device
/* this.registerCapabilityListener('onoff', async (value) => {
await this.setSubDeviceCapabilityValue(subDeviceId, 'onoff', value);
}); */
if (!subDeviceId) {
this.registerCapabilityListener('onoff', async (value) => {
this.log('onoff gang 1:', value);
return this.writeBool(1, value)
.catch(err => {
this.error('Error when writing to device: ', err);
});
});
} else if (subDeviceId === 'secondGang') {
this.registerCapabilityListener('onoff', async (value) => {
this.log('onoff gang 2:', value);
return this.writeBool(2, value)
.catch(err => {
this.error('Error when writing to device: ', err);
});
});
} else if (subDeviceId === 'thirdGang') {
this.registerCapabilityListener('onoff', async (value) => {
this.log('onoff gang 3:', value);
return this.writeBool(3, value)
.catch(err => {
this.error('Error when writing to device: ', err);
});
});
} else if (subDeviceId === 'fourthGang') {
this.registerCapabilityListener('onoff', async (value) => {
this.log('onoff gang 4:', value);
return this.writeBool(4, value)
.catch(err => {
this.error('Error when writing to device: ', err);
});
});
} else if (subDeviceId === 'fifthGang') {
this.registerCapabilityListener('onoff', async (value) => {
this.log('onoff gang 5:', value);
return this.writeBool(5, value)
.catch(err => {
this.error('Error when writing to device: ', err);
});
});
}
zclNode.endpoints[1].clusters.tuya.on("reporting", value => this.processResponse(value));
zclNode.endpoints[1].clusters.tuya.on("response", value => this.processResponse(value));
this.log("🚀 5 Gang Wall switch booted up!")
}
async processResponse(data) {
const dp = data.dp;
const parsedValue = getDataValue(data);
this.log('Wall switch on/off received', parsedValue);
try {
await this.setCapabilityValue('onoff', parsedValue);
} catch (e) {
this.log("Failed to set on/off", e);
}
}
onDeleted() {
this.log('5 Gang GPP Wall Switch removed ', subDeviceId);
}
}