TheAgentK / tuya-mqtt

Nodejs-Script to combine tuyaapi and openhab via mqtt
MIT License
173 stars 80 forks source link

Problem with Emylo SS-8839-03 and openhabian #23

Closed Fiftiz closed 4 years ago

Fiftiz commented 5 years ago

Hello,

I have a problem with tuya-mqtt (with mqtt binding version 2.4). I follow this guide on the openhab forum : Step-by-Step guide for adding Tuya-bulbs, Wi-Fi smart LED (Smart Life app) to OH2 using tuya-mqtt.js by AgentK. After installation and configuration all my Teckin SP21 work fine. But my Emylo SS-8839-03 dont work (local key , dev ID, ip… all is good) … impossible to find the solution. Any ideas ? thank you very much and sorry for my english :)

Fiftiz commented 4 years ago

Hi, I tried https://github.com/tsightler/tuya-mqtt, same problem. Teckin work fine, but SS-8839-03 don't work :(

Fiftiz commented 4 years ago

@tsightler ?

tsightler commented 4 years ago

Are you able to change the device state with the Tuya CLI code? My first guess is that perhaps it uses a DPS other than 1 to flip the switch but that's totally just a guess.

I think it's important to note that the code here does not talk to Tuya devices directly, rather it uses the Tuya API. There are literally hundreds of Tuya devices out there and they don't all behave the same, as you are experiencing.

Can you at least post the configs that you have tried, especially since you tested the code I've updated for the new encrypted Tuya protocol, what settings did you use there? Once we verify you settings are correct then we can try troubleshooting further via DEBUG output, etc.

Fiftiz commented 4 years ago

I just read : "Download this project to your openhab2-script-folder "/etc/openhab2/scripts" and install tuyapi from the same folder that the tuya-mqtt.js is in " . we need to install tuyapi, because I see it in node_modules ? may be my problem is here

I think it isn't a problem with DPS, because state don't work, I put in my channel for state: tuya/socket/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.93/state

and when I turn on (manually) the state don't change.... so no communication .. with teckin state change

tsightler commented 4 years ago

I don't think you understood what I meant. The tuya-mqtt script here does not talk directly to Tuya devices, rather, it uses the tuyapi API for this function. If one device works, and another doesn't the problem is unlikely to be in the code here, it's far more likely to be in the tuyapi code and that is a different project, so opening an "issue" here may not be successful, that's why I suggested trying tuya-cli and see if you can control your device with that. If it also doesn't work, then the problem is almost certainly in tuyapi and not the tuya-mqtt script.

However, we will try to work through it. You said you tested the branch at https://github.com/tsightler/tuya-mqtt but did you actually change your topic lines as support for Tuya protocol 3.3 is not 100% transparent, you have to change your command/state topic to either explicitly specify the protocol, or to use auto-discovery like so (the "socket" part of the topic is no longer required although won't hurt anything):

Auto-IP discovery: tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/state

Static IP: tuya/ver33/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.93/state

Of course, this will only help if the reason your device is not working is because it's using newer firmware that requires Tuya protocol 3.3 (older devices used Tuya protcol 3.1), if you just used your same topic then even the new code still defaults to the 3.1 protocol

tsightler commented 4 years ago

Just FYI, I ordered a Emylo SS-8839-03 from Amazon so that I can test it myself since it was available on Amazon Prime Day for $10. I'll let you know my result.

Fiftiz commented 4 years ago

ohhhh cool and thank you. I will try to install tuyapi API and tuya cli on other raspberry, but tuya_cli don't work ... no lucky :(

Also with your version I have a big leak of memory , but I will search why later :)

tsightler commented 4 years ago

Interesting about the memory leak, the code has fairly minimal changes, just bump to the new API and minor changes to support auto-discovery and protocol versions. Anyway, we should work that in another issue probably.

The fact that tuya_cli doesn't work is not promising but I'll let you know what I find out when I get the device, hopefully tomorrow.

tsightler commented 4 years ago

So I have good news and bad news. I received the SS-8839-03 device today, hooked it up and configured it via the Smart Life app, then fired up a tuya-mqtt instance and it worked fine, no issues at all. The tuya-cli also worked fine with this device when I used the proper keys. So I guess that's the good news.

Of course, the bad news is that this doesn't help determine your problem at all. I can only suggest to double check 100% that you've got the correct devID and localKey for the specific device.

If you are willing to do more advanced debugging, then you can try running tuya-cli with DEBUG enabled like so:

DEBUG=* ./tuya-cli get --id <devId> --key <localKey> --ip <ip_addr>

