Tuya Switch Control (Jinvoo, Smart Life)

I already own (4) raspberrypi. I use them to create my own voice activated devices in my house. Right now I am working on a project to automate my adjustable bed so I can use Alexa as my bed remote. :smile:

WELL I FELL really STUPID::zipper_mouth_face:

:astonished: Your CODE already does the function of setting multiple dps values.:hugs::star_struck:

Please disregard my pull request. IT IS NOT NEEDED!

To get njstuya.js to do multiple dps sets in one command use the following format for -set

To change the light to on and set color to yellow:

-set '{ \"multiple\": true, \"data\": { \"1\": true, \"2\": \"colour\", \"5\": \"ffc400002effff\" } }'

or 

to set the plug on and the usb port on that plug on:

-set '{ \"multiple\": true, \"data\": { \"1\": true, \"7\": true } }'

So the string you suggested will not work, but it was close. I get the impression you do not own a tuya light bulb :

This format WILL WORK

-set '{ "multiple": true, "data": { "2": "scene", "6": "bd76000168ffff" } }'

So any user using this format: beware of which dps values take strings, booleans or numbers.

Here is an example that sets the brightness and color temp. of my tuya bulb

-set '{ "multiple": true, "data": { "1": true, "2": "white", "3": 183, "4": 210 } }'

I am sorry for distributing you and I am sorry for making the pull request.:no_mouth: I now need to see if I can do this with the MQTT version (tuya-mqtt.exe).

THANK YOU, for pointing out this NEW FEATURE! to your amazing code!!!:sunglasses:

The mqtt version should do what you want in an automated fashion. So you just tell it you want it to be white and it should sort out our the dps stuff in the background.

Hi @unparagoned,
I could not locate the issue. I reverted back to a backup OH image BEFORE my tuya adventure and started all over again. However, this time I encountered many errors during the installation and could not get your script to work at all. The first set of errors were these messages

[19:23:53] openhabian@openHABianPi:/etc/openhab2/scripts$ sudo npm install unparagoned/njsTuya
[sudo] password for openhabian:

npm ERR! code 128
npm ERR! Command failed: /usr/bin/git submodule update -q --init --recursive
npm ERR! fatal: Could not change back to '/root/.npm/_cacache/tmp/git-clone-c7f4ed9e': Permission denied
npm ERR!

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-04-03T23_24_18_072Z-debug.log

The install instruction did not call for root but somehow the error messages seemed to indicate so. I’m not a programmer and still learning. Most of these (e.g. node , npm,…) are still foreign to me.

What would be a proper response to such errors? Thanks.

That looks like a permissions error. In theory you shouldn’t need sudo but it is required on some systems due to to permission issues. So try without sudo.

npm install unparagoned/njsTuya

Otherwise try

sudo -i -u openhabian npm install unparagoned/njsTuya

Or if that doesn’t work you should just delete or fix the permissions of /root/.npm/_cacache. You probably have user permissions rather than root or vise versa.

sudo chown openhabian:root /root/.npm/_cacache
or 
sudo chown root:openhabian /root/.npm/_cacache

@unparagoned The problem is that @AgentK uses the dps topic to send back information on the state of the device. I tried using it but the code ends up in a loop, because it tries to send and receive on the same topic. In fact what happened was that I set the bulb to 1 and my command was just overwritten by the current state of the bulb which was OFF so the command sent to the device ended up being OFF.

I sent @AgentK a pull request. I got two different JSON formats working all under the command topic. I also got ON, OFF to work like it should.

The balls now in his court if he wants to incorporate my additions or not.

but I made sure the two JSON formats work like they do in your script:

To set one dps value

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

To set multiple dps values

{ "multiple": true, "data": { "1": true, "7": true } }

I changed my update to go with more your suggestion of using the topic or switch that was already available in the code.

Another NOTE; I forgot to mention that @AgentK does a conversion of all the characters placed in the message area with the following code.

He first converts it to a string than to lowercase but then he does this:

return cmessge == 1  ? 'on' : "off";

So basically anything you put into the message field gets converted to “off”, EVEN the “on” string gets converted to “off”. The only value that gets converted to ‘on’ is a “1”!!!

If you place the “on” next to the command topic as follows:

command topic in current version of tuya-mqtt

tuya/<tuyaAPI-type>/<tuyaAPI-id>/<tuyaAPI-key>/<tuyaAPI-ip>/command/on 

@AgentK will send the string on as straight string (not a JSON string). I know you added the dpsJ topic, but I saw no need to keep it around since I needed to fix the “ON”,“on”,“OFF”,“off” problem anyways.

So my update fixes more than just adding the JSON strings.

BTW @unparagoned, I am sure you are aware of the following command:

process.on('unhandledRejection', err3 => {
    debug("unhandledRejection listener caught the Error, the Message is: ", err3.message);
});

That line will suppress this output from going to the log and stderr but still let it show up in the DEBUG=* LOGS :

[19:24:13] openhabian@openHABianPi:/etc/openhab2/scripts$ node node_modules/njstuya
(node:4131) UnhandledPromiseRejectionWarning: undefined
(node:4131) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4131) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:4131) UnhandledPromiseRejectionWarning: Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:4131) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

I honestly, believe its due to network traffic on the Wifi that this shows up some times. Every time it happens I just rerun the command again and it goes through!!

When I get time, I plan to test this theory with the use of a spare Wifi router and extra tuya bulbs and tuya plugs with my windows openhab2 server. The tuya plug and bulb and my machine will be the only things on this Wifi network and I will see if the problem goes away.

@unparagoned, I followed your instructions and was able to install your script without the npm errors. However, there were npm warnings

[19:14:51] openhabian@openHABianPi:/etc/openhab2/scripts$ npm install unparagoned/njsTuya
npm WARN saveError ENOENT: no such file or directory, open '/etc/openhab2/scripts/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/etc/openhab2/scripts/package.json'
npm WARN scripts No description
npm WARN scripts No repository field.
npm WARN scripts No README data
npm WARN scripts No license field.

+ njstuya@2.2.3
added 62 packages from 76 contributors and audited 81 packages in 55.797s
found 0 vulnerabilities

Based on your comment here,
https://github.com/unparagoned/njsTuya/issues/3#issuecomment-395934533, those should be normal responses?

But when I tested my install,

node node_modules/njstuya

I got the following errors:

[19:24:13] openhabian@openHABianPi:/etc/openhab2/scripts$ node node_modules/njstuya
(node:4131) UnhandledPromiseRejectionWarning: undefined
(node:4131) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4131) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:4131) UnhandledPromiseRejectionWarning: Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:4131) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

So I am stuck again :disappointed_relieved:. Please give me another hint. Thank you.

@oh_newbie, Hi,

That error is really just a warning, TRY THE COMMAND TWICE. I BET IT goes through on the second send of the command line.

This is the error I was talking. njsTuya is not the one throwing that error. Its coming from one of the TuyAPI calls. It’s really a bad socket connection type of error.

If you’ll -> npm install debug, using the following command:

npm install debug

After you install debug, you will be able to run (on raspberry pi) at the bash prompt

$ DEBUG=* node node_modules/njstuya

For windows users at the cmd.exe prompt:

>cd c:/openhab2/userdata/etc/scripts/node_modules
>set DEBUG=* & node tuya-mqtt.js

You can give him a better output of all the debug statements. DEBUG is really a nice module to have installed on your machine.

@GadgetAngel @unparagoned
I tried the command several times without success. I installed npm debug as suggested and ran the test command again. Here was output:

[20:49:55] openhabian@openHABianPi:/etc/openhab2/scripts$ DEBUG=* node node_modules/njstuya
  njstuya booting njstuya +0ms
  njstuya api {} or undefined +48ms
  TuyAPI Finding missing IP  or ID  +0ms
  TuyAPI Disconnect +10s
(node:12689) UnhandledPromiseRejectionWarning: undefined
(node:12689) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12689) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:12689) UnhandledPromiseRejectionWarning: Error: find() timed out. Is the device powered on and the ID or IP correct?
(node:12689) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

BTW, I do have @AgentK MQTT script running at system start up:

