Python Plugin: TUYA

Python and python framework

Moderator: leecollings

wkossen
Posts: 62
Joined: Friday 06 November 2020 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by wkossen »

Hi,

i am currently using the tuyaha based plugin. should i migrate to this one and if so, why, and if so, how?

does or will this support other devices than switches and lamps? I got a door sensor recently and would like to automate a lamp in a cupboard with it using domoticz.

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 »

The builder of the tuyaha library as added this to the readme. The tuyaha library is the base Tuya plugin.
My device is not listed in Tuya API response or contains incomplete state, what should I do?

Write an email to [email protected] and mention the tuyapy library and https://px1.tuya{}.com API endpoint. Usually they ignore incoming emails, but perhaps, if they get a lot of emails, they will start fixing the API.
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
User avatar
TiXav
Posts: 38
Joined: Saturday 28 November 2015 22:25
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Python Plugin: TUYA

Post by TiXav »

Hi Xenomes,

I saw 2 days ago that there is a new version of tuyaha librairy @ https://github.com/PaulAnnekov/tuyaha/commits/master
I uninstall pip3 tuyaha and I place the new librairy in the plugins folder because pip3 version is still at 0.08
It is working without error since 2 days

Regards
LucVolders
Posts: 11
Joined: Sunday 23 April 2017 22:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by LucVolders »

Hi,
I bought some lamps and sockets both from the Action store and from Lild.
Action works on wifi and Lidl has a Zigbee hub.

I installed the Tuya APP on my android phone and from there I can
connect to both the Action and the Lidl devices. Works flawless.

Then I added the Python script to Domoticz (the original not the Xenomes version).
It works but only shows the Action (wifi) devices and not the Lidl (Zigbee devices).

Anyone any experience with this.

Luc
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Rolandet »

itguy78 wrote: Wednesday 24 June 2020 3:26
For Downloads/Install steps/Source see this link:
https://github.com/guino/tuyaha
Thanks for the script. Adding devices works just fine :D

I've added my blinds, and it shows up in the Switches tab. Unfortunately it's just OPEN/CLOSE
I've tried with 'Venetian blinds', which adds a "STOP ' button. But that button doesn't do anything.

Any suggestions on how to fix that?

tnx
Custodes Septentrionum
martin82
Posts: 13
Joined: Monday 23 December 2019 15:24
Target OS: -
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by martin82 »

can you tell us which type switch, you use to connect your blinds?
gawel31
Posts: 10
Joined: Friday 11 July 2014 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by gawel31 »

Hi Rolandet,
i had same problem. I made a manual scene into Smart Life that stops blind. When you make a manual scene into smart life, tuya plugin automatically make a device into domoticz....so now, it's easy to make a "stop button" !! ;)
Last edited by gawel31 on Monday 21 December 2020 17:56, edited 1 time in total.
gawel31
Posts: 10
Joined: Friday 11 July 2014 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by gawel31 »

hi,
This plugin is very useful! Thanks to his author! But i also need help. I have tuya switches for blinds. It works perfectly: up, down, stop, half open, etc...When i push "up button", Domoticz tells me that blind is open... It's OK. But one minute later, when tuya script run, blind is updated, and is now closed in domoticz (but open in reality) ! :( So all my blinds are always closed in domoticz... :( My brother has same problem, and an other user in domoticz french forum has also same problem. Could you help us please? Thanks ! ;)

edit: same problem with wifi plugs tuya
Last edited by gawel31 on Monday 21 December 2020 19:25, edited 1 time in total.
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Rolandet »

gawel31 wrote: Monday 21 December 2020 17:42 Hi Rolandet,
i had same problem. I made a manual scene into Smart Life that stops blind. When you make a manual scene into smart life, tuya plugin automatically make a device into domoticz....so now, it's easy to make a "stop button" !! ;)
That works for me. Merci !
Custodes Septentrionum
GeorgeW
Posts: 2
Joined: Wednesday 23 December 2020 19:02
Target OS: Windows
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by GeorgeW »

nice plugin, great job :-)
I'm solving a problem :
OS: Windows 10

Domoticz does not find light 'Smart Strip Light-rdjl' (Smart LED Zigbee MINI Strip Controller RGB LED Strip Light Controller TUYA)
after editing plugyn.py it will add to Domoticz:
*******************************************************************************************************************
if dev_type == "light":
..... etc.
else:
Domoticz.Device(Name=dev.name(), Unit=unit, Type=241, Subtype=2, Switchtype=7, DeviceID=dev.object_id()).Create()
Domoticz.Debug("No controls found for your light device!")
********************************************************************************************************************
Domoticz Devices:
TUYA Xenomes - Smart Strip Light-rdjl Color Switch RGB On

Domoticz log:
(TUYA Xenomes) DEV name=Smart Strip Light-rdjl state=True id=bf921bxxxxxx online=True
(TUYA Xenomes) Update 1:'On' (TUYA Xenomes - Smart Strip Light-rdjl) TimedOut=False

Domoticz change color. plugyn.py original ..... works on / off:
Error: (TUYA Xenomes) 'onCommand' failed 'TypeError':'int() argument must be a string, a bytes-like object or a number, not 'NoneType''.
Eror: (TUYA Xenomes) ----> Line 276 in 'C:\Program Files (x86)\Domoticz\plugins\Domoticz-TUYA-Plugin-master\plugin.py'
Error: (TUYA Xenomes) ----> Line 150 in 'C:\Program Files (x86)\Domoticz\plugins\Domoticz-TUYA-Plugin-master\plugin.py'
Error: (TUYA Xenomes) ----> Line 79 in 'C:\Program Files (x86)\Domoticz\plugins\Domoticz-TUYA-Plugin-master\tuyaha\devices\light.py'
(TUYA Xenomes) onCommand called for Unit 4: Parameter 'Set Color', Level: 15
(TUYA Xenomes) Sending command for DeviceID=bf921bxxxxxxxx
(TUYA Xenomes) color={'b': 98, 'cw': 0, 'g': 199, 'm': 3, 'r': 255, 't': 0, 'ww': 0} h=0.10721868365180466 s=0.615686274509804
Status: setcolbrightnessvalue: ID: 8, bri: 15, color: '{m: 3, RGB: ffc762, CWWW: 0000, CT: 0}'

Domoticz change color. plugyn.py edit .... works on / off and brightness not works color:
*******************************************************************************************************************
Domoticz.Debug("color="+str(rgb)+" h="+str(h)+" s="+str(s))
# If color changed
if Devices[Unit].Color != Hue:
# if mode == 3:
# dev.set_color( [ h*360, s*100 ] )
# Domoticz.Debug("Set color called")
# if mode == 2:
temp = round(2700+((6500-2700)/255*(255-t)))
Domoticz.Debug("temp = " + str(temp))
dev.set_color_temp( temp )
Domoticz.Debug("Set white called")
# If level changed
*******************************************************************************************************************
Domoticz change color:
(TUYA Xenomes) Sending command for DeviceID=bf921bxxxxxxxx
(TUYA Xenomes) color={'b': 107, 'cw': 0, 'g': 144, 'm': 3, 'r': 255, 't': 0, 'ww': 0} h=0.041666666666666664 s=0.5803921568627451
Status: setcolbrightnessvalue: ID: 8, bri: 15, color: '{m: 3, RGB: ff906b, CWWW: 0000, CT: 0}'
Status: setcolbrightnessvalue: ID: 8, bri: 15, color: '{m: 3, RGB: ff906b, CWWW: 0000, CT: 0}'

Domoticz change brightness
(TUYA Xenomes) onCommand called for Unit 4: Parameter 'Set Color', Level: 74
2020-12-25 12:47:12.082 (TUYA Xenomes) Sending command for DeviceID=bf921bxxxxxxxxxxxxxxx
2020-12-25 12:47:12.083 (TUYA Xenomes) color={'b': 106, 'cw': 0, 'g': 143, 'm': 3, 'r': 255, 't': 0, 'ww': 0} h=0.04138702460850112 s=0.5843137254901961
2020-12-25 12:47:12.084 (TUYA Xenomes) temp = 6500
2020-12-25 12:47:12.288 (TUYA Xenomes) Set white called
2020-12-25 12:47:12.471 (TUYA Xenomes) Set bright called

******************************************************************************************************************
debug_discovery.py :
'header': {'code': 'SUCCESS', 'payloadVersion': 1},
'payload': { 'devices': [ { 'data': { 'color_mode': 'colour',
'online': True,
'state': 'true'},
'dev_type': 'light',
'ha_type': 'light',
'icon': 'https://images.tuyaeu.com/smart/icon/ay ... fd4c91.png',
'id': 'bf921bxxxxxxxxxxxx',
'name': 'Smart Strip Light-rdjl'}, ..... etc.
1. debug_discovery.py isn't there an TUYA extension?
2. how to edit * .py win10? (notepad not exactly ideal :-))
3. some tool for monitoring communication TUYA and Android mobile?

thank you for answer
GW
User avatar
Rolandet
Posts: 95
Joined: Thursday 31 January 2019 21:11
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: The Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Rolandet »

2. how to edit * .py win10? (notepad not exactly ideal :-))
Try Bash shell for windows.
Custodes Septentrionum
elbennito
Posts: 21
Joined: Tuesday 27 February 2018 18:19
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by elbennito »

tried this plugin to get my smart life "IR remote control" in domoticz. but I get this error; handleThread: you cannot auth exceed once in 60 seconds. looks Like smart life blocks if you check every 10 seconds the status of device. Anybdoy a solution? Or am I the only one with this problem?
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 »

I also have a problem with a led strip light and bulbs:

When i use the guino/tuyaha Plugin all devices are directed to a switch, but i cannot set lights temperature for the bulbs and color for the led strip.

But when i use the Xenomes/Domoticz-TUYA-Plugin i can set the color temperature for the bulb but the led strip is not assigned to a switch. Tried removing and addin several times.

2021-01-04 21:57:09.972 (Tuya nieuw) DEV name=Led Strip Lights state=True id=bfd13777feb40bfe129fcc online=True
2021-01-04 21:57:09.972 (Tuya nieuw) No controls found for your light device!

2021-01-04 21:57:09.972 (Tuya nieuw) DEV name=If Schema:08:00 Alle Dagen,\"Led Strip Lights\"On/Off:OFF state=False id=DwzAA2IUA6IRYXaN online=True
2021-01-04 21:57:09.972 (Tuya nieuw) DEV name=If Schema:19:00 Alle Dagen,\"Led Strip Lights\"On/Off:ON... state=False id=zWkFUoJotVjiIxB9 online=True
2021-01-04 21:57:19.685 (Tuya nieuw) onHeartbeat called time=1609793839.685206
2021-01-04 21:57:29.657 (Tuya nieuw) onHeartbeat called time=1609793849.6575963
2021-01-04 21:57:39.680 (Tuya nieuw) onHeartbeat called time=1609793859.6799166
2021-01-04 21:57:49.701 (Tuya nieuw) onHeartbeat called time=1609793869.7016788
2021-01-04 21:57:59.674 (Tuya nieuw) onHeartbeat called time=1609793879.6742349
2021-01-04 21:58:09.696 (Tuya nieuw) onHeartbeat called time=1609793889.6961265
2021-01-04 21:58:09.697 (Tuya nieuw) in handlethread
2021-01-04 21:58:09.946 (Tuya nieuw) DEV name=A60 806lm state=True id=30217610500291097a91 online=True
2021-01-04 21:58:09.947 (Tuya nieuw) DEV name=Led Strip Lights state=True id=bfd13777feb40bfe129fcc online=True
2021-01-04 21:58:09.947 (Tuya nieuw) No controls found for your light device!
2021-01-04 21:58:09.947 (Tuya nieuw) DEV name=If Schema:08:00 Alle Dagen,\"Led Strip Lights\"On/Off:OFF state=False id=DwzAA2IUA6IRYXaN online=True
2021-01-04 21:58:09.947 (Tuya nieuw) DEV name=If Schema:19:00 Alle Dagen,\"Led Strip Lights\"On/Off:ON... state=False id=zWkFUoJotVjiIxB9 online=True
2021-01-04 21:58:19.677 (Tuya nieuw) onHeartbeat called time=1609793899.6776757
2021-01-04 21:58:29.699 (Tuya nieuw) onHeartbeat called time=1609793909.6994908
2021-01-04 21:58:39.675 (Tuya nieuw) onHeartbeat called time=1609793919.6749253
2021-01-04 21:58:49.697 (Tuya nieuw) onHeartbeat called time=1609793929.6972575
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by waltervl »

Both plugins have been added to the Wiki Plugin list https://www.domoticz.com/wiki/Plugins (by me)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
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 »

Meeki wrote: Monday 04 January 2021 22:00 I also have a problem with a led strip light and bulbs:

When i use the guino/tuyaha Plugin all devices are directed to a switch, but i cannot set lights temperature for the bulbs and color for the led strip.

But when i use the Xenomes/Domoticz-TUYA-Plugin i can set the color temperature for the bulb but the led strip is not assigned to a switch. Tried removing and addin several times.

2021-01-04 21:57:09.972 (Tuya nieuw) DEV name=Led Strip Lights state=True id=bfd13777feb40bfe129fcc online=True
2021-01-04 21:57:09.972 (Tuya nieuw) No controls found for your light device!
Can you provide me with the json result of this script? debug_discovery.py
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
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 »

waltervl wrote: Monday 04 January 2021 23:55 Both plugins have been added to the Wiki Plugin list https://www.domoticz.com/wiki/Plugins (by me)
Thnx! I couldn't make a account to edit the page, never tried it later.
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 »

Can you provide me with the json result of this script? debug_discovery.py
Can you explain me how to do this? don't know how to run the script.

Kind regards/Groeten

Dennis
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 »

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
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
rbosch
Posts: 11
Joined: Monday 18 January 2016 20:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by rbosch »

I have bought some Tuya Wifi based light bulbs. Added the plugin to Domoticz, but keep getting login errors.

Code: Select all

2021-01-06 22:59:30.658 Error: (Tuya) handleThread: Get accesstoken failed. Username or password error! line 194
Also ran the debug_discovery script - using exactly the same credentials - and that worked fine, producing a nice overview of all my devices.

Can anyone think of what goes wrong?
rbosch
Posts: 11
Joined: Monday 18 January 2016 20:47
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by rbosch »

A few days later and it spontaneously started working. Probably an issue with too many authentication requests in a short timeframe.
Very happy with this plug-in!
Post Reply

Who is online

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