If you do this please include the command line and all output. Also, can you check what version of the firmware your device has via the Smart Life app?

Fiftiz commented 4 years ago

what firmware you have ? 1.0.2 ? I think about a thinks.... Smart life is connected at IFTTT .... may be disconnect smart life from IFTTT ?

tsightler commented 4 years ago

The device I have is currently running firmware 1.0.0. I can't imagine that 1.0.2 would be a huge difference, but who knows.

I wouldn't think that having IFTTT connected would matter (I've had IFTTT connected as well). However, I have seen cases where having the Smart Life app open will keep the device from working because you can only have one device connected at a time.

Running tuya-cli in debug as above should provide some good info.

Fiftiz commented 4 years ago

i will try to reinstall tuyaapi this week end ... if it is ok to work lol . I will try also to flash it with tuya convert... impossible, I tried also njstuya .... it detect all tuya device, but not Emylo on my local network .... i don't know where is the problem with this device

tsightler commented 4 years ago

Can you capture some network packets from this device so that we can see the protocol it is using? You have no problems configuring it with the Smart Life app?

Fiftiz commented 4 years ago

No problem to configure with smart life app. I tried several times to install tuya-cli on a raspberry pi zero W for test ... but impossible lot of errors during install and impossible to use it .... il will re try later this week.

Just to know , you use in MQTT thing this command with ver33 ? tuya/ver33/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.93/state

Fiftiz commented 4 years ago

Tuya-cli installed .... and I receive this message to infinity :

DEBUG=* tuya-cli get --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --ip 192.168.1.92 TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 192.168.1.92... +61ms TuyAPI Socket connected. +151ms TuyAPI GET Payload: +12ms TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +215ms TuyAPI Parsed: +21ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +12ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +222ms TuyAPI Parsed: +5ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +243ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +273ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +303ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +124ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +147ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +168ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +198ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +216ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +241ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +262ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +289ms TuyAPI Parsed: +2ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +319ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +21ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +17ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +185ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +211ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +234ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +253ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +16ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +43ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +6ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +319ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +148ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +4ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +159ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +171ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +191ms TuyAPI Parsed: +36ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +4ms TuyAPI Pong from 192.168.1.92 +26ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +16ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +5ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +212ms TuyAPI Parsed: +2ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +2ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +217ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +233ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +6ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +261ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +326ms TuyAPI Parsed: +3ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +3ms TuyAPI Pong from 192.168.1.92 +3ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +294ms TuyAPI Parsed: +4ms TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +2ms TuyAPI Pong from 192.168.1.92 +6ms

Fiftiz commented 4 years ago

When I try with device who work (Teckin SP21).... debug indicate :

DEBUG=* tuya-cli get --id 87046830cc50e320d66f --key 69767809f6c06729 --ip 192.168.1.7 TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 192.168.1.7... +61ms TuyAPI Error event from socket. 192.168.1.7 { Error: connect ECONNRESET 192.168.1.7:6668 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'connect', address: '192.168.1.7', port: 6668 } +67ms events.js:174 throw er; // Unhandled 'error' event ^

Error: Error from socket at Socket.client.on.err (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:323:30) at Socket.emit (events.js:198:13) at emitErrorNT (internal/streams/destroy.js:91:8) at emitErrorAndCloseNT (internal/streams/destroy.js:59:3) at process._tickCallback (internal/process/next_tick.js:63:19) Emitted 'error' event at: at Socket.client.on.err (/usr/lib/node_modules/@tuyapi/cli/node_modules/tuyapi/index.js:323:16) at Socket.emit (events.js:198:13) [... lines matching original stack trace ...] at process._tickCallback (internal/process/next_tick.js:63:19)

I am really tired with tuya-cli .... really a not stable package ... try on raspbian... openhabian....error on all systems

Fiftiz commented 4 years ago

Version 3.3 , but don't work :/

{ payload: TuyAPI { ip: '192.168.1.92', TuyAPI gwId: '46200800dc4f22a70029', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'ON0fHlAaAf7Pt7ja', TuyAPI version: '3.3' }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 } +2ms TuyAPI Connecting to 192.168.1.92... +55ms TuyAPI Socket connected. +311ms TuyAPI GET Payload: +8ms TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Received data: 000055aa000000010000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141bdfd1a075a2de3565a0d4d40fde1c3e50a4c2e0ea7a3881c9606240b4f1282a8a696419ded2df2b8a995e1943e39b5c8ff7dec0f0000aa55 +86ms TuyAPI Parsed: +7ms TuyAPI { payload: TuyAPI { devId: '46200800dc4f22a70029', TuyAPI dps: { '1': false, '101': '0', '102': 0 } }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 } +1ms TuyAPI GET Payload: +23ms TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Received data: 000055aa000000020000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141bdfd1a075a2de3565a0d4d40fde1c3e50a4c2e0ea7a3881c9606240b4f1282a8a696419ded2df2b8a995e1943e39b5c80d2fc2240000aa55 +35ms TuyAPI Parsed: +6ms TuyAPI { payload: TuyAPI { devId: '46200800dc4f22a70029', TuyAPI dps: { '1': false, '101': '0', '102': 0 } }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 2 } +2ms TuyAPI Disconnect +16ms { devId: '46200800dc4f22a70029', dps: { '1': false, '101': '0', '102': 0 } } TuyAPI Socket closed: 192.168.1.92 +29ms

tsightler commented 4 years ago

What do you mean it's not working? That is definitely the output I would expect from a working tuya-cli get command with DEBUG, specifically:

dps: { '1': false, '101': '0', '102': 0 } }

That's a valid response indicating that the switch is off. If you turn the switch on and run get again I would expect to see:

dps: { '1': true, '101': '0', '102': 0 } }

So, can you clarify what you mean?

Fiftiz commented 4 years ago

Randomly I have errors: Timeout, socket error, EPIPE, ECONNRESET ....

Fiftiz commented 4 years ago

I have turn on the emylo , yes there is dps: {'1': true, '101': '0', '102': 0}}

DEBUG=* tuya-cli get --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b -a

{ payload: TuyAPI { ip: '192.168.1.92', TuyAPI gwId: '46200800dc4f22a70029', TuyAPI active: 2, TuyAPI ability: 0, TuyAPI mode: 0, TuyAPI encrypt: true, TuyAPI productKey: 'ON0fHlAaAf7Pt7ja', TuyAPI version: '3.3' }, TuyAPI leftover: false, TuyAPI commandByte: 19, TuyAPI sequenceN: 0 } +3ms TuyAPI Connecting to 192.168.1.92... +46ms TuyAPI Socket connected. +151ms TuyAPI GET Payload: +9ms TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Received data: 000055aa000000010000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc11431413e5f215233a03480bd6a7582d3a93879f095bdad82fffca1bb32691d01190cc505b6bd3b3a5368f03553fe29c57e37ab2fa2f71d0000aa55 +75ms TuyAPI Parsed: +6ms TuyAPI { payload: TuyAPI { devId: '46200800dc4f22a70029', TuyAPI dps: { '1': true, '101': '0', '102': 0 } }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 } +2ms TuyAPI GET Payload: +23ms TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Received data: 000055aa000000020000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc11431413e5f215233a03480bd6a7582d3a93879f095bdad82fffca1bb32691d01190cc505b6bd3b3a5368f03553fe29c57e37abddf0d9360000aa55 +40ms TuyAPI Parsed: +6ms TuyAPI { payload: TuyAPI { devId: '46200800dc4f22a70029', TuyAPI dps: { '1': true, '101': '0', '102': 0 } }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 2 } +2ms TuyAPI Disconnect +13ms { devId: '46200800dc4f22a70029', dps: { '1': true, '101': '0', '102': 0 } } TuyAPI Socket closed: 192.168.1.92 +32ms

tsightler commented 4 years ago

Also, I realized I had a small error above, if you are using my modified tuya-mqtt with support for protocol 3.3 you need to use a state topic like this:

tuya/ver3.3/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.93/state

or, if you want to use auto device discovery:

tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/state

With auto device discovery it's possible to automatically determine the protocol version, but there can be a delay for the first connect as we have to wait a few seconds for a UDP broadcast from the device to find it, but this is only on the initial connect.

When you specify the IP address we don't need to wait for the UDP packet, but we have no way of knowing the protocol version before we attempt to connect to the device so you have to explicitly provide the protocol version. For the current development tuya-mqtt I did this by overloading the "socket" field since it's not used anymore and is there there for compatibility with older versions.

tsightler commented 4 years ago

The random connection errors are probably caused by the fact that the Tuya devices only allow one local connection at a time and timeout those connections slowly. If you happen to have the Smart Life app running, even in the background, or the tuya-mqtt script communicating with it, they will sometimes get an error because they are already have a local connection. Unfortunately that's a limit of the tuya device.

Fiftiz commented 4 years ago

I have news :

if i put : DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --set true Emylo work and turn on

if i put : DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --set true Emylo work and turn off

if i put : DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --ip 192.168.1.92 --set true Emylo don't work and I have infinty ping pong message and i see Piging +10s ... 10 seconds it's long...

{ gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms TuyAPI Pinging 192.168.1.92 +10s TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +214ms TuyAPI Parsed: +22ms

There is a problem when I indicate the IP ....

DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --set true

  TuyAPI Finding missing IP undefined or ID 46200800dc4f22a70029 +0ms
  TuyAPI Received UDP message. +638ms
  TuyAPI UDP data: +46ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.24',
  TuyAPI      gwId: '46200800dc4f22a6f863',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +2ms
  TuyAPI Received UDP message. +721ms
  TuyAPI UDP data: +10ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.98',
  TuyAPI      gwId: '46200800c44f33889bfa',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +2ms
  TuyAPI Received UDP message. +381ms
  TuyAPI UDP data: +9ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.44',
  TuyAPI      gwId: '46200800c44f3388a0e2',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +2ms
  TuyAPI Received UDP message. +382ms
  TuyAPI UDP data: +5ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.62',
  TuyAPI      gwId: '46200800dc4f22a6f938',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +3ms
  TuyAPI Received UDP message. +976ms
  TuyAPI UDP data: +6ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.92',
  TuyAPI      gwId: '46200800dc4f22a70029',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +3ms
  TuyAPI Connecting to 192.168.1.92... +54ms
  TuyAPI Socket connected. +45ms
  TuyAPI GET Payload: +8ms
  TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms
  TuyAPI Received data: 000055aa000000010000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141bdfd1a075a2de3565a0d4d40fde1c3e50a4c2e0ea7a3881c9606240b4f1282a8a696419ded2df2b8a995e1943e39b5c8ff7dec0f0000aa55 +72ms
  TuyAPI Parsed: +5ms
  TuyAPI { payload:
  TuyAPI    { devId: '46200800dc4f22a70029',
  TuyAPI      dps: { '1': false, '101': '0', '102': 0 } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +3ms
  TuyAPI SET Payload: +22ms
  TuyAPI { devId: '46200800dc4f22a70029',
  TuyAPI   gwId: '46200800dc4f22a70029',
  TuyAPI   uid: '',
  TuyAPI   t: 1563919500,
  TuyAPI   dps: { '1': true } } +2ms
  TuyAPI Received data: 000055aa00000002000000070000000c0000000018cfc5da0000aa55 +65ms
  TuyAPI Parsed: +3ms
  TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 2 } +2ms
  TuyAPI Got SET ack. +4ms
  TuyAPI Received data: 000055aa00000000000000080000006b00000000332e33000000000000029a000000013dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141d86eedbad77263a6b1c6d9cb1a617b7dbb269a6e444ce0f222ba7e5341569971aed4e085211778d0def5441f5d5e185b50bbb8f40000aa55 +4ms
  TuyAPI Parsed: +7ms
  TuyAPI { payload:
  TuyAPI    { devId: '46200800dc4f22a70029',
  TuyAPI      dps: { '1': true },
  TuyAPI      t: 1563919500 },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0 } +3ms
  TuyAPI Disconnect +15ms
Set succeeded.
  TuyAPI Socket closed: 192.168.1.92 +26ms
tsightler commented 4 years ago

As I stated above, this is normal behavior when a device uses protocol 3.3. If you specify the IP address for a protocol 3.3 device you must explicitly provide the protocol version. For tuya-cli you add the following

DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --set true --protocol-version 3.3

This will force TuyAPI to use protocol 3.3 when connecting, just like I explained in the post above.

Fiftiz commented 4 years ago

ok it's work DEBUG=* tuya-cli set --id 46200800dc4f22a70029 --key f7edc6a7eb5f322b --ip 192.168.1.92 --set true --protocol-version 3.3

TuyAPI IP and ID are already both resolved. +0ms
  TuyAPI Connecting to 192.168.1.92... +61ms
  TuyAPI Socket connected. +114ms
  TuyAPI GET Payload: +12ms
  TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +2ms
  TuyAPI Received data: 000055aa000000010000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141bdfd1a075a2de3565a0d4d40fde1c3e50a4c2e0ea7a3881c9606240b4f1282a8a696419ded2df2b8a995e1943e39b5c8ff7dec0f0000aa55 +396ms
  TuyAPI Parsed: +22ms
  TuyAPI { payload:
  TuyAPI    { devId: '46200800dc4f22a70029',
  TuyAPI      dps: { '1': false, '101': '0', '102': 0 } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +2ms
  TuyAPI SET Payload: +28ms
  TuyAPI { devId: '46200800dc4f22a70029',
  TuyAPI   gwId: '46200800dc4f22a70029',
  TuyAPI   uid: '',
  TuyAPI   t: 1563920205,
  TuyAPI   dps: { '1': true } } +2ms
  TuyAPI Received data: 000055aa00000002000000070000000c0000000018cfc5da0000aa55 +349ms
  TuyAPI Parsed: +3ms
  TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 2 } +2ms
  TuyAPI Got SET ack. +4ms
  TuyAPI Received data: 000055aa00000000000000080000006b00000000332e33000000000000029c000000013dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141d86eedbad77263a6b1c6d9cb1a617b7da84e903dd67d977121ff3a1ada9eb8a4aed4e085211778d0def5441f5d5e185bf71744e90000aa55 +4ms
  TuyAPI Parsed: +5ms
  TuyAPI { payload:
  TuyAPI    { devId: '46200800dc4f22a70029',
  TuyAPI      dps: { '1': true },
  TuyAPI      t: 1563920205 },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 8,
  TuyAPI   sequenceN: 0 } +1ms
  TuyAPI Disconnect +9ms
Set succeeded.
  TuyAPI Socket closed: 192.168.1.92 +21ms

So in mqqtt state topic (openhab 2.4) , i put : tuya/ver3.3/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.92/state

and mqtt command topic , i put: tuya/ver3.3/46200800dc4f22a70029/f7edc6a7eb5f322b/192.168.1.92/command

right ?

Fiftiz commented 4 years ago

Debug of tuya-mqtt.js with discover method

DEBUG=* node tuya-mqtt.js

 TuyAPI:mqtt MQTT-Server nicht verbunden. +0ms
  TuyAPI:mqtt Verbindung mit MQTT-Server hergestellt +40ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/command","action":"command","message":"","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +13s
  TuyAPI:device Search device in network +0ms
  TuyAPI Finding missing IP undefined or ID 46200800dc4f22a70029 +0ms
  TuyAPI Received UDP message. +299ms
  TuyAPI UDP data: +9ms
  TuyAPI { payload:
  TuyAPI    { ip: '192.168.1.92',
  TuyAPI      gwId: '46200800dc4f22a70029',
  TuyAPI      active: 2,
  TuyAPI      ability: 0,
  TuyAPI      mode: 0,
  TuyAPI      encrypt: true,
  TuyAPI      productKey: 'ON0fHlAaAf7Pt7ja',
  TuyAPI      version: '3.3' },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 19,
  TuyAPI   sequenceN: 0 } +1ms
  TuyAPI:device Device found in network +330ms
  TuyAPI Connecting to 192.168.1.92... +15ms
  TuyAPI Socket connected. +8ms
  TuyAPI:device Connected to device.  (undefined, 46200800dc4f22a70029, f7edc6a7eb5f322b) +12ms
  TuyAPI GET Payload: +2ms
  TuyAPI { gwId: '46200800dc4f22a70029', devId: '46200800dc4f22a70029' } +0ms
  TuyAPI:mqtt command is JSON +363ms
  TuyAPI:mqtt:error SyntaxError: Unexpected end of JSON input
  TuyAPI:mqtt:error     at JSON.parse (<anonymous>)
  TuyAPI:mqtt:error     at getCommandFromTopic (/etc/openhab2/scripts/tuyaapi_mqtt/tuya-mqtt.js:152:24)
  TuyAPI:mqtt:error     at /etc/openhab2/scripts/tuyaapi_mqtt/tuya-mqtt.js:195:35
  TuyAPI:mqtt:error     at process._tickCallback (internal/process/next_tick.js:68:7) +0ms
  TuyAPI Received data: 000055aa000000010000000a0000005c000000003dc4c42307ed5019005620f1687502f336f6b154cbf016a5569a9e8cc1143141bdfd1a075a2de3565a0d4d40fde1c3e50a4c2e0ea7a3881c9606240b4f1282a8a696419ded2df2b8a995e1943e39b5c8ff7dec0f0000aa55 +33ms
  TuyAPI Parsed: +2ms
  TuyAPI { payload:
  TuyAPI    { devId: '46200800dc4f22a70029',
  TuyAPI      dps: { '1': false, '101': '0', '102': 0 } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +0ms
  TuyAPI:device Data from device: { devId: '46200800dc4f22a70029',
  dps: { '1': false, '101': '0', '102': 0 } } +38ms
  TuyAPI:mqtt:device Data from device undefined : { devId: '46200800dc4f22a70029',
  dps: { '1': false, '101': '0', '102': 0 } } +0ms
  TuyAPI:mqtt:device mqtt status updated to:tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/state -> OFF +3ms
  TuyAPI:mqtt:device mqtt dps updated to:tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps ->  {"1":false,"101":"0","102":0} +2ms
  TuyAPI:mqtt:device mqtt dps updated to:tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/1 -> dps[1] false +1ms
  TuyAPI:mqtt:device mqtt dps updated to:tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/101 -> dps[101] "0" +1ms
  TuyAPI:mqtt:device mqtt dps updated to:tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/102 -> dps[102] 0 +0ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/state","action":"state","message":"OFF","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +76ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps","action":"dps","message":"{\"1\":false,\"101\":\"0\",\"102\":0}","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +4ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/1","action":"dps","message":"false","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +2ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/101","action":"dps","message":"\"0\"","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +1ms
  TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/dps/102","action":"dps","message":"0","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +5ms
  TuyAPI Pinging 192.168.1.92 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +294ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +0ms
  TuyAPI Pong from 192.168.1.92 +2ms
  TuyAPI Pinging 192.168.1.92 +10s
  TuyAPI Received data: 000055aa00000000000000090000000c00000000b051ab030000aa55 +117ms
  TuyAPI Parsed: +1ms
  TuyAPI { payload: false, leftover: false, commandByte: 9, sequenceN: 0 } +1ms
  TuyAPI Pong from 192.168.1.92 +1ms

and after infinity ping pong :)

tsightler commented 4 years ago

What's confusing here is that it looks like OpenHAB did not send a message:

TuyAPI:mqtt receive settings {"topic":"tuya/46200800dc4f22a70029/f7edc6a7eb5f322b/discover/command","action":"command","message":"","options":{"id":"46200800dc4f22a70029","key":"f7edc6a7eb5f322b","ip":"discover"}} +13s

So we basically received a null command and the script did not know what to do with this (see JSON parse error in the middle, which is why the state didn't change). I should probably fix this to not give and error, but that wouldn't make a difference here from a functional perspective, the script still wouldn't know what command to process because there was no command, just a null message on the topic. Do you definitely have a switch channel defined with "ON" and "OFF"?

Can you post a screenshot of your OpenHAB binding config? I'm not an OpenHAB expert as I abandoned OpenHAB for Home Assistant long ago, but maybe it will give a clue. Otherwise things look OK and as expected (the ping-pong is normal as it continues to monitor the switch state).

BTW, thanks for all the work, we've learned a lot today, the switch is definitely protocol 3.3 and it definitely works with TuyAPI, so now it's down to figuring out why it won't work with OpenHAB.

Fiftiz commented 4 years ago

IT'S WORKKKKKK lol I am just stupid, really really thank you for your patience, you are the best ;)

In On/open value, need to put 1 and Off/Closed value , need to put 0 ... and it work

I will update the post on openhab forum to indicate your version of tuya-mqtt , thank you again

tsightler commented 4 years ago

You should also be able to include the words "ON" and "OFF", but the script reacts to 1 and 0 as well. Glad you got it working. I'll close this issue since there was no problem in the script and I'll be merging the protocol 3.3 support in the next few weeks.

Fiftiz commented 4 years ago

Just a last question. I have also an Emylo with 2 way , so dps: { '1': false, '2': false, '9': 0, '10': 0 } } , how do i do the work in MQTT thing (on value ans off value) ? thank you very much

TuyAPI { payload:
  TuyAPI    { devId: '15143138c44f33889ac6',
  TuyAPI      dps: { '1': false, '2': false, '9': 0, '10': 0 } },
  TuyAPI   leftover: false,
  TuyAPI   commandByte: 10,
  TuyAPI   sequenceN: 1 } +1ms
  TuyAPI:device Data from device: { devId: '15143138c44f33889ac6',
  dps: { '1': false, '2': false, '9': 0, '10': 0 } } +31ms
  TuyAPI:mqtt:device Data from device undefined : { devId: '15143138c44f33889ac6',
  dps: { '1': false, '2': false, '9': 0, '10': 0 } } +0ms
tsightler commented 4 years ago

It's documented in the README.md file. If you look at the section on MQTT topics it shows how to change device state by payload. For systems with multiple switches, you have to define the specific DSP value you want to change so, for example, the first switch:

On value: "{ \"dps\": 1, \"set\": true }"

Off value: "{ \"dps\": 1, \"set\": false }"

And for the second switch in the same device:

On value: "{ \"dps\": 2, \"set\": true }"

Off value: "{ \"dps\": 2, \"set\": false }"

Fiftiz commented 4 years ago

ok it work, i understand the problem, on the mail of your answer the command is ok, here there is several backslash who are show in the command , there is same backslash in the commands on README.md... ok now I have to convert the dps state, because openhab don't like "true" and "false" and there is error of log file .... :) Also, I can you refund the emylo buy to test :)

tsightler commented 4 years ago

The backslashes are escapes for the quote marks. The value is a JSON string but, because the string contains quotes inside of a quoted string you have to use backslash to "escape" the quotes within the string.

Hopefully you can figure out a way to translate true/false to on/off as I know OpenHAB has a powerful translation feature. I had considered adding a "state" method for each DPS value which would be pre-translated, but it only makes sense for switch values while, for bulbs, the DPS can represent things like brightness and color, etc so I'd have to figure out someway to know if a given DPS is a switch or bulb and I just don't have access to enough devices.

Fiftiz commented 4 years ago

Hello, may be I have to create a new issue, but a confirm a leak of memory, tested with 2 raspberry( pi 3B+ and Zero Pi W) , same problem on the both

An exemple of command ps aux

openhab+ 13179 19.6 3.8 131740 38376 ? Ssl 08:27 0:00 /usr/bin/node /etc/openhab2/scripts/tuyaapi_mqtt/tuya-mqtt.js

it use 20% (19,6% in 8 hours) of memory and it continues to increase. For the moment I kill the process and the services re launch tuya-mqtt.js , after ut use 3,7% and increase in the day ...

When I did my tests with debug. I saw after each command it continue to ping and pong, and randomly closes the socket with a cleanup. thank you

tsightler commented 4 years ago

I'm not really sure I see a memory leak, can you please leave the code running for a few days and see if it eventually stables out? In your example the code is only using 38MB, which isn't very much for a NodeJS application that actually does things. I mean, a simple one liner that basically does nothing can easily use 20MB with default NodeJS settings and the TuyaAPI code on which this script depends has lots of dependencies so it's going to use a lot more than this. I would expect that the code would stable out around 40-50MB usage with default NodeJS settings when garbage collectors start kicking in, but I'm not sure 8 hours is enough for this.

Now, if you run for days, and it keeps growing to >100MBs, then I'd be concerned. Regardless, you really need to open a different issue if you believe this is a problem.

Fiftiz commented 4 years ago

oups sorry bad line ... this is the line after to have kill tuya-mqtt.js , to restart it

openhab+ 359 0.2 18.7 291472 186996 ? Ssl Jul25 2:55 /usr/bin/node /etc/openhab2/scripts/tuyaapi_mqtt

here 186MB of memory in 8 hours

tsightler commented 4 years ago

OK, fair enough. Please open a new issue and I'll look into it.

Libelung commented 4 years ago

Hello,

I'm kinda having the same issue, but i can't manage to solve it. I assume i need to send to tuya-cli the version-protocol 3.3 to make my lightbulb work, as i can turn it on or off with that command (--set true or false)

$ DEBUG=* tuya-cli set --key d54a9631e5fffb0d --id 7212000298f4abc95977 --ip 192 .168.1.52 --set false --protocol-version 3.3 TuyAPI IP and ID are already both resolved. +0ms TuyAPI Connecting to 192.168.1.52... +2ms TuyAPI Socket connected. +37ms TuyAPI GET Payload: +0ms TuyAPI { gwId: '7212000298f4abc95977', devId: '7212000298f4abc95977' } +0ms TuyAPI Received data: 000055aa000000010000000a0000011c00000000448c3fb411e162fa 9a2e37cf6933c812661fa8b781abf984d1c281c13e80f6c971926842c39edaf21b0d7afe7ba8f837 85c9ad0fb2ccdbef01c23d6949fbb0a07e58ac48b932303dfc53d13473a8e96c79b567513aec200f 25caa7da59e524deda6c915bab2f58686999dfece6b38c0b9cb0dbc2ac374c6181ac6e65169f358f 4ce393a24f1924ad4d8c1c7be15fc11b461b1efc5ab0712829477fd0c8d383c279cad6b64639027a 33defcd6a0987e0dd6d3e9c0af2e30b55d263ba5abe0763c9a6d7c84c44f2cfbccda5fa16f7ba5b4 ad2c5446ec6e460874542df407026e7a83e5b09aefaf711eaec10e9a11d7ff1bc7cd3388d2ef655b 830f83e66575efbd3eec47976bf44b6a1426606daab247c6baca62cf0000aa55 +20ms TuyAPI Parsed: +1ms TuyAPI { TuyAPI payload: { TuyAPI devId: '7212000298f4abc95977', TuyAPI dps: { TuyAPI '1': true, TuyAPI '2': 'white', TuyAPI '3': 255, TuyAPI '5': 'ff00000000ffff', TuyAPI '6': '00ff0000000000', TuyAPI '7': 'ffff500100ff00', TuyAPI '8': 'ffff8003ff000000ff000000ff000000000000000000', TuyAPI '9': 'ffff5001ff0000', TuyAPI '10': 'ffff0505ff000000ff00ffff00ff00ff0000ff000000' TuyAPI } TuyAPI }, TuyAPI leftover: false, TuyAPI commandByte: 10, TuyAPI sequenceN: 1 TuyAPI } +0ms TuyAPI SET Payload: +1ms TuyAPI { TuyAPI devId: '7212000298f4abc95977', TuyAPI gwId: '7212000298f4abc95977', TuyAPI uid: '', TuyAPI t: 1578820236, TuyAPI dps: { '1': false } TuyAPI } +0ms TuyAPI Received data: 000055aa00000002000000070000000c0000000018cfc5da0000aa55 +16ms TuyAPI Parsed: +0ms TuyAPI { payload: false, leftover: false, commandByte: 7, sequenceN: 2 } +0ms TuyAPI Got SET ack. +1ms TuyAPI Received data: 000055aa00000000000000080000006b00000000332e330000000000 00000900000001448c3fb411e162fa9a2e37cf6933c812661fa8b781abf984d1c281c13e80f6c9b0 c1e600df2fc2d0626152675b8a6fe60d62eeb966a7bd6179f2e685dd7643d312dcd8b83ee334d141 fdec14dda5d8a4c21a159a0000aa55 +50ms TuyAPI Parsed: +0ms TuyAPI { TuyAPI payload: { devId: '7212000298f4abc95977', dps: { '1': false }, t: 157 8820236 }, TuyAPI leftover: false, TuyAPI commandByte: 8, TuyAPI sequenceN: 0 TuyAPI } +0ms TuyAPI Disconnect +1ms Set succeeded. TuyAPI Socket closed: 192.168.1.52 +3ms

The thing is when i try to send my request via mqtt to tuya-mqtt, it doesn't seem to handle it correctly.

$ DEBUG=* node /etc/openhab2/scripts/tuya-mqtt/tuya-mqtt.js TuyAPI:mqtt MQTT-Server nicht verbunden. +0ms TuyAPI:mqtt Verbindung mit MQTT-Server hergestellt +6ms TuyAPI:mqtt receive settings {"topic":"tuya/7212000298f4abc95977/d54a9631e5fff b0d/192.168.1.52/command","action":"command","message":"off","options":{"id":"72 12000298f4abc95977","key":"d54a9631e5fffb0d","ip":"192.168.1.52","version":"3.3" }} +42s TuyAPI:device Search device in network +0ms TuyAPI IP and ID are already both resolved. +0ms TuyAPI:device Device found in network +1ms TuyAPI Connecting to 192.168.1.52... +2ms TuyAPI Socket connected. +49ms TuyAPI:device Connected to device. undefined (192.168.1.52, 7212000298f4abc959 77, d54a9631e5fffb0d) +50ms TuyAPI:device GET Payload: +0ms TuyAPI:device { gwId: '7212000298f4abc95977', devId: '7212000298f4abc95977' } +0ms TuyAPI:mqtt receive command { set: false } +58ms TuyAPI:device set: { set: false } +6ms TuyAPI SET Payload: +7ms TuyAPI { TuyAPI devId: '7212000298f4abc95977', TuyAPI gwId: '7212000298f4abc95977', TuyAPI uid: '', TuyAPI t: 1578820124, TuyAPI dps: { '1': false } TuyAPI } +0ms TuyAPI Pinging 192.168.1.52 +10s TuyAPI Pinging 192.168.1.52 +10s TuyAPI Pinging 192.168.1.52 +10s TuyAPI Error event from socket. 192.168.1.52 Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:200:27) { errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } +75ms TuyAPI:device:error Error: Error from socket TuyAPI:device:error at Socket. (/etc/openhab2/scripts/tuya-mqtt/node_modules/tuyapi/index.js:365:30) TuyAPI:device:error at Socket.emit (events.js:223:5) TuyAPI:device:error at emitErrorNT (internal/streams/destroy.js:92:8) TuyAPI:device:error at emitErrorAndCloseNT (internal/streams/destroy.js:60:3) TuyAPI:device:error at processTicksAndRejections (internal/process/task_queues.js:81:21) +0ms TuyAPI Socket closed: 192.168.1.52 +2ms TuyAPI:device Disconnected from device. undefined (192.168.1.52, 7212000298f4abc95977, d54a9631e5fffb0d) +30s TuyAPI:device delete Device undefined (192.168.1.52, 7212000298f4abc95977, d54a9631e5fffb0d) +0ms

I tried to set the ip to discover instead, still not working. I also tried to set the version to 3.3 instead of 3.1 in the tuya-mqtt.js and node_modules/tuyapi/index.js but with no luck.