Tuya-smart-device and tuya-smart-device-generic node questions

I am trying to get either of the above nodes to work. I downloaded the sample flow and it seems straightforward enough.

I have a wifi lightswitch that is connected to my wifi and I obtained the DeviceID and DeviceKey. I can turn on & off the switch using the Smart Home app, but would much rather use Node-RED.

The flow I am trying to get to work is based on the sample flow.

and the function node contains this:
image

The output I get is this, but nothing happens at the switch (will not turn on or off)
image

Anything obvious that I am missing?

All you should need is to connect the Inject Node to the Tuya Node and set the Inject node msg.payload type to JSON and then enter (set is true for On false for Off)

{"dps": 20, "set": true}

or to make it more flexible use the Function node as you have but with the following code;

/* Function Node Input (Set injection Node msg.payload to boolean)
*  msg.payload   - True or false (On or Off)
*/

const setStateDps = 20
let lightState = msg.payload

msg.payload = {dps: setStateDps, set: lightState}

return msg

In either case the msg.topic can be anything you like but best if you use something that helps later.

As a reply for a power socket I get

payload: object
  data: object
     devId: "xxxxxxxx"
     dps: object
       1: false
    t: 1625954080
   deviceId: "xxxxxx"
   deviceName: "Power Switch 02"

Thank you, but I still cannot get it to work.

If I use the Tuya Smart Life app, and I toggle the switch ON or OFF, I can see my responses in the debug pane...

But when I use the Turn On inject node, I get a response that is different and then a Timeout error.

The function node contains what you wrote:
image

For whatever reason, my payload.data contains a string of some number of characters that start with 3.3V when I use the Smart Life app, and no timeout error, and the light stays on. But when I use the Turn On button, I get a string starting with 1v and then a timeout error.

image

Whenever i have seen this it is a corrupted/incorrect key.

I assume you followed the whole process for getting keys at the commandline ? Tuya-CLI all worked OK and returned the info.

Are you sure you have not repaired the device in the Tuya app after getting the device key ?

Have you tried setting it to V3.1 ?

Also simplify it a little

Use the bigger ndoe that you can embed the device information into rather than loading it from a function node. Make sure you only put in the device ID and Key - not the IP address

When i first started - this was what i did and then just used a simple inject node

This is what my node looks like

image

And the inject node just has this

{"set": "silence", "dps" : 2}

Craig

I have to agree with Craig because the message from the node after switching with Smart Life is not what you should get (see the end of my previous reply).

The dps use can vary for different devices so you need a valid message to confirm which to use (having said that most lamps do use the same dps but it DOES vary from 3.1 or 3.3 units)

tinytuya · PyPI is a good webpage to start you off

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.