/usr/bin/node /etc/openhab2/scripts/tuyaapi_mqtt/tuya-mqtt.js

Could this cause the error?

@oh_newbie, ARE you sure your -id and -key and -ip address are correct?

OH, I see where it’s gone wrong. Don’t you need to have the command look like this?

$DEBUG=* node njstuya.js -ip 192.168.0.30 -id 5846055184f3eb20bfaf -key afb9b013346054e6 -set '{  "multiple": true, "data": { "1": true, "7": true } }'

if you just type in node njstuya.js , the command is suppose to get an error. It was designed to do that because you sent it an illegal command.

Confirmed. It looks to me that I cannot have @AgentK MQTT script and @unparagoned njstuya script running at the same time.

After disabling the MQTT script, I was able to run njstuya script without error.
Thanks.

@oh_newbie, having MQTT running is like having the Smart Life App open when you are running the script. The devices are not very smart and do not have a lot of compute power so they can not listen to more than one port at a time.

These are very small micro controllers you are talking to.

@GadgetAngel
FYI. For my case (when it works)

node node_modules/njstuya

yields


[21:18:04] openhabian@openHABianPi:/etc/openhab2/scripts$ node node_modules/njstuya
{ "devices": [
{ "id": 22544545c44f33808db9, "broadcast": {"ip":"10.5.5.100","gwId":"22544545c44f33808db9","active":2,"ability":0,"mode":0,"encrypt":true,"productKey":"4B6JKjYQnOglMceL","version":"3.1"}, "schema": {"devId":"22544545c44f33808db9","dps":{"1":false,"2":false,"9":0,"10":0,"18":0,"19":0,"20":1157,"21":1,"22":591,"23":24902,"24":14371,"25":1450}} },
] }
{ "devices": [ {"22544545c44f33808db9":{"ip":"10.5.5.100","gwId":"22544545c44f33808db9","active":2,"ability":0,"mode":0,"encrypt":true,"productKey":"4B6JKjYQnOglMceL","version":"3.1","devId":"22544545c44f33808db9","dps":{"1":false,"2":false,"9":0,"10":0,"18":0,"19":0,"20":1157,"21":1,"22":591,"23":24902,"24":14371,"25":1450}}} ] }

…having MQTT running is like having the Smart Life App open when you are running the script. The devices are not very smart and do not have a lot of compute power so they can not listen to more than one port at a time…

Thanks for pointing that out. I learn something new everyday! :smiley:

@oh_newbie, the only advantage that MQTT has over this njstuya script is that MQTT does a keep alive request with your device. If you use the njstuya script you will have to implement a cron job in the rules file to connect to all your devices after a certain length of time.

I believe @unparagoned has an example showing how to do that.

I think you refer to this?

/etc/openhab2/scripts/node_modules/njstuya/rules/temperature.rules
rule "cron Guard"
when
    Time cron "13 0/2 * * * ?"
then
    //CRON only needs to run when unlocked no need to stack updates over other commands
    if(!locktuya.isLocked()){
        var titerator = gTuya.members.iterator
        var delay=1
        while(titerator.hasNext){
            val det = titerator.next
            if(db) { logInfo("Tuya", "Update [{}]", det)}
            createTimer(now.plusMillis(delay), [ |
                sendCommand(det.name + "Command", "STATUS")
            ])
            delay = delay + 1000
        }

    }

1 Like

yes

Sorry to bother with problems, but I cant make it work:

@unparagoned can you help me with this? Thanks… :frowning:

Trying to install and…


sudo npm install unparagoned/njsTuya


(node:12455) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.
npm ERR! git clone git@github.com:github:unparagoned/cloudtuya Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-github-unparagoned-cloudtuya-b866f8d2'...
npm ERR! git clone git@github.com:github:unparagoned/cloudtuya fatal: remote error:
npm ERR! git clone git@github.com:github:unparagoned/cloudtuya is not a valid repository name
npm ERR! git clone git@github.com:github:unparagoned/cloudtuya Email support@github.com for help
npm ERR! git clone git@github.com:github:unparagoned/tuyapi Cloning into bare repository '/root/.npm/_git-remotes/git-github-com-github-unparagoned-tuyapi-18a66305'...
npm ERR! git clone git@github.com:github:unparagoned/tuyapi fatal: remote error:
npm ERR! git clone git@github.com:github:unparagoned/tuyapi is not a valid repository name
npm ERR! git clone git@github.com:github:unparagoned/tuyapi Email support@github.com for help
npm ERR! Error: Not found : cloudtuya
npm ERR! at RegClient. (/usr/share/npm/node_modules/npm-registry-client/lib/request.js:300:14)
npm ERR! at Request._callback (/usr/share/npm/node_modules/npm-registry-client/lib/request.js:238:65)
npm ERR! at Request.self.callback (/usr/lib/nodejs/request/index.js:148:22)
npm ERR! at emitTwo (events.js:126:13)
npm ERR! at Request.emit (events.js:214:7)
npm ERR! at Request. (/usr/lib/nodejs/request/index.js:896:14)npm ERR! at emitOne (events.js:121:20)
npm ERR! at Request.emit (events.js:211:7)
npm ERR! at IncomingMessage. (/usr/lib/nodejs/request/index.js:847:12)
npm ERR! at emitNone (events.js:111:20)
npm ERR! If you need help, you may report this *entire* log,
npm ERR! including the npm and node versions, at:
npm ERR! 

npm ERR! System Linux 4.14.98+
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "unparagoned/njsTuya"
npm ERR! cwd /etc/openhab2/scripts
npm ERR! node -v v8.11.1
npm ERR! npm -v 1.4.21
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /etc/openhab2/scripts/npm-debug.log
npm ERR! not ok code 0

tried git cloning and this was the result:

:~/tuya/njsTuya$ node ./njstuya.js
module.js:549
throw err;
^

Error: Cannot find module 'cloudtuya'
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/home/openhabian/tuya/njsTuya/njstuya.js:20:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)

@unparagoned, I had to reinstall my openhab2 which meant reinstalling you scripts

Something strange is happening:

When I install it and run the command with out parameters your directions say the following should happen:

If no the ip and id are missing then the script will scan the network and return the state schema(state) of all devices.

BTW, i clone your repository before doing the npm install command. So my version of njstuya.js is in the directory c:/openhab2/userdata/etc/scripts/njsTuya

here is the out put I get:

c:\openHAB2\userdata\etc\scripts\njsTuya>node ./njstuya.js
  njstuya booting njstuya +0ms
  njstuya api {} or undefined +6ms
  TuyAPI Finding missing IP  or ID  +0ms
  TuyAPI Received UDP message. +53ms
  TuyAPI Error: Magic prefix mismatch: 020900ffff011200ea000402e803010006ffa906436c61697279080e03
  TuyAPI     at MessageParser._parse (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\lib\message-parser.js:47:13)
  TuyAPI     at Object.parse (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\lib\message-parser.js:176:5)
  TuyAPI     at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:594:28)
  TuyAPI     at Socket.emit (events.js:189:13)
  TuyAPI     at UDP.onMessage [as onmessage] (dgram.js:628:8) +1ms
  TuyAPI UDP data: +1ms
c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:601
        debug(dataRes.data);
                      ^

TypeError: Cannot read property 'data' of undefined
    at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:601:23)
    at Socket.emit (events.js:189:13)
    at UDP.onMessage [as onmessage] (dgram.js:628:8)

So I decided to give it a IP and ID to see what happens and the code works like it should, here is that output:

