Tuya Cloud platform and homey scripting

I have got everything working, but since the device is not in the Tuya app, I have created a virtual device with the App Device Capabilities.

First I needed to get the device id and the name of the Capabilities, this can be done by dumping out all devices and capabilities with this code and find the device id and the capabilites (this only needs to be done once):

console.log(await Homey.devices.getDevices());

Then i use the device ID:

const device = await Homey.devices.getDevice({ id: 'whatever the ID is' });

To get the value of the Capability i use the name with this code:

device.capabilitiesObj['whatever the name of the capability is'].value);

Then i compare the value recived with the script and update if it is out of sync:

  if ((device.capabilitiesObj['whatever the name of the capability is'].value) !== (result.result[position].value)) {
    await Homey.devices.setCapabilityValue({
    deviceId:'whatever the ID is', 
    capabilityId:'whatever the name of the capability is',
    value: (result.result[position].value)});
    console.log('På/Av oppdatert med:',(result.result[position].value));
  }

Hope this helps if someone is trying the same. Was a lot of trial and error to get the device and set the value of the capabilities.

1 Like