This is a simple node.js server, which allows managing TUYA devices via POST requests.
Obtain the project
$ git clone https://github.com/beshkin/automation-server-nodejs.gitInstall dependences
$ npm installStart server
$ npm run startNote: You need npm 14.x+
If you want to run the server as a service, I suggest using pm2
Install PM2
$ npm install pm2 -gStart an application
$ pm2 start app.jsListing all running processes:
$ pm2 listIt will list all process. You can then stop / restart your service by using ID or Name of the app with following command.
$ pm2 stop all$ pm2 stop 0$ pm2 restart allSwitch on/off Tuya device.
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"deviceId":"DEVICE_ID","key":"DEVICE_KEY","ip":"DEVICE_IP", "action":"[off|on]"}' \
http://localhost:8001/switch/tuya/powerGet Tuya device status
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"deviceId":"DEVICE_ID","key":"DEVICE_KEY","ip":"DEVICE_IP"' \
http://localhost:8001/switch/tuya/powerSwitch on/off Mi device
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"key":"DEVICE_KEY","ip":"DEVICE_IP", "action":"[off|on]"}' \
http://localhost:8001/switch/mi/powerGet Mi device status
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"key":"DEVICE_KEY","ip":"DEVICE_IP"' \
http://localhost:8001/switch/mi/powerSet brightness for Mi lamps
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"key":"DEVICE_KEY","ip":"DEVICE_IP","brightness":100}' \
http://localhost:8001/switch/mi/brightnessGet brightness for Mi lamps
$ curl --header "Content-Type: application/json" \
--request POST \
--data '{"key":"DEVICE_KEY","ip":"DEVICE_IP"}' \
http://localhost:8001/switch/mi/brightnesshttps://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf