unparagoned / njsTuya

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

is there a way to set set multiple dps options in one command? #16

Closed GadgetAngel closed 4 years ago

GadgetAngel commented 5 years ago

I would like to set the color on my Tuya light bulb

I can see there is a way to set multiple dps at one time. like here is an example:

I want to set the scene on my tuya light bulb: so I need to set dps 2 and dps 6 at the same time: node c:/openhab2/userdata/etc/scripts/node_modules/njstuya/njstuya.js -ip 192.168.0.38 -id asdasdasd -key asdasdasdasd -set "[{ \"dps\": 2, \"set\": \"scene\" },{ \"dps\": 6, \"set\": \"bd76000168ffff\" }]" should work but it does not.

-set "[ { \"dps\": 2, \"set\": \"scene\" },{ \"dps\": 6, \"set\": \"bd76000168ffff\" } ]" is a valid JSON string. Let's call this string myJsonString. If you would var obj = JSON.parse(tuyaSet). On myJsonString you would get the valid JSON obj. if you then convert it to an array you can see that the array length is greater than 1. The call to tuya.set(obj) could then be adjusted but you would need a new function to convert the myJsonString or tuyaSet to the Data format: insted of { "dps": 2, "set": "scene" } you need { '1': true, '2': 'scene', '3': 255, '4': 255, '5': 'xxx', '6': 'xxx', '7': 'xxxx', '8': 'xxxx', '9': 'xxxx', etc} which tuyapi is calling the obj.data object. He also has a obj.multiple defined that when you pass the obj.data to tuya.set you set to true.

`if multiple dps need setting then call a function to convert tuyaSet to obj.data format

await tuya.set( { obj.multiple=true, obj.data }) and his routine will set the dps values `

otherwise just call like you always have tuya.set(stateObj);

i have tried to mess around but I am not half as good as you are with Java Script

Could you please consider enabling the feature to set multiple dps values in one call to your secript

Thank you for your time

EDIT: Edit to remove id and key

unparagoned commented 5 years ago

I'm very busy atm and won't have time to look at this properly for at least a month or so, but it should work if you format the command properly

The syntax can be found in the main tuyapi script. https://github.com/codetheweb/tuyapi There the example given is as below,

{
   *           multiple: true,
   *           data: {
   *             '1': true,
   *             '2': 'white'
   *          }}

So I guess try something like

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

You may have to play around with the quotes a bit, trying various options and combination depending on what system you have running. I'd suggest try getting it working from the terminal first, putting the set command into a variable to help with all the quote and any issues escaping them, etc.

"
\"
... etc

If you can't get it working try @tuyapi/cli

P.S. Please edit out your device id and key whenever you post commands in the future.