Zigbee 5 Gang Switch Tuya

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

}

@johan_bendz any advice / suggestions on how to tackle this one?

I am a bit “stuck” on this part…

Thanks!

Hi @shahzadskm do you have an interview to share?

If the device is using cluster 6 (on/off) on all endpoints I think your code is a bit overworked :slight_smile: If it’s using the Tuya cluster 61184 I need to better understand the device before I can guide you.

@johan_bendz

The interview is here #694 - and yes I believe it is using 61184

@johan_bendz if you have some time (I know too many requests and messages!) - would appreciate some guidance - for this device set capability only works on the main device (gang 1) - struggling to work through which command to use to manage sub device.