Tuya Local and Protocol 3.5 support

I have been a longtime user of localtuya and tried to configure a recently purchased triple USB tuya plug that looks like that below. localtuya has been suggested by most of the tutorials online and is one of the most popular add-ons. The device name showing up on the SmartLife app is 3CH Wifi USB Switch Module CBU. As a side note, the advertisement claim is accurate and all 3 plugs can indeed be individually switched on or off. In addition, there is also a timer function that will automatically switch off the selected plug after a certain duration.

image

After struggling for over an hour, I finally made a breakthrough. Firstly, newer devices may utilize Protocol Version 3.5 which is not backward compatible with older versions. Also localtuya as of now does not support Protocol Version 3.5 so it will not detect the device, manually adding the device and setting the DP values will result in switches that cannot be clicked.

In order to troubleshoot if version compatibility is the issue, tuya-cli is a very useful tool. If you attempt to connect using Protocol Version 3.4 and it fails at session key negotiation and the socket gets terminated, your device may be using Protocol Version 3.5.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
npm i @tuyapi/cli -g
# DEBUG=* tuya-cli get --ip 192.168.1.123 --id abcd --key 'abc123!@#' --protocol-version 3.4
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.1.123... +3ms
  TuyAPI Socket connected. +55ms
  TuyAPI Protocol 3.4, 3.5: Negotiate Session Key - Send Msg 0x03 +4ms
  TuyAPI Socket closed: 192.168.1.123 +107ms
# DEBUG=* tuya-cli get --ip 192.168.1.123 --id abcd --key 'abc123!@#' --protocol-version 3.5
  TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.1.123... +2ms
  TuyAPI Socket connected. +28ms
  TuyAPI Protocol 3.4, 3.5: Negotiate Session Key - Send Msg 0x03 +2ms
  TuyAPI Received data: 0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz +111ms
  TuyAPI Parsed: +2ms
  TuyAPI {
  TuyAPI   payload: <Buffer 34 31 33 38 ...>,

Once you have verified that the your device is using Protocol Version 3.5, you can use tuya local instead which supports Protocol Version 3.5. In my case, the device was automatically detected, and after a few nexts the device was successfully setup. It is so trivial that it's not worth documenting.