Xenomes / Domoticz-TUYA-Plugin

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

No Devices Discovered in Domoticz, but seen in debug_discovery #32

Closed cookerrr closed 1 year ago

cookerrr commented 1 year ago

I've been using this plugin for at least a year now with no problems. The previous dev's, and now yours. I have 2 rgb light bulbs that change colors per the holiday that's around. They worked fine around Halloween, but now xmas time the bulbs stopped working in domoticz. The 2 devices in domoticz did nothing, so i removed and reinstalled the plugin. The bulbs work fine in the tuya app. I just can't get domoticz to control them. The debug_discovery script sees them. but when i try using the plugin it isn't working. Here are the logs from debug discovery and then domoticz. Any pointers? (I currently only have 1 bulb in my tuya account while i am troubleshooting this, and starred out user/pass).

pi@raspi:~/domoticz/plugins/Domoticz-TUYA-Plugin/tools $ python debug_discovery.py Getting credentials Got credentials { u'access_token': u'AZhaz1576249589248ezT71ejv2PzJDKb', u'expires_in': 864000, u'refresh_token': u'AZhaz1576249589248ezT713F0jRfFyi0', u'token_type': u'bearer'} Getting devices Got devices { u'header': { u'code': u'SUCCESS', u'payloadVersion': 1}, u'payload': { u'devices': [ { u'data': { u'brightness': u'255', u'color_mode': u'colour', u'color_temp': 10000, u'online': True, u'state': u'true'}, u'dev_type': u'light', u'ha_type': u'light', u'icon': u'https://images.tuyaus.com/smart/program_category_icon/dj.png', u'id': u'33765453bcddc2a259d7', u'name': u'Garage'}], u'scenes': []}} !!! NOW REMOVE THIS FILE, SO YOUR CREDENTIALS (username, password) WON'T LEAK !!!

Nov 27 15:59:00 raspi domoticz: Tuya: Worker thread started. Nov 27 15:59:00 raspi domoticz: Tuya: Started. Nov 27 15:59:00 raspi domoticz: Tuya: Entering work loop. Nov 27 15:59:01 raspi domoticz: Tuya: Initialized version 1.0.14, author 'Wagner Oliveira contributed Xenomes' Nov 27 15:59:01 raspi domoticz: Tuya: Waiting 60 seconds to connect TuyaApi login error timeout Nov 27 15:59:01 raspi domoticz: Tuya: Waiting 50 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 15:59:11 raspi domoticz: Tuya: Waiting 40 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 15:59:21 raspi domoticz: Tuya: Waiting 30 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 15:59:31 raspi domoticz: Tuya: Waiting 20 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 15:59:41 raspi domoticz: Tuya: Waiting 10 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 15:59:51 raspi domoticz: Tuya: Waiting 0 seconds to connect TuyaApi (Tuya Plug-in) Nov 27 16:00:01 raspi domoticz: Tuya: TUYA plugin started Nov 27 16:00:01 raspi domoticz: Tuya: Debug logging mask set to: PYTHON PLUGIN QUEUE IMAGE DEVICE CONNECTION MESSAGE Nov 27 16:00:01 raspi domoticz: Tuya: 'HardwareID':'31' Nov 27 16:00:01 raspi domoticz: Tuya: 'HomeFolder':'/home/pi/domoticz/plugins/Domoticz-TUYA-Plugin/' Nov 27 16:00:01 raspi domoticz: Tuya: 'StartupFolder':'/home/pi/domoticz/' Nov 27 16:00:01 raspi domoticz: Tuya: 'UserDataFolder':'/home/pi/domoticz/' Nov 27 16:00:01 raspi domoticz: Tuya: 'Database':'/home/pi/domoticz/domoticz.db' Nov 27 16:00:01 raspi domoticz: Tuya: 'Language':'en' Nov 27 16:00:01 raspi domoticz: Tuya: 'Version':'1.0.14' Nov 27 16:00:01 raspi domoticz: Tuya: 'Author':'Wagner Oliveira contributed Xenomes' Nov 27 16:00:01 raspi domoticz: Tuya: 'Name':'Tuya' Nov 27 16:00:01 raspi domoticz: Tuya: 'Port':'0' Nov 27 16:00:01 raspi domoticz: Tuya: 'Username':'****' Nov 27 16:00:01 raspi domoticz: Tuya: 'Password':'****' Nov 27 16:00:01 raspi domoticz: Tuya: 'Key':'tuya' Nov 27 16:00:01 raspi domoticz: Tuya: 'Mode1':'1' Nov 27 16:00:01 raspi domoticz: Tuya: 'Mode2':'tuya' Nov 27 16:00:01 raspi domoticz: Tuya: 'Mode6':'-1' Nov 27 16:00:01 raspi domoticz: Tuya: 'DomoticzVersion':'2022.2' Nov 27 16:00:01 raspi domoticz: Tuya: 'DomoticzHash':'eea9db734' Nov 27 16:00:01 raspi domoticz: Tuya: 'DomoticzBuildTime':'2022-11-05 08:05:35' Nov 27 16:00:01 raspi domoticz: Tuya: Device count: 0 Nov 27 16:00:01 raspi domoticz: Tuya: in handlethread Nov 27 16:00:01 raspi domoticz: Tuya: Acquiring GIL for 'onStartCallback' Nov 27 16:00:01 raspi domoticz: Tuya: Pushing 'onHeartbeatCallback' on to queue Nov 27 16:00:01 raspi domoticz: Tuya: Processing 'onHeartbeatCallback' message Nov 27 16:00:01 raspi domoticz: Tuya: Acquiring GIL for 'onHeartbeatCallback' Nov 27 16:00:01 raspi domoticz: Tuya: Calling message handler 'onHeartbeat' on 'module' type object. Nov 27 16:00:01 raspi domoticz: Tuya: onHeartbeat called time=1669582801.3637362 Nov 27 16:00:01 raspi domoticz: Tuya: in handlethread Nov 27 16:00:01 raspi domoticz: Tuya: Device count: 0 Nov 27 16:00:01 raspi domoticz: Tuya: Acquiring GIL for 'onHeartbeatCallback' Nov 27 16:00:01 raspi domoticz: Tuya: handleThread: line 209 Nov 27 16:00:01 raspi CRON[22857]: (pi) CMD (/usr/bin/python /home/pi/GCal/gcal.py >> /dev/null) Nov 27 16:00:21 raspi domoticz: Tuya: Pushing 'onHeartbeatCallback' on to queue Nov 27 16:00:21 raspi domoticz: Tuya: Processing 'onHeartbeatCallback' message Nov 27 16:00:21 raspi domoticz: Tuya: Acquiring GIL for 'onHeartbeatCallback' Nov 27 16:00:21 raspi domoticz: Tuya: Calling message handler 'onHeartbeat' on 'module' type object. Nov 27 16:00:21 raspi domoticz: Tuya: Acquiring GIL for 'onHeartbeatCallback'

