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.
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.
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.
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
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)