unparagoned / njsTuya

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

Trying to get -set dps output #11

Closed RikMuilwijk closed 5 years ago

RikMuilwijk commented 5 years ago

Thank you very much for sharing this wrapper! đź‘Ť

I am able to control my dimmer switch via njsTuya or even via homebridge-tuya (so device id and key is correct). I started all of this, trying to figure out why my dimmer switch isn’t reacting to my mqtt command topic in OpenHAB.

Via njsTuya I get my device to switch on with

node njstuya.js -ip <deviceip> -id <deviceid> -key <devicekey> -set "{ \"dps\": 1, \"set\": true }" and off with node njstuya.js -ip <deviceip> -id <deviceid> -key <devicekey> -set "{ \"dps\": 1, \"set\": false }"

Does anyone here maybe has a suggestion on where to look for a fix? Suggestions on this are very welcome.

The switch I am using (EU model): https://nl.aliexpress.com/item/Hot-WiFi-LED-Dimmer-220-v-110-v-Dimmen-Panel-Schakelaar-Aangesloten-op-Alexa-Google-Thuis/32910295055.html?spm=a2g0z.search0104.3.1.1edc55ebZaUZIK&transAbTest=ae803_5&ws_ab_test=searchweb0_0%2Csearchweb201602_1_10065_10068_319_317_10696_10084_453_10083_454_10618_10304_10307_10820_10821_10301_537_536_10902_10843_10059_10884_10887_321_322_10103%2Csearchweb201603_57%2CppcSwitch_0&algo_pvid=44a4e116-2614-4ae6-aa16-f1851bf490e3&algo_expid=44a4e116-2614-4ae6-aa16-f1851bf490e3-0

unparagoned commented 5 years ago

You need to use a dash before the set -set So

node njstuya.js -ip <deviceip> -id <deviceid> -key <devicekey> -set "{ \"dps\": 1, \"set\": true }"
node njstuya.js -ip <deviceip> -id <deviceid> -key <devicekey> -set "{ \"dps\": 1, \"set\": false }"
RikMuilwijk commented 5 years ago

Thank you! I overlooked this in my comment, as stated this was already working.

I'm particularly interested in the MQTT-end of this code. Do you know which device is sending the final MQTT command to my device or where I can find this code? By using this wrapper I can connect to it and control it. On the other hand, sorry for bothering you with this question, I know this might not be the best place for it..

unparagoned commented 5 years ago

I think you are on the wrong git page. I think you might want https://github.com/TheAgentK/tuya-mqtt

unparagoned commented 5 years ago

I haven't run tuya-mqtt before and it's too much effort to set up, but I did have a quick look at the code and made some changes. I'm not too hot on mqtt so I may be wrong but it doesn't look like you can send dps directly using that code. I made some minor changes so it might work but I haven't tested it. So try using my modified tuya-mqtt file. It's just a couple of functions if you want to add them to your existing setup. https://github.com/unparagoned/tuya-mqtt/blob/master/tuya-mqtt.js So there already are functions to publish the data, I added a couple that receive messages that should send the dps commands to your device. So I used a similar format as they are published. But it's not exactly, I don't know if that means it won't wok. I added two topic or whatever, dps and dpsJ. The J means that the DPSCOMMAND goes through a JSON.parse before being sent on.

 type + "/" + tuyaID + "/" + tuyaKey + "/" + tuyaIP + "/" +dps +"/" +DPSCOMMAND"
So something like this 
socket/32kdjtuyaIDsdfdf/3dfxtuyaKey/123.123.1.0.1/dps/"{ \"dps\": 1, \"set\": true }"

socket/32kdjtuyaIDsdfdf/3dfxtuyaKey/123.123.1.0.1/dpsJ/"{ \"dps\": 1, \"set\": true }"