Closed unparagoned closed 6 years ago
Tried it, error keeps the same, sorry.
[10:43:57] openhabian@openHABianPi:~$ cd /etc/openhab2/scripts
[10:46:32] openhabian@openHABianPi:/etc/openhab2/scripts$ npm install codetheweb/tuyapi
/etc/openhab2/scripts
└─┬ tuyapi@2.0.1 (git://github.com/codetheweb/tuyapi.git#290d6e937130d15e091a143cd094b6f8b2979eab)
├─┬ debug@3.1.0
│ └── ms@2.0.0
├─┬ net-retry-connect@0.1.1
│ └── retry@0.9.0
├── node-forge@0.7.1
└─┬ string-occurrence@1.2.0
├── escape-string-regexp@1.0.5
└── regex-occurrence@1.0.0
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.
[10:46:56] openhabian@openHABianPi:/etc/openhab2/scripts$
I spun up a new VM to test it from scratch. Here is pretty much everything I did well I've left out making the folder since that's not that relevant.
cd /etc/openhab2/scripts
sudo apt install npm
(npm init --yes this is completely optional but reduces the number of warning in the next step)
npm install codetheweb/tuyapi
You can ignore the warnings, it's installed fine, I think they are all about if you were trying to make your own npm script. Download and copy scripts njstuyamonitor.py and njsTuya.js to the scripts folder
That should be it. You can test the scripts as below. Use the monitor to find all devices on the network. To use njstuya.js you need to have found your key,
$ cd /etc/openhab2/scripts --You should still be in this folder so shouldn't need to do this
$ python njstuyamonitor.py
{ Devices: [ { -ip 192.168.0.11 -id 01234654984984989798 -key }, { -ip 192.168.0.15 -id 01234654984984982343 -key } ] }
$ node njstuya.js -ip 192.168.0.11 -id 01234654984984989798 -key 4c9c4b34242348e0f STATUS
OFF
edit: @renegade2k let me know if it works
After a little bit of tinkering, the scripts worked for me. My problems were almost entirely caused by running an old node v4.2.6, so i had to update a couple things. ^_^
I imagine a requirements.txt would be nice in the repo (unless my version of python is so old that the timeout package comes with it now.
houghtelin@lifebook ~/scripts $ python njstuyamonitor.py
Traceback (most recent call last):
File "njstuyamonitor.py", line 9, in <module>
from timeout import timeout
ImportError: No module named timeout
So I had to install timeout.
pip install timeout
Following that, there was another easily remedied Python error. Although, I'm running Python v2.7.12 on this old box. I'll update eventually. ¯_(ツ)_/¯
houghtelin@lifebook ~/scripts $ python njstuyamonitor.py
Traceback (most recent call last):
File "njstuyamonitor.py", line 24, in <module>
@timeout(2, os.strerror(errno.ETIMEDOUT))
TypeError: timeout() takes exactly 1 argument (2 given)
Removing the second argument stopped it from complaining without upgrading Python and produced the expected data.
houghtelin@lifebook ~/scripts $ python njstuyamonitor.py
{ Devices: [ { -ip 192.168.0.3 -id 012008585ccf7f7195ec -key } ] }
I stumbled through a lot of issues due to the fact i was running node v.4.2.6 but after updating to node v8.9.4, I was able to use the njstuya.js script just fine.
houghtelin@lifebook ~/scripts $ node njstuya -ip 192.168.0.3 -id 012008585ccf7f7195ec -key 85533c7d251ed19b STATUS ON
ON
houghtelin@lifebook ~/scripts $ node njstuya -ip 192.168.0.3 -id 012008585ccf7f7195ec -key 85533c7d251ed19b STATUS OFF
OFF
and running the script did actuate the power status of the power outlet I was attempting to change the state of. Thanks @unparagoned !
when doing this: cd /etc/openhab2/scripts npm install codetheweb/tuyapi
I get the following: npm WARN checkPermissions Missing write access to /etc/openhab2/scripts 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.
npm ERR! path /etc/openhab2/scripts npm ERR! code EACCES npm ERR! errno -13 npm ERR! syscall access npm ERR! Error: EACCES: permission denied, access '/etc/openhab2/scripts' npm ERR! { [Error: EACCES: permission denied, access '/etc/openhab2/scripts'] npm ERR! stack: npm ERR! 'Error: EACCES: permission denied, access \'/etc/openhab2/scripts\'', npm ERR! errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access', npm ERR! path: '/etc/openhab2/scripts' } npm ERR! npm ERR! Please try running this command again as root/Administrator.
I have also tried: sudo npm install codetheweb/tuyapi and I get this: 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-6c3f62ce': Permission denied npm ERR!
Any idea? What's missing?
@nicobfg that looks like permission issues. ` $ whoami openhabian
$ ls -al /etc/openhab2/scripts ... drwxrwxr-x+ 10 openhab openhabian 4096 Jun 9 03:26 node_modules ... ` This is to check to see if the normal user openhabian has permissions to the scripts folder. You shouldn't need sudo.
$ ls -al /etc/openhab2/scripts drwxr-xr-x 61 root root 4096 Jun 8 01:20 node_modules How can I change that?
@nicobfg If you are using openhabian then
sudo openhabian-config
Then Apply Improvements, Fix permissions.
You might be able to change permissions of that folder, but you might get other permission errors for other folders. You can use whoami to find out your username, then use chown to add that user to the permissions for the folder.
So for your output it looks like the following should work.
sudo chown "$(whoami)":root /etc/openhab2/scripts
ok got it. This is progress! Thank you!
Am I missing something in the install?
$ npm install codetheweb/tuyapi npm WARN saveError ENOENT: no such file or directory, open '/etc/openhab2/scripts/package.json' 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.
@nicobfg that looks fine. Follow the rest of the steps to check it works
@unparagoned Thank you for your help - I just turned ON and OFF one of the switch in the house. My 3-year old thinks I am doing magic! ;-)
@renegade2k @Ericmas001 @jhoughtelin You should cd into the dir of the script then install tuyapi
Let me know if that works