Python Plugin: TUYA

Python and python framework

Moderator: leecollings

Post Reply
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Great that it is fixed!
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Meeki
Posts: 9
Joined: Saturday 14 January 2017 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Meeki »

Xenomes wrote: Wednesday 06 January 2021 21:37
Meeki wrote: Wednesday 06 January 2021 20:43 Can you explain me how to do this? don't know how to run the script.

Kind regards/Groeten

Dennis
It is not difficult, edit the file and add you credentials and set it up as in Domoticz run it and post the output. edit it again and remove your credentials.

The setting to change:

Code: Select all

# CHANGE THIS - BEGGINING
USERNAME = ""
PASSWORD = ""
REGION = "eu" # cn, eu, us
COUNTRY_CODE = "1" # Your account country code, e.g., 1 for USA or 86 for China
BIZ_TYPE = "smart_life" # tuya, smart_life, jinvoo_smart
Hi,

Thank you for the explanation. But i am Noob with Python/scripts. I use domoticz very long but i have no idea how to start a script or just set it up and run the output. I know how to change the credentials and put it in the right folder, but i have no idea what the commands are to start the script or where i can find the output...
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

When you have edit and saved the file you can run the file by running 'python3 debug_discovery.py' the output will be displayed in the command-line-interface.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Meeki
Posts: 9
Joined: Saturday 14 January 2017 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Meeki »

Thanks that was easy... eventuatly :shock:

Got credentials
{ 'access_token': 'EUheu1609586110102mlAAZQhy0lpJ48A',
'expires_in': 864000,
'refresh_token': 'EUheu1609586110102mlAAZw1nR80Bxuy',
'token_type': 'bearer'}
Getting devices
Got devices
{ 'header': {'code': 'SUCCESS', 'payloadVersion': 1},
'payload': { 'devices': [ { 'data': { 'brightness': '570',
'color_mode': 'white',
'color_temp': 7635,
'online': False,
'state': 'false'},
'dev_type': 'light',
'ha_type': 'light',
'icon': 'https://images.tuyaeu.com/smart/icon/ba ... 94800c.png',
'id': '30217610500291097a91',
'name': 'A60 806lm'},
{ 'data': { 'color_mode': 'colour',
'online': True,
'state': 'false'},
'dev_type': 'light',
'ha_type': 'light',
'icon': 'https://images.tuyaeu.com/smart/icon/ay ... af6b75.png',
'id': 'bfd13777feb40bfe129fcc',
'name': 'Led Strip Lights'},
{ 'data': {},
'dev_type': 'scene',
'ha_type': 'scene',
'id': 'DwzAA2IUA6IRYXaN',
'name': 'If Schema:07:00 Alle '
'Dagen,\\"Led Strip '
'Lights\\"On/Off:OFF'},
{ 'data': {},
'dev_type': 'scene',
'ha_type': 'scene',
'id': 'zWkFUoJotVjiIxB9',
'name': 'If Schema:19:00 Alle '
'Dagen,\\"Led Strip '
'Lights\\"On/Off:ON...'}],
'scenes': []}}

Here is the output
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Code: Select all

'data': {
	'color_mode': 'colour',
	'online': True,
	'state': 'false'
},
'dev_type': 'light',
'ha_type': 'light',
'icon': 'https://images.tuyaeu.com/smart/icon/ay ... af6b75.png',
'id': 'bfd13777feb40bfe129fcc',
'name': 'Led Strip Lights'
}
This is the json part of you LED strip, the tuya api only reports color_mode, online, state there is no brightness or color_temp so there is noting that I can do about that. But I updated the plug-in so that when there is a light with missing data in the json it still creates an on/off device.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

Still have problems login in.
I have checked 100 times for the correct credentials . I even logged out in the tuya app and manually typed in the same credentials, there is no problem. The app is closed if i try the test script
But with the test script i get these errors:

Getting credentials
Got credentials
{ 'errorMsg': 'Get accesstoken failed. Username or password error!',
'responseStatus': 'error'}
Traceback (most recent call last):
File "test.py", line 35, in <module>
payload = {"accessToken": auth_response["access_token"]}
KeyError: 'access_token'

Am i missing a file on the raspberry or could it be something else?

Hope someone can help
Thanks
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

edwin1234 wrote: Saturday 16 January 2021 8:17 Traceback (most recent call last):
File "test.py", line 35, in <module>
I don´t understand where his is coming from, there is no mention of test.py anywhere in the code. Can you give more info on the system where u are running it on?
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

Sorry i renamed debug_discovery.py
To test.py that test script i mean
I run it on a raspberry pi 3b
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

I got only this error when i mistype my credentials.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

Im sure I typed it correct
alexcasu
Posts: 3
Joined: Thursday 21 January 2021 20:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by alexcasu »

I've got the same problem.
Don't understand what's going bad.
alexcasu
Posts: 3
Joined: Thursday 21 January 2021 20:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by alexcasu »

RESOLVED

- At the beginning I created a new account in Tuya via Google
- The authentication in Domoticz via Tuya plugin didn't work
- I closed the account in Tuya
- I created a new account with a different email and using a simple password (no special characters)

