TheAgentK / tuya-mqtt

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

zombe state reconnecting issue? #76

Closed beaune33 closed 2 years ago

beaune33 commented 2 years ago

Hi,

I have been testing tuya-mqtt for a while and I am still convinced that this is something I could use in my home. Unfortunately there are issues, and you stopped developing the project, but maybe you could give me some hints, so that I can try to fix myself or find another workaround…

My point is similar to some I already read about here, but I am not completely sure if it is really the same. My setup is like follows

What I discovered:

170 2022-02-22 15:23:03,860717  192.168.2.87    0.0.0.0 TCP 76  [TCP Out-Of-Order] 40470 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460
171 2022-02-22 15:23:03,860836  192.168.2.87    0.0.0.0 TCP 76  [TCP Out-Of-Order] 40470 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460
7221    2022-02-22 15:23:05,857960  192.168.2.87    0.0.0.0 TCP 76  [TCP Retransmission] 40470 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460
7222    2022-02-22 15:23:05,858074  192.168.2.87    0.0.0.0 TCP 76  [TCP Retransmission] 40470 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460
7223    2022-02-22 15:23:05,858310  192.168.2.87    0.0.0.0 TCP 76  [TCP Retransmission] 40470 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460
8612    2022-02-22 15:23:06,337255  192.168.2.87    255.255.255.255 UDP 232 59727 → 6667 Len=172
8613    2022-02-22 15:23:06,337397  192.168.2.87    255.255.255.255 UDP 232 59727 → 6667 Len=172
8614    2022-02-22 15:23:06,337555  192.168.2.87    255.255.255.255 UDP 232 59727 → 6667 Len=172
97289   2022-02-22 15:23:31,348172  192.168.2.87    192.168.2.47    DNS 91  Standard query 0x1dff A m2.tuyaeu.com
97290   2022-02-22 15:23:31,348215  192.168.2.87    192.168.2.47    DNS 91  Standard query 0x1dff A m2.tuyaeu.com
97291   2022-02-22 15:23:31,350665  192.168.2.47    192.168.2.87    DNS 109 Standard query response 0x1dff A m2.tuyaeu.com A 0.0.0.0
97697   2022-02-22 15:23:31,465734  192.168.2.87    0.0.0.0 TCP 76  40788 → 8886 [SYN] Seq=0 Win=4380 Len=0 MSS=1460

My questions:

This is how tuya_mqtt starts working:

  tuya-mqtt:tuyapi Search for device id bfxxxxxxxxxxxxxxxxsoqx +0ms
  tuya-mqtt:tuyapi Found device id bfxxxxxxxxxxxxxxxxsoqx +7ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"20":false,"26":0} +197ms
  tuya-mqtt:tuyapi Connected to device LSC Moodlight RGB+CCT (192.168.2.87, bfxxxxxxxxxxxxxxxxsoqx, 924213fa9a2161fb) +882ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/21/command","message":"colour"} +0ms
  tuya-mqtt:command Received command for DPS21:  colour +0ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"21","set":"colour"} +77ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/22/command","message":"920"} +17ms
  tuya-mqtt:command Received command for DPS22:  920 +14ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"22","set":920} +14ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/23/command","message":"625"} +3ms
  tuya-mqtt:command Received command for DPS23:  625 +4ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"23","set":625} +3ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/24/command","message":"000003e803e8"} +2ms
  tuya-mqtt:command Received command for DPS24:  000003e803e8 +2ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"24","set":"000003e803e8"} +2ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/25/command","message":"19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000"} +3ms
  tuya-mqtt:command Received command for DPS25:  19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000 +3ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"25","set":"19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000"} +3ms
  tuya-mqtt:command Received MQTT message ->  {"topic":"tuya/lsc_moodlight_rgb_cct/DPS/20/command","message":"false"} +3ms
  tuya-mqtt:command Received command for DPS20:  false +2ms
  tuya-mqtt:tuyapi Set device bfxxxxxxxxxxxxxxxxsoqx -> {"dps":"20","set":false} +2ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"20":false,"26":0} +71ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"20":false,"26":0} +0ms
  tuya-mqtt:state MQTT DPS20: tuya/lsc_moodlight_rgb_cct/dps/20/state ->  false +2ms
  tuya-mqtt:state MQTT DPS26: tuya/lsc_moodlight_rgb_cct/dps/26/state ->  0 +1ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"21":"colour"} +361ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"21":"colour"} +356ms
  tuya-mqtt:state MQTT DPS21: tuya/lsc_moodlight_rgb_cct/dps/21/state ->  colour +2ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"21":"white","22":920} +205ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"21":"white","22":920} +203ms
  tuya-mqtt:state MQTT DPS21: tuya/lsc_moodlight_rgb_cct/dps/21/state ->  white +0ms
  tuya-mqtt:state MQTT DPS22: tuya/lsc_moodlight_rgb_cct/dps/22/state ->  920 +1ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"21":"white","23":625} +206ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"21":"white","23":625} +204ms
  tuya-mqtt:state MQTT DPS21: tuya/lsc_moodlight_rgb_cct/dps/21/state ->  white +1ms
  tuya-mqtt:state MQTT DPS23: tuya/lsc_moodlight_rgb_cct/dps/23/state ->  625 +1ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"21":"white","24":"000003e803e8"} +204ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"21":"white","24":"000003e803e8"} +203ms
  tuya-mqtt:state MQTT DPS21: tuya/lsc_moodlight_rgb_cct/dps/21/state ->  white +1ms
  tuya-mqtt:state MQTT DPS24: tuya/lsc_moodlight_rgb_cct/dps/24/state ->  000003e803e8 +1ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"21":"white","25":"19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000"} +307ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"21":"white","25":"19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000"} +305ms
  tuya-mqtt:state MQTT DPS21: tuya/lsc_moodlight_rgb_cct/dps/21/state ->  white +1ms
  tuya-mqtt:state MQTT DPS25: tuya/lsc_moodlight_rgb_cct/dps/25/state ->  19464601007803e803e800000000464602006e0320025800000000464602005a038403e800000000 +0ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"20":false} +208ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"20":false} +207ms
  tuya-mqtt:state MQTT DPS20: tuya/lsc_moodlight_rgb_cct/dps/20/state ->  false +1ms
  tuya-mqtt:tuyapi Received JSON data from device bfxxxxxxxxxxxxxxxxsoqx -> {"20":false,"26":0} +3ms
  tuya-mqtt:state MQTT DPS JSON: tuya/lsc_moodlight_rgb_cct/dps/state ->  {"20":false,"26":0} +2ms
  tuya-mqtt:state MQTT DPS20: tuya/lsc_moodlight_rgb_cct/dps/20/state ->  false +1ms
  tuya-mqtt:state MQTT DPS26: tuya/lsc_moodlight_rgb_cct/dps/26/state ->  0 +1ms

