TuyaAPI / cli

🔧 A CLI for Tuya devices
MIT License
261 stars 44 forks source link

Set true to a Bluetooth subdevice only working sporadically, set off always works #162

Closed caco3 closed 1 year ago

caco3 commented 1 year ago

I have a Water Irrigation Timer (SOP18) from here: https://www.amazon.de/dp/B09P3VRVVB/ref=pe_27091401_487027711_TE_SCE_dp_2

I would like to switch it on/off somehow using an API.

The Gateway and the Timer are linked and the wizard finds them:

tuya-cli wizard
? Do you want to use these saved API credentials? *** Yes
? Provide a 'virtual ID' of a device currently registered in the app: bf641c545b9e1920da14vi
[
  {
    name: 'Wi-Fi hub',
    id: 'bf641c545b9e1920da14vi',
    key: 'V+IuH~QWR`)v6A{r',
    subDevices: [
      {
        name: 'Bewässerungscomputer',
        id: 'bf166cmaafamcows',
        cid: 'f2a63e4085f363b6'
      }
    ]
  }
]
  1. With protocol 3.3 I am able to read the status:

    > tuya-cli get --ip 192.168.1.170 --id bf641c545b9e1920da14vi --key 'V+IuH~QWR`)v6A{r' --protocol-version 3.3 --cid f2a63e4085f363b6 --full
    {
      dps: {
        '1': true,
        '4': 0,
        '7': 32,
        '9': 7311,
        '10': 'cancel',
        '11': 599,
        '12': 'manual',
        '14': false,
        '15': 1111
      },
      cid: 'f2a63e4085f363b6'
    }
  2. I am always able to switch it off:

    > tuya-cli set --ip 192.168.1.170 --id bf641c545b9e1920da14vi --key 'V+IuH~QWR`)v6A{r' --protocol-version 3.3 --cid f2a63e4085f363b6 --set false --dps 1
    Set succeeded.
  3. How ever I am only sporadically able to switch it on:

      tuya-cli set --ip 192.168.1.170 --id bf641c545b9e1920da14vi --key 'V+IuH~QWR`)v6A{r' --protocol-version 3.3 --cid f2a63e4085f363b6 --set false --dps 1
      Set succeeded.

    Most of the time how ever I get a timeout when trying to switch it on:

      Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Timeout waiting for status response from device id: bf641c545b9e1920da14vi')
          at TuyaDevice.emit (events.js:303:17)
          at /usr/local/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:434:12
          at Timeout._onTimeout (/usr/local/lib/node_modules/@tuyapi/cli/node_modules/p-timeout/index.js:25:13)
          at listOnTimeout (internal/timers.js:554:17)
          at processTimers (internal/timers.js:497:7) {
        code: 'ERR_UNHANDLED_ERROR',
        context: 'Timeout waiting for status response from device id: bf641c545b9e1920da14vi'
      }
caco3 commented 1 year ago

ok, I think I got it working now. It seems that the time needs to be set beforehand. If i dont do this, the timer (dps 119 is set to 0 and this might prevent it from switching on and giving a response.

So I do now this:

tuya-cli set --ip 192.168.1.170 --id bf641c545b9e1920da14vi --key 'V+IuH~QWR`)v6A{r' --protocol-version 3.3 --cid f2a63e4085f363b6 --set true --dps 11 --set 3600 # Or what ever time you want to keep it on
tuya-cli set --ip 192.168.1.170 --id bf641c545b9e1920da14vi --key 'V+IuH~QWR`)v6A{r' --protocol-version 3.3 --cid f2a63e4085f363b6 --set true --dps 1