codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.04k stars 333 forks source link

devid not found - when trying to use cid #498

Open lelemm opened 3 years ago

lelemm commented 3 years ago

Hi guys, I'm trying to get schema from a subdevice. I'm not sure if its supported or I'm doing something wrong.

My device looks like this:

  {
    name: 'Smart IR',
    id: 'abc',
    key: 'def',
    subDevices: [
      {
        name: 'Air',
        id: 'ghj',
        cid: 'klm'
      }
    ]
  },

trying to do this after connecting to the device:

device.get({cid:'klm', schema: true}).then(data => console.log(data))

But the answer is:

Connected to device!
  TuyAPI GET Payload: +3ms
  TuyAPI {
  TuyAPI   gwId: 'abc',
  TuyAPI   devId: 'abc',
  TuyAPI   t: '1625717040',
  TuyAPI   dps: {},
  TuyAPI   uid: 'abc',
  TuyAPI   cid: 'klm'
  TuyAPI } +0ms
  TuyAPI GET Payload: +2ms
  TuyAPI {
  TuyAPI   gwId: 'abc',
  TuyAPI   devId: 'abc',
  TuyAPI   t: '1625717040',
  TuyAPI   dps: {},
  TuyAPI   uid: 'abc'
  TuyAPI } +0ms
  TuyAPI Received data: 000055aa000000010000000a0000001c00000001460038f6aa8cbd3394eafef56d9a1537937932ef0000aa55 +8ms
  TuyAPI Parsed: +0ms
  TuyAPI {
  TuyAPI   payload: 'devid not found',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +0ms
  TuyAPI Received DATA packet +1ms
Data from device: devid not found

Any ideas?

Thanks

lelemm commented 3 years ago

Just an update.

Striped all other parameters from GET, left just the CID of the sub device on it:

  TuyAPI GET Payload: +3ms
  TuyAPI { cid: '5078a77cc4ff610b' } +0ms
  TuyAPI GET Payload: +2ms
  TuyAPI {} +0ms
  TuyAPI Received data: 000055aa000000010000000a0000001c00000001460038f6aa8cbd3394eafef56d9a1537937932ef0000aa55 +6ms
  TuyAPI Parsed: +0ms
  TuyAPI {
  TuyAPI   payload: 'devid not found',
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +0ms
  TuyAPI Received DATA packet +1ms
Data from device: devid not found

If I pass the devId from the main device in the cid, it returns data from the main device:

  TuyAPI GET Payload: +2ms
  TuyAPI { cid: 'eba43f851cb1fdbc51ir31' } +1ms
  TuyAPI GET Payload: +1ms
  TuyAPI {} +0ms
  TuyAPI Received data: 000055aa000000010000000a0000002c00000000026ac63d6a7e760645c97ebc062851ded015a652744eeee4253edea62547d065fcb4b5970000aa55 +7ms
  TuyAPI Parsed: +0ms
  TuyAPI {
  TuyAPI   payload: { dps: { '101': 209, '102': 65 } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1
  TuyAPI } +1ms
  TuyAPI Received DATA packet +0ms
Data from device: { dps: { '101': 209, '102': 65 } }

If I pass any value to CID other than the devId from the main device it returns "devid not found"

codetheweb commented 3 years ago

Instead of specifying the CID there, you could try instead creating an instance with

new TuyAPI({
    gwID: 'your-parent-device-id',
    id: 'your-child-device-id',
    ...
})