All works fine.
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

I also use a google mailadres

Do you still use a googlemail adres in your new working account?
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

alexcasu wrote: Friday 22 January 2021 13:14 - I created a new account with a different email and using a simple password (no special characters)
Nice! I don't use have a Google email address but I have special characters in the password and that works fine. If this is a solution for edwin1234 too, then I added it to the readme on the github.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
alexcasu
Posts: 3
Joined: Thursday 21 January 2021 20:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by alexcasu »

edwin1234 wrote: Friday 22 January 2021 13:54 Do you still use a googlemail adres in your new working account?
Hi, I didn't use a google address for the second case and works fine.
Probably Google appplies some security policy that could create problem to the plugin.
Anyway, hope this solution is the right one for all.
Thank you.
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

Ok,
Thanks for your answer
I wil try it without a Gmail adress
edwin1234
Posts: 249
Joined: Sunday 09 October 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: Nederland
Contact:

Re: Python Plugin: TUYA

Post by edwin1234 »

I tried with a dummy account
And it worked :D

Thanks for your help
Afterburner
Posts: 10
Joined: Wednesday 26 February 2020 17:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Afterburner »

I buyed some Lidl Home stuff ( On/Off and Smartplug) to test with Domotics. I discovered it actually is Tuya stuff, so I installed the Smart Life app and configured the devices. Works fine. Installed the Xenomes Tuya plugin. It works fine, no errors, but, no devices. So I tried everything, reinstall app, new account without gmail, reinstall the plugin etc. Nothing helps. What happens here. I don't have new or special devices, but they are not visible.... Thanks for helping...

Log info:

After HW config.
2021-01-30 20:31:17.028 Status: (Tuya-Lidl stuff) Started.
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) TUYA plugin started
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) Debug logging mask set to: PYTHON CONNECTION
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'HardwareID':'19'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'HomeFolder':'/home/ubuntu/domoticz/plugins/Domoticz-TUYA-Plugin/'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'StartupFolder':'/home/ubuntu/domoticz/'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'UserDataFolder':'/home/ubuntu/domoticz/'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Database':'/home/ubuntu/domoticz/domoticz.db'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Language':'nl'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Version':'1.0.4'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Author':'Wagner Oliveira'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Name':'Tuya-Lidl stuff'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Port':'0'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Username':'---------'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Password':'---------'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Key':'tuya'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Mode1':'31'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Mode2':'tuya'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'Mode6':'18'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'DomoticzVersion':'2020.2'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'DomoticzHash':'b63341bc0'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) 'DomoticzBuildTime':'2020-04-26 13:47:55'
2021-01-30 20:31:18.414 (Tuya-Lidl stuff) Device count: 0
2021-01-30 20:31:18.415 (Tuya-Lidl stuff) in handlethread
2021-01-30 20:31:18.411 Status: (Tuya-Lidl stuff) Entering work loop.
2021-01-30 20:31:18.412 Status: (Tuya-Lidl stuff) Initialized version 1.0.4, author 'Wagner Oliveira'

Repeating.
2021-01-30 20:32:28.434 (Tuya-Lidl stuff) onHeartbeat called time=1612035148.4344158
2021-01-30 20:32:38.458 (Tuya-Lidl stuff) onHeartbeat called time=1612035158.4587584
2021-01-30 20:32:48.482 (Tuya-Lidl stuff) onHeartbeat called time=1612035168.4818926

Same result when I fill in Smart Life voor de appname in the HW config.
User avatar
Xenomes
Posts: 379
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Afterburner wrote: Saturday 30 January 2021 20:54 I buyed some Lidl Home stuff ( On/Off and Smartplug) to test with Domotics. I discovered it actually is Tuya stuff, so I installed the Smart Life app and configured the devices. Works fine. Installed the Xenomes Tuya plugin. It works fine, no errors, but, no devices. So I tried everything, reinstall app, new account without gmail, reinstall the plugin etc. Nothing helps. What happens here. I don't have new or special devices, but they are not visible.... Thanks for helping...
Can you post the result of debug_discovery.py in the tools directory. But i think that this zigbee products are not routed to the Tuya api used in the tuyaha liberty.
HP T630 (32GB SSD/8GB Mem) - Ubuntu 22.04.4 LTS (64Bit) - Domoticz 2024.7 with Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Afterburner
Posts: 10
Joined: Wednesday 26 February 2020 17:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Afterburner »

Thanks for responding so quickly.

Suprising respons:
2021-01-31 22:27:00.589 Error: EventSystem: Failed to execute python event script "Script #26"
2021-01-31 22:27:00.589 Error: EventSystem: Traceback (most recent call last):
2021-01-31 22:27:00.589 Error: EventSystem: File "<string>", line 2, in <module>
2021-01-31 22:27:00.589 Error: EventSystem: ModuleNotFoundError: No module named 'requests'

When I run the install command for tuyaha and requests, for the respons, see attachment including file-info.
Attachments
Tuya forum info.doc
(53.5 KiB) Downloaded 71 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest