unparagoned / njsTuya

Openhab interface for Tuya home automation devices sold under various names
27 stars 11 forks source link

Exception while testing your stuff. #4

Closed japdos closed 6 years ago

japdos commented 6 years ago

That's happen when I tried to use your scripts within openhab. (I'm able to use njstuya.js with node and get working right) but when trying to use both scripts (items and rules) within openhab, this is shown every 2 minutes (cron entry): any idea? I cann't integrate ir with openhab which would be very usefull.

2018-03-04 13:36:14.921 [INFO ] [.eclipse.smarthome.model.script.Tuya] - Execute action [NULL STATUS] : resp [/etc/openhab2/scripts/node_modules/node-forge/lib/aes.js:203 var len = tmp.length(); ^ TypeError: tmp.length is not a function at forge.aes.Algorithm.initialize (/etc/openhab2/scripts/node_modules/node-forge/lib/aes.js:203:19) at new forge.cipher.BlockCipher (/etc/openhab2/scripts/node_modules/node-forge/lib/cipher.js:118:18) at Object.forge.cipher.createCipher (/etc/openhab2/scripts/node_modules/node-forge/lib/cipher.js:42:10) at new TuyaDevice (/etc/openhab2/scripts/node_modules/tuyapi/index.js:62:43) at Object. (/etc/openhab2/scripts/njstuya.js:26:12) at Module._compile (module.js:571:32) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:488:32) at tryModuleLoad (module.js:447:12) at Function.Module._load (module.js:439:3)]

japdos commented 6 years ago

I solved myself: the rules file has commented code for the rule 'TuyaConfig'. I had to move it after val definitions, btw.

interist commented 6 years ago

Hi jadpos, I am quite new to openHAB, coding, etc. So I managed to find the IP, ID and key of all my Tuya smart plugs and am getting the ON / OFF in the terminal. However I am quite stuck now and not able to continue. How exactly within the Paper UI I am managing those plugs? Since there is no Tuya binding I don't know how to connect the plugs to my Sitemaps or Panel. I hope you can summarize in few short steps what I can do further and how. Many thanks in advance!

unparagoned commented 6 years ago

@interist This isn't a proper binding yet. So it might be a bit complicated for a newbie to use, but not impossible. Try starting out using the njstuya.js directly then look at the rules that run njstuya.js, and things should start making sense.

To add it to the Paper UI you would need to make a thing. I've never made a thing before so it's not something I can help you with but if you search there should be a few examples. I use habpanel, and added the code the the README.

This works mainly by sending commands to the correct item and then the rules will do what you need. Essentially this is where the magic happens, you can do it through rules, or some other means

executeCommandLine("/usr/bin/node /etc/openhab2/scripts/njstuya.js ON", 50000)

@japdos I have the TuyaConfig in another file since it has the keys, so I have it commented out in the rule file for you to uncomment and complete. I should have made that clear in the readme.

bmachek commented 6 years ago

I also get this error when trying to run njstuya.js from the command line. Can someone enlighten me what I'm doing wrong. Thanks.

unparagoned commented 6 years ago

@bmachek If you are getting the same error then just do what what that user said to fix it "the rules file has commented code for the rule 'TuyaConfig'. I had to move it after val definitions, btw."

amitn16 commented 5 years ago

@interist can you share the step to get the ip, id and key details and thereafter getting on/off working from command line. I tried to do following, but no success

clone njsTuya in script folder using git install "npm install codetheweb/tuyapi" created developer app in tuya iot to fetch app key and secret key then trying "node njstuya" with ip of plug which i got after configuring it from smart life app along with device id, which also can be taken from smart life app.

unparagoned commented 5 years ago

Getting the keys were the hardest part. I got them by getting an app to perform an MITM attack while registering a device. There is a new wizzard you can you that should work. I haven'tried it though. Try the instruction here https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md

amitn16 commented 5 years ago

I had tried all options :( but no luck.

I tried to use key from captured from various sources e.g.

  1. through Tyua IOT platform developer portal, buy creating an app and fetch app & secret key from there as mentioned in "https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md", but in last step it gives timeout and device is not getting registered.

  2. MITM attack on smart life app using capture packet… here i can find my local key

  3. MITM attack on smart life app using capture packet… here i can find my client id

In all 2 & 3 options, command executed without an error, but my plug not responding on that.

any help/direction would be helpful