# Zigbee 5 Gang Switch Tuya

**URL:** <https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882>\
**Category:** Developers\
**Tags:** zigbee\
**Created:** [February 1, 2024, 9:08am UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882 "2024-02-01T09:08:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahzadsk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/shahzadsk/32/12505_2.png) [@shahzadsk](https://community.homey.app/u/shahzadsk)\
**Post date:** [February 1, 2024, 9:08am UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882/1 "2024-02-01T09:08:26Z")

</div>

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](https://community.homey.app/t/zigbee-single-gang-tuya-switch/102807), 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!

```auto
'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);
}

}

```

---

<div class="post-metadata">

**Author:** ![shahzadsk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/shahzadsk/32/12505_2.png) [@shahzadsk](https://community.homey.app/u/shahzadsk)\
**Post date:** [February 5, 2024, 10:27am UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882/2 "2024-02-05T10:27:50Z")

</div>

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

I am a bit “stuck” on this part…

Thanks!

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [February 5, 2024, 10:03pm UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882/3 "2024-02-05T22:03:15Z")

</div>

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 🙂 If it’s using the Tuya cluster 61184 I need to better understand the device before I can guide you.

---

<div class="post-metadata">

**Author:** ![shahzadsk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/shahzadsk/32/12505_2.png) [@shahzadsk](https://community.homey.app/u/shahzadsk)\
**Post date:** [February 5, 2024, 10:16pm UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882/4 "2024-02-05T22:16:29Z")

</div>

@johan_bendz

The interview is here [#694](https://github.com/JohanBendz/com.tuya.zigbee/issues/694) - and yes I believe it is using 61184

---

<div class="post-metadata">

**Author:** ![shahzadsk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/shahzadsk/32/12505_2.png) [@shahzadsk](https://community.homey.app/u/shahzadsk)\
**Post date:** [February 10, 2024, 11:38pm UTC](https://community.homey.app/t/zigbee-5-gang-switch-tuya/102882/5 "2024-02-10T23:38:35Z")

</div>

@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.