Xenomes commented 1 year ago

Hi cookerr,

The log shows Nov 27 16:00:01 raspi domoticz: Tuya: Device count: 0 so the plugin didn't detect the bulb. Do you know if there was a firmware update of the bulb? I just started a new project for Tuya devices with a other python module, see https://github.com/Xenomes/Domoticz-TinyTUYA-Plugin i must say it is version 1.0 there could be some bugs.

cookerrr commented 1 year ago

I saw that in domoticz it says device count 0, but on the command line with debug_discovery it sees my bulbs fine. So I don't know if its something with my python config that is messing up the plugin or what. I tried messing with your newer plugin, and had similar problems. I can see the bulbs with the scan tool with python2 but with python3 and the wizard it crashes with an exception. the wizard works fine with python2 but I get the exception with python3, which makes me think maybe somethings wrong on my python3 install. any idea what this exception means? Google isn't helping me.

pi@raspi:~/domoticz/plugins/Domoticz-TinyTUYA-Plugin $ python3 -m tinytuya wizard TinyTuya Setup Wizard [1.8.0]

Existing settings:
    API Key=
    Secret=
    DeviceID=
    Region=us

Use existing credentials (Y/n): y

Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/urllib3/util/ssl_.py", line 402, in ssl_wrap_socket context.load_verify_locations(ca_certs, ca_cert_dir, ca_cert_data) ssl.SSLError: [X509] PEM lib (_ssl.c:4053)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 710, in urlopen chunked=chunked, File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 386, in _make_request self._validate_conn(conn) File "/usr/local/lib/python3.7/dist-packages/urllib3/connectionpool.py", line 1042, in _validate_conn conn.connect() File "/usr/local/lib/python3.7/dist-packages/urllib3/connection.py", line 424, in connect tls_in_tls=tls_intls, File "/usr/local/lib/python3.7/dist-packages/urllib3/util/ssl.py", line 404, in ssl_wrap_socket raise SSLError(e) urllib3.exceptions.SSLError: [X509] PEM lib (_ssl.c:4053)

Xenomes commented 1 year ago

Looks like you are missing something basic.

TinyTuya Installation

TinyTuya supports python versions 2.7 and 3.x (recommended).

Install TinyTuya

python -m pip install tinytuya

Pip will attempt to install pycryptodome, requests and colorama if not already installed.

Try to install pycryptodome, requests and colorama on your Python3 installation with pip3

cookerrr commented 1 year ago

all figured out. Tinytuya is working for me now. I assume it was the same problem that i was having with this plugin as well.... sudo pip3 install certifi --upgrade I assume I had expired certificates.

Xenomes commented 1 year ago

Thnx for your solution, never had to update them.