Python Plugin: TUYA

Python and python framework

Moderator: leecollings

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

Re: Python Plugin: TUYA

Post by Xenomes »

Ha i see its version 1.0. Try this one version 1.3
https://github.com/Xenomes/Domoticz-TUYA-Plugin
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Ruudhoevenaar
Posts: 8
Joined: Wednesday 24 July 2019 14:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Ruudhoevenaar »

Hi, I cloned your code from github.

When I use grep, I see that it is now up-to-date:
/plugins/Domoticz-TUYA-Plugin/plugin.py
<plugin key="tuya" name="TUYA" author="Wagner Oliveira" contributed="Xenomes" version="1.0.3" wikilink="http://www.domoticz.com/wiki/plugins/plugin.html" externallink="https://github.com/Xenomes/Domoticz-TUYA-Plugin.git">
# If Mode2 is not set (previous version didn't use it), set it
Since the plugin didn't work right away due to missing files, I copied the missing files from the original plugin. It now works again.
(The files in your repo were .git, __pycache__, tools, plugin.py, README.md \\ Missing parts were: .vscode, tuyaha, .drone.yml, LICENSE, setup.py)

I still have a rgb color wheel and cannot seem to change the hue/color of the lights (by which I mean warmer/cooler colors of the white bulb).
Also, scenes are not available. I guess I'm doing something wrong. Would you be able tell what I need to change?

Thanks again for your support, really appreciate it!
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Ruudhoevenaar wrote: Tuesday 03 November 2020 8:06 Since the plugin didn't work right away due to missing files, I copied the missing files from the original plugin. It now works again.
(The files in your repo were .git, __pycache__, tools, plugin.py, README.md \\ Missing parts were: .vscode, tuyaha, .drone.yml, LICENSE, setup.py)
See the install instructions.
Ruudhoevenaar wrote: Tuesday 03 November 2020 8:06 I still have a rgb color wheel and cannot seem to change the hue/color of the lights (by which I mean warmer/cooler colors of the white bulb).
Also, scenes are not available. I guess I'm doing something wrong. Would you be able tell what I need to change?
Delete the wrong device(s), go to 'Hardware' select the Tuya plugin and click update. Hardware detection must be on.
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Ruudhoevenaar
Posts: 8
Joined: Wednesday 24 July 2019 14:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Ruudhoevenaar »

Removing the lights did the trick.
The plugin automatically refreshed the lights and the yellow-to-blue-wheel became available.

Thanks for the support!
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Nice to hear that it works!
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Domotiks
Posts: 2
Joined: Tuesday 10 November 2020 16:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Domotiks »

Thanks for this plugin, I now can automate my Girier Smart Plugs via Domoticz. 8-)
Is it also possible to monitor the power consumption like in the Smart Life App?
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Domotiks wrote: Tuesday 10 November 2020 16:51 Is it also possible to monitor the power consumption like in the Smart Life App?
Can you provide me with the json result of this script? debug_discovery.py
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Domotiks
Posts: 2
Joined: Tuesday 10 November 2020 16:38
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Domotiks »

[/quote]
Can you provide me with the json result of this script? debug_discovery.py
[/quote]

Sure

Getting devices
Got devices
{ 'header': {'code': 'SUCCESS', 'payloadVersion': 1},
'payload': { 'devices': [ { 'data': {'online': True, 'state': True},
'dev_type': 'switch',
'ha_type': 'switch',
'icon': 'https://images.tuyaeu.com/smart/icon/15 ... kr6b_0.png',
'id': '54524532b4e62d5cd45a',
'name': 'Switch_1'},
{ 'data': {'online': True, 'state': True},
'dev_type': 'switch',
'ha_type': 'switch',
'icon': 'https://images.tuyaeu.com/smart/icon/15 ... kr6b_0.png',
'id': '58660042d8bfc0f1afb4',
'name': ' Switch_2'},
{ 'data': {'online': True, 'state': False},
'dev_type': 'switch',
'ha_type': 'switch',
'icon': 'https://images.tuyaeu.com/smart/icon/15 ... kr6b_0.png',
'id': '478803312cf43204a977',
'name': 'Switch_3'},
{ 'data': {},
'scenes': []}}
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

In the json there is no power consumption value returning. I will check the tuyaha library if there is some code for reading it. I will let you know.
Edit:
There in no reading tuyaha library in the, see https://github.com/PaulAnnekov/tuyaha/b ... /switch.py
Last edited by Xenomes on Monday 16 November 2020 8:41, edited 1 time in total.
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
User avatar
TiXav
Posts: 40
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 »

Xenomes

following the post in Re: Python Plugin still running after disabling in Hardware page @ viewtopic.php?f=65&t=34563

I do these modifications because I bought 2 RGB led strip controllers (CuisinePlan is one of them) and there is a mode colour but no brightness neither no color_temp, so I use them as switch even it could use them at least as dimmer :-(
Capture d’écran 2020-11-16 004409.png
Capture d’écran 2020-11-16 004409.png (47.58 KiB) Viewed 2498 times
debug_discovery.png
debug_discovery.png (37.6 KiB) Viewed 2498 times
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

That is strange, if you change setting in the used Tuya-App and rerun the debug_discovery.py script do you get other data fields in the JSON?
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
moengiant
Posts: 28
Joined: Monday 25 January 2016 6:33
Target OS: Windows
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by moengiant »

Nice work. I do have an issue however with the plugin. I have RGBW Merkury lights and they show up in the tuya app as RGB, however in Domoticz they show up as on/off switches. I'll try to edit the plugin to log info about the bulbs and post back as to what I find out. But again thanks for the nice plugin.
I'd rather have a bottle in front of me than a frontal lobotomy
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

moengiant wrote: Wednesday 18 November 2020 3:05 Nice work. I do have an issue however with the plugin. I have RGBW Merkury lights and they show up in the tuya app as RGB, however in Domoticz they show up as on/off switches. I'll try to edit the plugin to log info about the bulbs and post back as to what I find out. But again thanks for the nice plugin.
Can you provide me with the json result of this script? debug_discovery.py
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
twoenter
Posts: 76
Joined: Sunday 17 February 2019 15:01
Target OS: NAS (Synology & others)
Domoticz version: 4.10
Contact:

Re: Python Plugin: TUYA

Post by twoenter »

Chris12 wrote: Friday 04 September 2020 12:28 I figured out that I need to be in the directory to install pip requests

Code: Select all

root@xxxxxx:~# cd /volume1/@appstore/py3k/usr/local/bin
root@xxxxxx:/volume1/@appstore/py3k/usr/local/bin# sudo python3 pip3 install requests
Collecting requests
  Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB)
     |████████████████████████████████| 61 kB 52 kB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
  Downloading urllib3-1.25.10-py2.py3-none-any.whl (127 kB)
     |████████████████████████████████| 127 kB 10.9 MB/s
Collecting certifi>=2017.4.17
  Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB)
     |████████████████████████████████| 156 kB 11.9 MB/s
Collecting idna<3,>=2.5
  Downloading idna-2.10-py2.py3-none-any.whl (58 kB)
     |████████████████████████████████| 58 kB 1.1 MB/s
Collecting chardet<4,>=3.0.2
  Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
     |████████████████████████████████| 133 kB 11.2 MB/s
Installing collected packages: urllib3, certifi, idna, chardet, requests
  WARNING: The script chardetect is installed in '/volume1/@appstore/py3k/usr/local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.10
root@xxxxxx:/volume1/@appstore/py3k/usr/local/bin#
After stopping and starting Domoticz on my Synology, the domoticz package won't start any more (it directly stops)
How can I unstall the above installed pip requests?

edit: this one was simple to find:

Code: Select all

root@xxxxxx:/volume1/@appstore/py3k/usr/local/bin# sudo python3 pip3 uninstall requests
Found existing installation: requests 2.24.0
Uninstalling requests-2.24.0:
  Would remove:
    /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests-2.24.0.dist-info/*
    /volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages/requests/*
Proceed (y/n)? y
  Successfully uninstalled requests-2.24.0
root@xxxxxx:/volume1/@appstore/py3k/usr/local/bin#
Now domoticz run fine again... but the smartplug has still the same error.

edit2:
When removing first the TUYA hardware already defined/created in domoticz, and then install the pip3 request
Domoticz keeps on running fine, after adding the TUYA hardware, domoticz is stopped and wont start again.

Had the same problems with installing the python packages. sudo pip3 requests did the trick, without python or python3 before pip. ;-). If you want a complete guide from a to z for installing tuya devices in domoticz, read my blog: https://www.twoenter.nl/blog/domoticz/t ... -domoticz/ (in dutch but you can use google translate)
Check my Domoticz tutorials, ESP8266 and Synology blog at https://www.twoenter.nl/blog
cle69
Posts: 2
Joined: Monday 01 August 2016 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by cle69 »

Very nice works :) :) :)

This plugin work very well. i have 4 roller shutter switch and 3 scene
But i have a problem with 1 device he don't works with this plugin :( I found a by-pass by using scene to control it, but isn't a good solution ;)
The faulty device it-is a new 4th generation of roller shutter switch with new percent feature.

Can you help me to improve plugin to manage well this switch ?

You can find below the discovery log
the faulty device is "Volet Salon 1"

Got devices
Spoiler: show

Code: Select all

{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'online': True,
                                                  'state': 1,
                                                  'support_stop': True},
                                      'dev_type': 'cover',
                                      'ha_type': 'cover',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/qt.png',
                                      'id': '62180573bcddc2',
                                      'name': 'Volet Vanessa'},
                                  {   'data': {   'online': True,
                                                  'state': 3,
                                                  'support_stop': True},
                                      'dev_type': 'cover',
                                      'ha_type': 'cover',
                                      'icon': 'https://images.tuyaeu.com/smart/program_category_icon/clkg.png',
                                      'id': '45106374bcddc',
                                      'name': 'Volet Amis'},
                                  {   'data': {   'online': True,
                                                  'state': 3,
                                                  'support_stop': True},
                                      'dev_type': 'cover',
                                      'ha_type': 'cover',
                                      'icon': 'https://images.tuyaeu.com/smart/program_category_icon/clkg.png',
                                      'id': '451063742cf432',
                                      'name': 'volet Cuisine'},
                                  { [b]  'data': {'online': True, 'state': False},
                                      'dev_type': 'switch',
                                      'ha_type': 'switch',
                                      'icon': 'https://images.tuyaeu.com/smart/program_category_icon/cl.png',
                                      'id': '0518502640f52',
                                      'name': 'Volet Salon 1'},[/b]
                                  {   'data': {},
                                      'dev_type': 'scene',
                                      'ha_type': 'scene',
                                      'id': 'yd32oG8gTwkX',
                                      'name': 'Si :23:30 volet Cuisine '
                                              'Fermer '},
                                  {   'data': {},
                                      'dev_type': 'scene',
                                      'ha_type': 'scene',
                                      'id': '5LAASAkwq9X',
                                      'name': 'si Coucher du soleil Ferme '
                                              'ami/salon'},
                                  {   'data': {},
                                      'dev_type': 'scene',
                                      'ha_type': 'scene',
                                      'id': 'ADJthuwyxX3',
                                      'name': 'Si Chassieu Lever Ouvrir ami / '
                                              'Salon'}],
                   'scenes': []}}
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

cle69 wrote: Monday 30 November 2020 16:21 You can find below the discovery log
the faulty device is "Volet Salon 1"
The strange thing is the 'tuyaha' report it as a switch. can you change the state of the device and run the debug_discovery.py again?
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
cle69
Posts: 2
Joined: Monday 01 August 2016 20:24
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by cle69 »

cle69 wrote: Monday 30 November 2020 16:21 The strange thing is the 'tuyaha' report it as a switch. can you change the state of the device and run the debug_discovery.py again?
Yes that is strange, I have tested to open and close and the status never change, it is always State = False. :(
With Smart Life application is work well, with some new options, percentage, child lock...
I'm wondering if it's not using a new, improved API version :?:
CV8R
Posts: 21
Joined: Thursday 27 September 2018 7:13
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by CV8R »

Hi @Xenomes

Thank you for working on this plugin.

I have recently acquired an Inkbird ITC-308-WIFI temperature controller. It reports temperature and allows the switching of heating and cooling based on a set point. I am using it for a Marine Fish Tank.

Below is a dump from your debug_discovery. The TUYA app allows me to set the units switchpoints and various settings but also reports the temp.

Getting devices
Got devices
{ 'header': {'code': 'SUCCESS', 'payloadVersion': 1},
'payload': { 'devices': [ { 'data': { 'current_temperature': 232,
'max_temper': 2120,
'min_temper': -400,
'online': True,
'state': 'false',
'temperature': 240},
'dev_type': 'climate',
'ha_type': 'climate',
'icon': 'https://images.tuyaeu.com/smart/icon/15 ... 2c7z_0.png',
'id': '428061235002916fca85',
'name': 'Marine Tank Thermostat'}],
'scenes': []}}


From what I can tell based on the setup of the unit the returned values are as per below. Temps are <value/10> so 232 is 23.2C.

'current_temperature': 232 = Current Temp
'max_temper': 2120, = Max Temp for Alarm
'min_temper': -400, = Min Temp for Alarm
'online': True, = Is the unit online
'state': 'false', = No idea, does not appear to change even if the unit goes into heating or cooling mode.
'temperature': 240 = Set point for the temp

Is it possible that you could look at integrating this device to report at minimum the reported temp and allow setting the set point? There are many things it does via the TUYA app like flag alarms over the max and min alarm set points but I am not sure how I can sniff this data.

Cheers
CV8R.
User avatar
Xenomes
Posts: 402
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

CV8R wrote: Wednesday 02 December 2020 9:00 Is it possible that you could look at integrating this device to report at minimum the reported temp and allow setting the set point? There are many things it does via the TUYA app like flag alarms over the max and min alarm set points but I am not sure how I can sniff this data.
I created a issue on GitHub
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2024.7 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
Rusla
Posts: 3
Joined: Wednesday 15 January 2020 14:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Rusla »

Xenomes wrote: Tuesday 10 November 2020 22:04 There in no reading tuyaha library in the
So there is no possibility to read power from smart plug?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest