How do I change color using this API?
I don’t have access to colour bulbs so I’m not too sure but the first step would be getting the schema of the device. Running with debug would also help
win set DEBUG=* && node example.js
linux DEBUG=* node example.js
I don’t have access to colour bulbs so I’m not too sure but the first step would be getting the schema of the device. Running with debug would also help
win set DEBUG=* && node example.js
linux DEBUG=* node example.js
node example.js is the command to run and that is what I don’t know. How can I get debug output from a command that I don’t have?
Oops I meant
DEBUG=* node node_modules/njstuya/njstuya.js
Oops I meant
DEBUG=* node node_modules/njstuya/njstuya.js
I must not be making my self clear. I know I have to use the command “node …/njstuya.js”. If I want to the state of a light, I issue the command:
node node_modules/njstuya/njstuya.js -mode cloud -id 9999999999999 STATE
That works fine; so does on and off. However, what is the command I would use to change the color of the RGBW light strip?
I don’t know the command. If you run using DEBUG mode it will show the device properties which will help me work out the command.
DEBUG=* node node_modules/njstuya/njstuya.js -mode cloud
I don’t know the command. If you run using DEBUG mode it will show the device properties which will help me work out the command.
DEBUG=* node node_modules/njstuya/njstuya.js -mode cloud
Okay. I see what you are saying now. It produced a lot of output do you really need me to post it all or can you direct me what to look it? If not, is there a portion I should post?
You can post any of it that contains your device. The block that starts cloudtuya [ { data: is nicely formatted. The blocks that start with cloudtuya prefilter is nice and compact.
You can post any of it that contains your device. The block that starts cloudtuya [ { data: is nicely formatted. The blocks that start with cloudtuya prefilter is nice and compact.
The entire output is about 160 lines long. Hopefully, this will give you what you are looking for:
cloudtuya data: {
cloudtuya brightness: '390',
cloudtuya color_mode: 'colour',
cloudtuya online: true,
cloudtuya state: 'false'
cloudtuya },
cloudtuya name: 'THEATERTVLED',
cloudtuya icon: 'https://images.tuyaus.com/smart/icon/15502004153t3ybzjreo6_0.png',
cloudtuya id: '7132272898f4abeb6747',
cloudtuya dev_type: 'light',
cloudtuya ha_type: 'light'
cloudtuya },
cloudtuya prefilter [{“data”:{“online”:true,“state”:false},“name”:“Theater Seat Rumblers”,“icon”:“https://images.tuyaus.com/smart/icon/1512015439_0.png",“id”:“04200099b4e62d136fea”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“brightness”:“390”,“color_mode”:“colour”,“online”:true,“state”:“false”},“name”:“THEATERTVLED”,“icon”:“https://images.tuyaus.com/smart/icon/15502004153t3ybzjreo6_0.png”,“id”:“7132272898f4abeb6747”,“dev_type”:“light”,“ha_type”:“light”},{“data”:{“online”:true,“state”:false},“name”:"Brandon’s Traffic Light”,“icon”:“https://images.tuyaus.com/smart/icon/1528685571e8zjudcjy7u_0.png",“id”:“784465082cf432b58b45”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Movie night sign”,“icon”:“https://images.tuyaus.com/smart/icon/1512015439_0.png",“id”:“04200099b4e62d13684c”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Switch 1”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“10670365bcddc2f9d58c_1”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Switch 2”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“10670365bcddc2f9d58c_2”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:true},“name”:"Switch 1”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“10670365bcddc2fa4c7c_1”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:true},“name”:"Switch 2”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“10670365bcddc2fa4c7c_2”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:true},“name”:"XBox Chargers”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“06200045dc4f2236e565_1”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Shuffleboard Scoreboard”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“06200045dc4f2236e565_2”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Theater Cabinet Power”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“0620004568c63abd5ad0_1”,“dev_type”:“switch”,“ha_type”:“switch”},{“data”:{“online”:true,“state”:false},“name”:"Theater Cabinet Light”,“icon”:“https://images.tuyaus.com/smart/icon/1551088021vd7nif6r6g_0.jpg",“id”:“0620004568c63abd5ad0_2”,“dev_type”:“switch”,“ha_type”:"switch”}] +30ms
I’m sorry but the responses from tuya api don’t contain details about the bulb’s color only the fact it’s a color bulb.So if I had to guess the api doesn’t support changing the color.
I know it’s a pain to set up but local mode should work fine.
I’ve got a similar output from my SmartLight LED light, however the brightness is missing. I’m wondering, is it possible to set color_mode and maybe try brightness as well?
Possible values for me using the SmartLife app are: music, colour, scene, DIY
cloudtuya data: { color_mode: 'music', online: true, state: 'true' },
cloudtuya name: 'Led Lights',
cloudtuya icon: 'https://images.tuyaeu.com/smart/icon/ay1535688520667EMyk6/160238127190477af6b75.png',
cloudtuya id: 'bfe869873c62537a07lurd',
cloudtuya dev_type: 'light',
cloudtuya ha_type: 'light'
On iot.tuya.com, i found the following additional data if that helps:
I have been able to find color using “tuya-cli get” command line, but I could never get the “set” command to work. It looks like this:
$ tuya-cli get --ip 192.168.0.174 --id bfe869873c62537a07lurd --key xxxx --all --protocol-version 3.3
{ dps:
{ '20': false,
'21': 'colour',
'24': '000503e803e8',
'25': '06',
'101': 62,
'102': '0001a401fe',
'103': '01010101000603e8000503e8',
'104': '03' } }
You can either try changing the color with the app and then see what dps items changed but that can
switch the device into encrypted mode so might take a while. Alternatively, just try and change the various dps items and see which ones change the color
node njstuya.js -ip 10.0.0.2 -id 213klj349sdfjl324po32 -key 342kljerw98 -set '{ "dps": 101, "set": 24}'
Or have a look here to see what they do
I would really like to try that, but I get an error when using local mode. Received data appears jumbled, perhaps that’s what you meant by encrypted. Perhaps it has to do with protocol version, is that command argument even implemented? Version 3.3 was necessary to get tuya-cli to work as you can se in my previous post.
Without DEBUG mode, you get a hard crash with no helpful details. A message saying something like “TuyAPI returned parse data error” would be more helpful than “Cannot read property ‘1’ of undefined” for those who don’t yet know about DEBUG mode. If that’s at all possible.
Any ideas how to get this working in local mode? Thanks
Btw, I checked the code you linked but didn’t find any matching property indices. Perhaps a color light is different from LED strip which is what this is. I’m fine with trial and error when it comes to that.
$ DEBUG=* node njstuya.js -ip 192.168.2.163 -id bfe869873c62537a07lurd -key xxxx -protocol-version 3.3 ON
njstuya booting njstuya +0ms
njstuya "{argName} value is: 192.168.2.163 +4ms
njstuya "{argName} value is: bfe869873c62537a07lurd +0ms
njstuya "{argName} value is: xxxx +1ms
njstuya api {"Instructions":"Complete with tuya/smart_life app email/pass/dialingCode/region then rename to key.json","userName":"xxxx@xxxx.xx","password":"xxxx","countryCode":"43","bizType":"smart_life","region":"EU"} or xxxx@xxxx.xx +1ms
TuyAPI Connecting to 192.168.2.163... +0ms
TuyAPI Socket connected. +26ms
njstuya Connected to device! +29ms
TuyAPI GET Payload: +1ms
TuyAPI {
TuyAPI gwId: 'bfe869873c62537a07lurd',
TuyAPI devId: 'bfe869873c62537a07lurd',
TuyAPI t: '1605859292',
TuyAPI dps: {},
TuyAPI uid: 'bfe869873c62537a07lurd'
TuyAPI } +0ms
TuyAPI Received data: 000055aa000000010000000a0000002c000000017d1b535fd078aa88d7ab53f81a54706fb4c74bccffcfb971f6a306a97f2bb8745aa76c340000aa55 +15ms
TuyAPI Parsed: +4ms
TuyAPI {
TuyAPI payload: 'parse data error',
TuyAPI leftover: false,
TuyAPI commandByte: 10,
TuyAPI sequenceN: 1
TuyAPI } +0ms
njstuya runCommand has started with data "parse data error" +21ms
(node:8177) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '1' of undefined
at TuyaDevice.runCommand (/etc/openhab2/scripts/node_modules/njstuya/njstuya.js:300:33)
at TuyaDevice.emit (events.js:314:20)
at TuyaDevice._packetHandler (/etc/openhab2/scripts/node_modules/tuyapi/index.js:443:10)
at /etc/openhab2/scripts/node_modules/tuyapi/index.js:342:43
at Array.forEach (<anonymous>)
at Socket.<anonymous> (/etc/openhab2/scripts/node_modules/tuyapi/index.js:338:19)
at Socket.emit (events.js:314:20)
at addChunk (_stream_readable.js:298:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
(node:8177) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8177) [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.
TuyAPI Disconnect +10s
njstuya undefined +10s
TuyAPI Socket closed: 192.168.2.163 +3ms
njstuya Disconnected from device. +1ms
Version support isn’t documented but you should be able to set it using this command
DEBUG=* node njstuya.js -ip 192.168.2.163 -id bfe869873c62537a07lurd -key xxxx -v 3.3
That works fine, thank you!
For reference, here are the commands to check status and turn on the Tuya/Smart Life LED strip respectively:
node njstuya.js -ip 192.168.2.163 -id bfe869873c62537a07lurd -key 3acf32edb54b7fc7 -v 3.3
node njstuya.js -ip 192.168.2.163 -id bfe869873c62537a07lurd -key 3acf32edb54b7fc7 -v 3.3 -set '{ "dps": 20, "set": true }'
A few other DPS parameters that I’ve discovered for Tuya/Smart Life LED strip:
20 power: false/true
21 mode: "music"/"colour"/"scene"/"DIY"
24 colour HSL 0-3e8 (1000): HHHHSSSSLLLL. Example Red: 000103e803e8
25 scene "01"-"08": Night, Read, Party, Romance, Rainbow, Flowing, Chase, Rolling
101 speed: 0-100
102 Timer control
103 DIY settings
104 Always "01"?
I didn’t find any setting to change light pattern for music mode though. Music mode is absolutely awesome on these strips with flowing colours ![]()
I might have been wrong, I’ve read that sometimes the api might not report the color field but you may still be able to set it.
I added support to njstuya to allow you to send more arbitrary and complicated commands. So run npm update so you can try the following out. The structure for changing the color is quite complicated so you may need to fiddle with formatting and values a bit.
DEBUG=* node node_modules/njstuya/njstuya.js -mode cloud -id devID -set '{"command": "colorSet", "payload" :{"color": "{ \"hue\": 50, \"saturation\": 50, \"brightness\": 50}" }}'
Hi There,
I am struggling on installing. When I give this:
var resp = executeCommandLine(“node /etc/openhab2/scripts/node_modules/njstuya” + command, 50000)
for the configuration in one of the first steps, I get this error:
-bash: var: command not found
I couldn’t find anyone with the same problem in this chat. Thank you for helping.
Youl would define command first. So something like
val command = "-ip 192.168.x.x -id 1231204564df -key dsf456sdf ON"
var resp = executeCommandLine(“node /etc/openhab2/scripts/node_modules/njstuya” + command, 50000)
The way I have it set up is that the ip/id/key are set as the item’s label.
String BedroomHeaterCommand "-ip 192.168.2.x -id 12346 -key 123456" (gTuyaActions)
So I then just do the following
var setCommand="node /etc/openhab2/scripts/node_modules/njstuya/njstuya.js " + triggeringItem.label + " " + receivedCommand.toString
