Xenomes / Domoticz-TUYA-Plugin

Implements the special Tuya Home Assistant API.
22 stars 8 forks source link

Connection timed out #53

Closed vespino closed 5 months ago

vespino commented 5 months ago

The plugin still works fine, but gives the following timeout a couple of time per day:

Error: Tuya: handleThread: ('Connection aborted.', TimeoutError(110, 'Connection timed out')) line 224

Xenomes commented 5 months ago

Hi, That is line 224 isthe "self.tuya.refresh_access_token()" normally when you stop the plugin for 5 to 10 minutes and then restart it. This action should obtain a new token.

vespino commented 5 months ago

@Xenomes I don’t quite understand. I found the line of code and understand what it does, but I don’t stop the plugin at any point. Should this be a “status” instead of a “problem” entry?

Xenomes commented 5 months ago

I don't run this plugin 24/7 anymore, the used python module is end of live, Tuya announce that they will stop that connection where the module hook in too. Maybe the server is not running perfect anymore.

vespino commented 5 months ago

Bullocks. So their cloud api is the only option looking towards the future?

vespino commented 5 months ago

I have created a bunch of dummy switches and am now controlling my lights and switches using the cloud api. Thanks for your work supporting this plugin.

Xenomes commented 5 months ago

I have build a other plugin witch is using the Tinytuya module, https://github.com/Xenomes/Domoticz-TinyTUYA-Plugin and https://github.com/Xenomes/Domoticz-TinyTUYA-Local-Plugin But this is now only support on/off.

vespino commented 5 months ago

And these also load the devices automatically? I’m using switches and rgb lights at the moment, nothing else, so I might give those a try.

Xenomes commented 5 months ago

Yes they chould work!

vespino commented 5 months ago

First attempt...

2024-01-12 20:11:01.985 Error: TinyTUYA: (tinytuya) failed to load 'plugin.py', Python Path used was '/opt/domoticz/userdata/plugins/Domoticz-TinyTUYA-Plugin/:/usr/lib/python39.zip:/usr/lib/python3.9:/usr/lib/python3.9/lib-dynload:/usr/local/lib/python3.9/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.9/dist-packages'.
2024-01-12 20:11:01.987 Error: TinyTUYA: Traceback (most recent call last):
2024-01-12 20:11:01.987 Error: TinyTUYA: File "/opt/domoticz/userdata/plugins/Domoticz-TinyTUYA-Plugin/plugin.py", line 60, in <module>
2024-01-12 20:11:01.987 Error: TinyTUYA: import tinytuya
2024-01-12 20:11:01.987 Error: TinyTUYA: File "/usr/local/lib/python3.9/dist-packages/tinytuya/__init__.py", line 92, in <module>
2024-01-12 20:11:01.987 Error: TinyTUYA: from .core import *
2024-01-12 20:11:01.987 Error: TinyTUYA: File "/usr/local/lib/python3.9/dist-packages/tinytuya/core.py", line 121, in <module>
2024-01-12 20:11:01.987 Error: TinyTUYA: raise ModuleNotFoundError('No crypto library found, please "pip install" cryptography, pycryptodome, or pyaes')
2024-01-12 20:11:01.987 Error: TinyTUYA: ModuleNotFoundError: No crypto library found, please "pip install" cryptography, pycryptodome, or pyaes 

I figure this out later.

Xenomes commented 5 months ago

Nornal cryptography is also installed by Tinytuya... sudo pip3 install cryptography

vespino commented 5 months ago

After instelling cryptography it works fine, thanks for the tip. But what about this log?

2024-01-13 07:57:34.125 TinyTUYA: No device data returned for Tuya. Trying again!
2024-01-13 07:57:34.691 TinyTUYA: Scanning for tuya devices on network... 

If a new device comes along, is it added automatically?

Xenomes commented 5 months ago

TinyTUYA: No device data returned for Tuya. Trying again!

This is a loop that reads the basic info about the device from Tuya and store it in memory. it will try 10 times. You can see that info of you setup and run the debug_discovery.py in the tools directory. Function loaded at the start plugin and status every minute.

Scanning for tuya devices on network...

This will detect the ip-adress of the device and store in also in memory.

If a new device comes along, is it added automatically?

No, the plugin needs a restart to detect the new device, its is to reduce the calls to the Tuya server.

vespino commented 5 months ago

So what the plugin basically does is get the IP from 1 device and scan that IP-range for other devices?

And on/off triggers are done locally or using the Tuya server?

Xenomes commented 5 months ago

Yep indeed. At the moment no local control, the commands are complete different.

vespino commented 5 months ago

Cheers! I'll let this run for a while and see what happens the next time I add a device.

vespino commented 5 months ago

Just a thought: in my tests I was able to list all my devices straight from the Tuya server. Isn’t this easier than scanning the entire network? I was using the following: https://github.com/ground-creative/tuyapiphp

Xenomes commented 5 months ago

I used the built-in function in the Tinytuya module to keep it simple. The scanning time is about 15 seconds, and it only occurs at the start of the plugin. I know there's a lot to optimize in the plugin; I'm just a hobbyist, not a programmer! 😅

vespino commented 5 months ago

Just a thought, keep up the excellent work 👌🏻