jasonacox / tinytuya

Python API for Tuya WiFi smart devices using a direct local area network (LAN) connection or the cloud (TuyaCloud API).
MIT License
867 stars 157 forks source link

Unable to scan or connect to Tuya devices - localtuya and tinytuya - solved #315

Open MisterRadish opened 1 year ago

MisterRadish commented 1 year ago

Firstly I would like to say thank you for your work on tinytuya. Apologies if the point below is documented elsewhere but I could not find any information on issues running Homeassistant localtuya and tinytuya at the same time.

I have a selection of tuya devices which I use with the Homeassistant Tuya integration platform. I have recently started to migrate to Homeassistant localtuya with mixed results as newer Tuya devices become offline and required a reboot of Homeassistant. I installed tinytuya to try and debug and found that while tinytuya could retrieve all information from the cloud it could not connect to these newer devices at all but had no problem with older devices.

Disabling Localtuya in Homeassistant enabled tinytuya to both scan and connect to these new Tuya devices. This then prompted me to inspect every phone in the household and I also found a rogue smartlife service running on an old phone which I think was causing the instability in localtuya :-)

It appears that the new devices I have only accept one inbound socket connection?

The tuya device in question is a Gosund RGB bulb "category": "dj", "product_name": "WB4-D", "biz_type": 18, "model": "WB4\uff08WB4-D\uff09", "version": "3.3"

uzlonewolf commented 1 year ago

It's not really an old vs new thing, it's a combination of how powerful the chip in the device is and what actions it is performing. My devices which use a more powerful RTL chip and do nothing but act as a WiFi-to-serial bridge support 3 or 4 connections, whereas my light bulbs which use cheaper BK chips and drive the LEDs directly only support a single connection. A few devices have a quirk where they stop broadcasting discovery packets after a single connection even though they actually support 2+ connections; you can still connect to them if you already know their IP address and version, but they will not show up in a scan.

MisterRadish commented 1 year ago

That is interesting info- thank you.

I can confirm though that I was not able to scan or connect directly when using the python examples when Localtuya running in the background. Closing Localtuya enabled both scanning and connection.