But after a while, sometimes after minutes only, sometimes after hours:

  tuya-mqtt:tuyapi Found device id bfxxxxxxxxxxxxxxxxsoqx +1ms
  tuya-mqtt:error Error: Error from socket
  tuya-mqtt:error     at Socket.client.on.err (/opt/tuya-mqtt/node_modules/tuyapi/index.js:399:30)
  tuya-mqtt:error     at Socket.emit (events.js:198:13)
  tuya-mqtt:error     at emitErrorNT (internal/streams/destroy.js:91:8)
  tuya-mqtt:error     at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
  tuya-mqtt:error     at process._tickCallback (internal/process/next_tick.js:63:19) +12s
  tuya-mqtt:error connect EHOSTUNREACH 192.168.2.87:6668 +2ms
  tuya-mqtt:error Error connecting to device id bfxxxxxxxxxxxxxxxxsoqx...retry in 10 seconds. +0ms

Its really a pity that tuya devices are so complicated. In principle everything works, but I really hate the continued sending of something into the internet, this is really a no-go for me. The idea of blocking devices internet access is ok for me, but does not seem to be without negative consequences for the systems stability, or maybe I made a mistake in my blocking setup. I also thought about changing to tasmota, even if I had to open the device for connecting to flash the alternative firmware. But even this is no option for the moodlight as I contains CB3S module instead of ESP-12 or similar. Obviously there is no tasmota firmware for CB3S, so I would need to open, dissolder the old module with a heat gun and solder a new module with new firmware https://templates.blakadder.com/lsc_smart_connect_3004154.html. This seems to be possible… but unfortunately not for me. So I still hope to find an option how to use the device with original firmware. Any ideas or hints appreciated…

tsightler commented 2 years ago

Many (most?) Tuya devices will only accept a single local connection so that could be one issue if, for example, you have a device with the Tuya app running which will also attempt to control the device if Internet is blocked.

That being said, I'm not going to be able to help as I've given up on Tuya devices except in a few places where I'm willing to live with a cloud connection (i.e. I'm using them with other cloud services).

In principle everything works, but I really hate the continued sending of something into the internet, this is really a no-go for me.

Then why purchase a device where that's the only vendor supported mode? Tuya IP based devices are billed as internet controlled smart devices that don't require a hub, not locally controlled devices, and that's what they provide. All attempts to control them locally are mostly exploiting security issues to do so, they are not designed for local control at all.

This is why I've decided not to continue with this project and to only use Tuya devices in cases where Internet based control is already OK since I actually want to control it via the internet so there's really no choice but to have it send data to the internet anyway. Also, I'll still happily use Zigbee based Tuya devices as well, since I can control those locally.

As to your questions, I suggest you look more at other active Tuya projects (there are plenty), such as Tinytuya as I certainly won't have any answers for you. Good luck!