vinodsr / node-red-contrib-tuya-smart-device

a node-red module for managing tuya smart devices
https://flows.nodered.org/node/node-red-contrib-tuya-smart-device
MIT License
43 stars 15 forks source link

Tuya Wizard CLI set works, but via Node Red, No Joy? #111

Closed Jibun-no-Kage closed 1 year ago

Jibun-no-Kage commented 1 year ago

I can connect and disconnect just file, but if I sand DPS 1, set false, device does not disconnect power. Whereas with tuya-cli wizard if I set 'true' and sent dps 1, the device disconnects power just as expected. Given that the cli wizard works, I know my key and such is correct. Also I can do a get --full and that returns results. but can't seem to get any 'get' query to return results.

Clearly there is some type of communication issue with the Node Red nodes...

error: object message: "Timeout waiting for status response from device id: XXXX"

Where as after disconnecting NR nodes. Then use the CLI...

# tuya-cli get --ip 192.168.X.X --id XXX --key XXX --protocol-version 3.1 --full { devId: 'XXX', dps: { '1': true, '2': 0, '4': 731, '5': 762, '6': 1176 } }

vinodsr commented 1 year ago

Are you trying node red and cli from the same machine ?

On Wed, 12 Apr 2023 at 3:53 AM, Jibun-no-Kage @.***> wrote:

I can connect and disconnect just file, but if I sand DPS 1, set false, device does not disconnect power. Whereas with tuya-cli wizard if I set 'true' and sent dps 1, the device disconnects power just as expected. Given that the cli wizard works, I know my key and such is correct. Also I can do a get --full and that returns results. but can't seem to get any 'get' query to return results.

Clearly there is some type of communication issue with the Node Red nodes...

error: object message: "Timeout waiting for status response from device id: XXXX"

Where as after disconnecting NR nodes. Then use the CLI... tuya-cli get --ip 192.168.X.X --id XXX --key XXX --protocol-version 3.1 --full

{ devId: 'XXX', dps: { '1': true, '2': 0, '4': 731, '5': 762, '6': 1176 } }

— Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/111, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OBBMKV5SAJ5B72GNVDXAXKWRANCNFSM6AAAAAAW23LGI4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Vinod Surendran R vinodsr.dev

Jibun-no-Kage commented 1 year ago

Yes. And, I am explicitly validating that ONLY the wizard or NR have the active connection at any given time. If you need any more information or testing just let me know. Am 30 year IT entire engineer, so I can help as needed. Just not a JavaScript guru.

vinodsr commented 1 year ago

Ok. . that's great

Can you please share the node red server logs while connecting tuya

On Fri, 14 Apr 2023 at 1:26 AM, Jibun-no-Kage @.***> wrote:

Yes. And, I am explicitly validating that ONLY the wizard or NR have the active connection at any given time. If you need any more information or testing just let me know. Am 30 year IT entire engineer, so I can help as needed. Just not a JavaScript guru.

— Reply to this email directly, view it on GitHub https://github.com/vinodsr/node-red-contrib-tuya-smart-device/issues/111#issuecomment-1507533915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADQ6OH6GA2OC7BCECXNEPLXBBK6TANCNFSM6AAAAAAW23LGI4 . You are receiving this because you commented.Message ID: @.*** com>

-- Vinod Surendran R vinodsr.dev

Jibun-no-Kage commented 1 year ago

Will have time this weekend to work on this. Not forgotten.

msillano commented 1 year ago

In my experience, this type of error (if the device connects regularly) mostly comes from a malformed message for the tuya_smart_device node. Some details can be found here: step 12, in an article that deals with the process of discovering the capabilities of the single dp of the Tuya devices. I hope this information can help.

Jibun-no-Kage commented 1 year ago

I got it working with SOME of my smart switches. But I have two, that are just not working. I can query the two switches via tuya-cli wizard, set them just fine with same. So I know they are active, I can use them via my phone using the generic tuya app. It is only the NR node method that does not want to work with these 2 smart plugs.

Jibun-no-Kage commented 1 year ago

There is still a pending question! How to you do a FULL get query?

msillano commented 1 year ago

Jibun-no-Kage wrote:

I can query the two switches via tuya-cli wizard, set them just fine with same. ........ It is only the NR node method that does not want to work with these 2 smart plugs.

This sounds very strange to me: both tuya-cli and tuya-smart-device node are wrappers around the same library: tuyapi, what one does also does the other! (if they are the same version).

The way to deal with these problems is always only one: reverse engineering of the Tuya protocol of critical DPs, capturing in node-red the MQTT messages received and sent using SmartLife (which should work).


How do you do a FULL get query?

try SCHEMA.

GET returns always the value of a single PD: they can be atomic data (boolean, int, etc.) or an encoded string (usually base64), which, once decoded, becomes a structure with many data: an example is here.

There is the 'SCHEMA' option, which returns the values of all the DPs present in the device, but it is implemented in a few devices. In node-red use::

      {
       "payload": {
          "devId": "60a453fffe******",         //cid, only if subdevice in gateway
          "operation":"GET",
          "schema"=true
          } }

Best regards. m.s.

Jibun-no-Kage commented 1 year ago

@msillano Thanks. I got the simple GET (per device) query working. I swear I had it right, but it did not seem to want to work, so recreated the node, and it worked. I was just trying to get {"operation":"GET"} working. I created a type of call back flow, so that when a given smart plug is 'on' the icon and color/background of the dashboard button change in NR, similar to what the various apps do. The trick was to only issue the GET once the state of CONNECTED was returned of course. So, for my need, all done. Thanks for the assistance.