c:\openHAB2\userdata\etc\scripts\njsTuya>node ./njstuya.js -ip 192.168.0.30 -id 5846055184f3eb20bfaf -key afb9b013346054e6 -get "{ \"schema\": true }"
  njstuya booting njstuya +0ms
  njstuya "{argName} value is: 192.168.0.30 +2ms
  njstuya "{argName} value is: 5846055184f3eb20bfaf +1ms
  njstuya "{argName} value is: afb9b013346054e6 +0ms
  njstuya "{argName} value is: { "schema": true } +0ms
  njstuya api {} or undefined +4ms
  TuyAPI Connecting to 192.168.0.30... +0ms
  TuyAPI Socket connected. +135ms
  njstuya Connected to device! +138ms
  TuyAPI GET Payload: +2ms
  TuyAPI { gwId: '5846055184f3eb20bfaf', devId: '5846055184f3eb20bfaf' } +1ms
  TuyAPI Received response +16ms
  TuyAPI 000055aa000000000000000a000000fb000000007b226465764964223a223538343630353531383466336562323062666166222c22647073223a7b2231223a747275652c2232223a227768697465222c2233223a32372c2234223a3235352c2235223a223030666630343030373966666666222c2236223a223361353962643030653261666263222c2237223a226666666633323031303066663030222c2238223a226666666632303033666630303030303066663030303030306666222c2239223a226666666632303031666630303030222c223130223a226666666633323035666630303030303066663030666666663030666630306666303030306666227d7d9b920deb0000aa55 +0ms
  TuyAPI Parsed response data: +2ms
  TuyAPI { devId: '5846055184f3eb20bfaf',
  TuyAPI   dps:
  TuyAPI    { '1': true,
  TuyAPI      '2': 'white',
  TuyAPI      '3': 27,
  TuyAPI      '4': 255,
  TuyAPI      '5': '00ff040079ffff',
  TuyAPI      '6': '3a59bd00e2afbc',
  TuyAPI      '7': 'ffff320100ff00',
  TuyAPI      '8': 'ffff2003ff000000ff000000ff',
  TuyAPI      '9': 'ffff2001ff0000',
  TuyAPI      '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +1ms
  njstuya runCommand has started with data {"devId":"5846055184f3eb20bfaf","dps":{"1":true,"2":"white","3":27,"4":255,"5":"00ff040079ffff","6":"3a59bd00e2afbc","7":"ffff320100ff00","8":"ffff2003ff000000ff000000ff","9":"ffff2001ff0000","10":"ffff3205ff000000ff00ffff00ff00ff0000ff"}} +23ms
  TuyAPI GET Payload: +5ms
  TuyAPI { gwId: '5846055184f3eb20bfaf', devId: '5846055184f3eb20bfaf' } +0ms
  TuyAPI Received response +12ms
  TuyAPI 000055aa000000000000000a000000fb000000007b226465764964223a223538343630353531383466336562323062666166222c22647073223a7b2231223a747275652c2232223a227768697465222c2233223a32372c2234223a3235352c2235223a223030666630343030373966666666222c2236223a223361353962643030653261666263222c2237223a226666666633323031303066663030222c2238223a226666666632303033666630303030303066663030303030306666222c2239223a226666666632303031666630303030222c223130223a226666666633323035666630303030303066663030666666663030666630306666303030306666227d7d9b920deb0000aa55 +1ms
  TuyAPI Parsed response data: +1ms
  TuyAPI { devId: '5846055184f3eb20bfaf',
  TuyAPI   dps:
  TuyAPI    { '1': true,
  TuyAPI      '2': 'white',
  TuyAPI      '3': 27,
  TuyAPI      '4': 255,
  TuyAPI      '5': '00ff040079ffff',
  TuyAPI      '6': '3a59bd00e2afbc',
  TuyAPI      '7': 'ffff320100ff00',
  TuyAPI      '8': 'ffff2003ff000000ff000000ff',
  TuyAPI      '9': 'ffff2001ff0000',
  TuyAPI      '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } } +0ms
  njstuya Status: [object Object] +19ms
{ devId: '5846055184f3eb20bfaf',
  dps:
   { '1': true,
     '2': 'white',
     '3': 27,
     '4': 255,
     '5': '00ff040079ffff',
     '6': '3a59bd00e2afbc',
     '7': 'ffff320100ff00',
     '8': 'ffff2003ff000000ff000000ff',
     '9': 'ffff2001ff0000',
     '10': 'ffff3205ff000000ff00ffff00ff00ff0000ff' } }
  TuyAPI Disconnect +5ms
  TuyAPI Socket closed: 192.168.0.30 +1ms
  njstuya Disconnected from device. +4ms

So I tried again with out the parameters because you said it should work without specifying anything and again I get an error, Here is the output I keep getting, can you explain what I am doing wrong??

c:\openHAB2\userdata\etc\scripts\njsTuya>node ./njstuya
  njstuya booting njstuya +0ms
  njstuya api {} or undefined +8ms
  TuyAPI Finding missing IP  or ID  +0ms
  TuyAPI Received UDP message. +99ms
  TuyAPI UDP data: +2ms
  TuyAPI { ip: '192.168.0.19',
  TuyAPI   gwId: '15764628dc4f22ff7b04',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'AiHXxAyyn7eAkLQY',
  TuyAPI   version: '3.1' } +0ms
  TuyAPI Received UDP message. +407ms
  TuyAPI UDP data: +1ms
  TuyAPI { ip: '192.168.0.10',
  TuyAPI   gwId: '75070011840d8e53bd0f',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'AiHXxAyyn7eAkLQY',
  TuyAPI   version: '3.1' } +1ms
  TuyAPI Received UDP message. +1ms
  TuyAPI Error: Magic prefix mismatch: 020900ffff011200ea000502e803010006ffa906436c61697279080f03
  TuyAPI     at MessageParser._parse (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\lib\message-parser.js:47:13)
  TuyAPI     at Object.parse (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\lib\message-parser.js:176:5)
  TuyAPI     at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:594:28)
  TuyAPI     at Socket.emit (events.js:189:13)
  TuyAPI     at UDP.onMessage [as onmessage] (dgram.js:628:8) +1ms
  TuyAPI UDP data: +1ms
c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:601
        debug(dataRes.data);
                      ^

TypeError: Cannot read property 'data' of undefined
    at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\njsTuya\node_modules\tuyapi\index.js:601:23)
    at Socket.emit (events.js:189:13)
    at UDP.onMessage [as onmessage] (dgram.js:628:8)

c:\openHAB2\userdata\etc\scripts\njsTuya>

it appears that something has changed in the tuaAPI interface, can you give me some insight?

Any help here would be appreciated

I ran npm install again

npm install unparagoned/njsTuya

Here is the output from the install:

c:\openHAB2\userdata\etc\scripts>npm install unparagoned/njsTuya
npm WARN saveError ENOENT: no such file or directory, open 'c:\openHAB2\userdata\etc\scripts\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'c:\openHAB2\userdata\etc\scripts\package.json'
npm WARN scripts No description
npm WARN scripts No repository field.
npm WARN scripts No README data
npm WARN scripts No license field.

+ njstuya@2.2.3
added 62 packages from 76 contributors and audited 81 packages in 15.761s
found 0 vulnerabilities


I know it should not matter, where its installed I just thought maybe if I typed it in wrong?? Anyways the result is the same. Here is the output running it from node_modules:

c:\openHAB2\userdata\etc\scripts>node node_modules/njstuya
  njstuya booting njstuya +0ms
  njstuya api {} or undefined +7ms
  TuyAPI Finding missing IP  or ID  +0ms
  TuyAPI Received UDP message. +119ms
  TuyAPI UDP data: +3ms
  TuyAPI { ip: '192.168.0.46',
  TuyAPI   gwId: '67833830cc50e3d57eaa',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'bQ59gAWgRIxuiXKQ',
  TuyAPI   version: '3.1' } +1ms
  TuyAPI Received UDP message. +303ms
  TuyAPI UDP data: +1ms
  TuyAPI { ip: '192.168.0.41',
  TuyAPI   gwId: '67833830cc50e3d4cda8',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'bQ59gAWgRIxuiXKQ',
  TuyAPI   version: '3.1' } +1ms
  TuyAPI Received UDP message. +2ms
  TuyAPI Error: Magic prefix mismatch: 020900ffff011200ea000402e803010006ffa906436c61697279080e03
  TuyAPI     at MessageParser._parse (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\lib\message-parser.js:47:13)
  TuyAPI     at Object.parse (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\lib\message-parser.js:176:5)
  TuyAPI     at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:594:28)
  TuyAPI     at Socket.emit (events.js:189:13)
  TuyAPI     at UDP.onMessage [as onmessage] (dgram.js:628:8) +0ms
  TuyAPI UDP data: +2ms
c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:601
        debug(dataRes.data);
                      ^

TypeError: Cannot read property 'data' of undefined
    at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:601:23)
    at Socket.emit (events.js:189:13)
    at UDP.onMessage [as onmessage] (dgram.js:628:8)

c:\openHAB2\userdata\etc\scripts>

Here is the output with node node_models/njstuya -mode local

:\openHAB2\userdata\etc\scripts>node node_modules/njstuya -mode local
  njstuya booting njstuya +0ms
  njstuya "{argName} value is: local +6ms
  njstuya api {} or undefined +4ms
  TuyAPI Finding missing IP  or ID  +0ms
  TuyAPI Received UDP message. +218ms
  TuyAPI UDP data: +3ms
  TuyAPI { ip: '192.168.0.36',
  TuyAPI   gwId: '67833830cc50e3d4e70a',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'bQ59gAWgRIxuiXKQ',
  TuyAPI   version: '3.1' } +0ms
  TuyAPI Received UDP message. +304ms
  TuyAPI UDP data: +1ms
  TuyAPI { ip: '192.168.0.35',
  TuyAPI   gwId: '67833830cc50e3d57761',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'bQ59gAWgRIxuiXKQ',
  TuyAPI   version: '3.1' } +1ms
  TuyAPI Received UDP message. +203ms
  TuyAPI UDP data: +1ms
  TuyAPI { ip: '192.168.0.6',
  TuyAPI   gwId: '50642000840d8e525b6b',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'AiHXxAyyn7eAkLQY',
  TuyAPI   version: '3.1' } +1ms
  TuyAPI Received UDP message. +202ms
  TuyAPI UDP data: +2ms
  TuyAPI { ip: '192.168.0.11',
  TuyAPI   gwId: '05835352dc4f228bf22e',
  TuyAPI   active: 2,
  TuyAPI   ability: 0,
  TuyAPI   mode: 0,
  TuyAPI   encrypt: true,
  TuyAPI   productKey: 'AiHXxAyyn7eAkLQY',
  TuyAPI   version: '3.1' } +0ms
  TuyAPI Received UDP message. +102ms
  TuyAPI Error: Magic prefix mismatch: 020900ffff011200ea000202e803010006ffa906436c61697279080c03
  TuyAPI     at MessageParser._parse (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\lib\message-parser.js:47:13)
  TuyAPI     at Object.parse (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\lib\message-parser.js:176:5)
  TuyAPI     at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:594:28)
  TuyAPI     at Socket.emit (events.js:189:13)
  TuyAPI     at UDP.onMessage [as onmessage] (dgram.js:628:8) +1ms
  TuyAPI UDP data: +2ms
c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:601
        debug(dataRes.data);
                      ^

TypeError: Cannot read property 'data' of undefined
    at Socket.listener.on.message (c:\openHAB2\userdata\etc\scripts\node_modules\tuyapi\index.js:601:23)
    at Socket.emit (events.js:189:13)
    at UDP.onMessage [as onmessage] (dgram.js:628:8)

c:\openHAB2\userdata\etc\scripts>

Again, did I do something wrong??

@GadgetAngel @unparagoned Hi,
Is there a multiple dps get command?
I tried

-get '{ "multiple": true, "data": { "18", "19", "20" }}'

and got errors:

(node:463) UnhandledPromiseRejectionWarning: SyntaxError: Unexpected token , in JSON at position 34
    at JSON.parse (<anonymous>)
    at getState (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:139:16)
    at TuyaDevice.runCommand (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:234:46)
    at emitTwo (events.js:131:20)
    at TuyaDevice.emit (events.js:214:7)
    at Socket.client.on.data (/etc/openhab2/scripts/node_modules/tuyapi/index.js:425:16)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
(node:463) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reje   ction id: 3)
(node:463) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:463) UnhandledPromiseRejectionWarning: undefined
(node:463) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (reje   ction id: 4)

Thanks

if you mean for njstuya use

-get '{ "schema": true}'

the

“multiple” is really for setting multiple dps values

I hope this helps