Python Plugin: TUYA

Python and python framework

Moderator: leecollings

tontze
Posts: 317
Joined: Thursday 12 January 2017 15:30
Target OS: Linux
Domoticz version: Beta Ch
Location: Finland
Contact:

Re: Python Plugin: TUYA

Post by tontze »

Xenomes wrote: Saturday 27 March 2021 11:58
tontze wrote: Saturday 27 March 2021 10:39 Hm, im trying to use your plugin, but cant seem to get it working .. Here is output.
It is missing the requests.
tontze@T610:~$ sudo pip3 install requests
[sudo] password for tontze:
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.25.1)

I wonder why requests is a problem in so many plugins, had hard time with it in miio stuff too..

Code: Select all

Name: requests
Version: 2.25.1
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
Location: /usr/lib/python3/dist-packages
Requires:
Required-by: CacheControl
Last edited by tontze on Saturday 27 March 2021 12:27, edited 1 time in total.
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Sunday 21 March 2021 21:55
Xenomes wrote: Friday 19 March 2021 7:51
manjh wrote: Thursday 18 March 2021 22:36 Output is in the post a little higher in this forum.
Found it 👍🏻 i see the problem i need to think how to solve the issue.
The payload is exactly the same, I could do if the light is on white mode the only brightness and temperature and if it is colour then colour, brightness and temperature. Then with a instruction in the readme for RGBWW light before detection set the light on a colour.
Would it be possible to create a switch somewhere so I can set the device to white or rgb?

What puzzles me: if the payload is the same, then why is it that the Tuya app knows that the lamp is white-only? Apparently the app has a way to detect it!
Hans
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 »

manjh wrote: Saturday 27 March 2021 12:25 What puzzles me: if the payload is the same, then why is it that the Tuya app knows that the lamp is white-only? Apparently the app has a way to detect it!
Not all info is shared by the api
This is you payload (White only):

Code: Select all

{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'brightness': '130',
                                                  'color_mode': 'white',
                                                  'color_temp': 1000,
                                                  'online': True,
                                                  'state': 'true'},
                                      'dev_type': 'light',
                                      'ha_type': 'light',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/ay1541056239985fDGjj/15919273389f9d925c99f.png',
                                      'id': '6276453110521cc9ecd9',
                                      'name': 'LSC 2'},
This is my payload (RGBWW):

Code: Select all

{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'brightness': '255',
                                                  'color_mode': 'colour',
                                                  'color_temp': 10000,
                                                  'online': True,
                                                  'state': 'true'},
                                      'dev_type': 'light',
                                      'ha_type': 'light',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/ay1541056239985fDGjj/15620318474c719f1c5cf.png',
                                      'id': 'bfa550692e71343800we58',
                                      'name': '3D Lamp'}],
When I set my lamp to white then 'color_mode': 'colour', change 'color_mode': 'white', . So there is no other data to use.
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 »

tontze wrote: Saturday 27 March 2021 12:00 I wonder why requests is a problem in so many plugins, had hard time with it in miio stuff too..
I am also on version 2.25.1, did you edit the file and start the debug_discovery.py as

Code: Select all

sudo python3 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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Saturday 27 March 2021 13:44
manjh wrote: Saturday 27 March 2021 12:25 What puzzles me: if the payload is the same, then why is it that the Tuya app knows that the lamp is white-only? Apparently the app has a way to detect it!
Not all info is shared by the api
OK, understood. Perhaps the ID field is used by Tuya to find the type of lamp in a database somewhere... :(

So either we go for the additional flag on the device, making it a white or rgb lamp, or we simply leave it as it is.
I guess I can live with the superfluous color wheel...

If we leave it, perhaps it is a good idea to mention in the readme that the plugin cannot always determine the type of lamp?
Hans
tontze
Posts: 317
Joined: Thursday 12 January 2017 15:30
Target OS: Linux
Domoticz version: Beta Ch
Location: Finland
Contact:

Re: Python Plugin: TUYA

Post by tontze »

Xenomes wrote: Saturday 27 March 2021 13:52
tontze wrote: Saturday 27 March 2021 12:00 I wonder why requests is a problem in so many plugins, had hard time with it in miio stuff too..
I am also on version 2.25.1, did you edit the file and start the debug_discovery.py as

Code: Select all

sudo python3 debug_discovery.py
Yes i did.
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Vomera »

Code: Select all

2021-03-30 11:20:01.115 Error: (Tuya) 'onCommand' failed 'TypeError':'int() argument must be a string, a bytes-like object or a number, not 'NoneType''.
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 250 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 143 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 79 in '/home/pi/domoticz/plugins/tuyaha/tuyaha/devices/light.py', function set_color
I am still not able to change color from the RGB in domoticz, i can turn off and on the light and can dim. If someone has a solution please let me know :D
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 »

Vomera wrote: Tuesday 30 March 2021 11:42

Code: Select all

2021-03-30 11:20:01.115 Error: (Tuya) 'onCommand' failed 'TypeError':'int() argument must be a string, a bytes-like object or a number, not 'NoneType''.
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 250 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 143 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 79 in '/home/pi/domoticz/plugins/tuyaha/tuyaha/devices/light.py', function set_color
I am still not able to change color from the RGB in domoticz, i can turn off and on the light and can dim. If someone has a solution please let me know :D
Why do you have tuyaha in you Domoticz plug-in directory?
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 »

manjh wrote: Saturday 27 March 2021 14:39 OK, understood. Perhaps the ID field is used by Tuya to find the type of lamp in a database somewhere... :(

So either we go for the additional flag on the device, making it a white or rgb lamp, or we simply leave it as it is.
I guess I can live with the superfluous color wheel...

If we leave it, perhaps it is a good idea to mention in the readme that the plugin cannot always determine the type of lamp?
I added my idea to the plug-in for RGBWW and White it works, but i can not test it for RGB only devices. Can you test it on your White only device?
Warning development version!

Code: Select all

git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git -b development
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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Wednesday 31 March 2021 22:17
manjh wrote: Saturday 27 March 2021 14:39 OK, understood. Perhaps the ID field is used by Tuya to find the type of lamp in a database somewhere... :(

So either we go for the additional flag on the device, making it a white or rgb lamp, or we simply leave it as it is.
I guess I can live with the superfluous color wheel...

If we leave it, perhaps it is a good idea to mention in the readme that the plugin cannot always determine the type of lamp?
I added my idea to the plug-in for RGBWW and White it works, but i can not test it for RGB only devices. Can you test it on your White only device?
Warning development version!

Code: Select all

git clone https://github.com/Xenomes/Domoticz-TUYA-Plugin.git -b development
I ran the git line in my R-Pi. No change. Should I do something to force renewal of the lamps?
Already disabled and enabled the Tuya HW line in Domoticz. No effect.
Last edited by manjh on Wednesday 31 March 2021 22:45, edited 1 time in total.
Hans
Vomera
Posts: 184
Joined: Wednesday 06 September 2017 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Vomera »

Xenomes wrote: Wednesday 31 March 2021 20:12
Vomera wrote: Tuesday 30 March 2021 11:42

Code: Select all

2021-03-30 11:20:01.115 Error: (Tuya) 'onCommand' failed 'TypeError':'int() argument must be a string, a bytes-like object or a number, not 'NoneType''.
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 250 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 143 in '/home/pi/domoticz/plugins/tuyaha/plugin.py', function onCommand
2021-03-30 11:20:01.115 Error: (Tuya) ----> Line 79 in '/home/pi/domoticz/plugins/tuyaha/tuyaha/devices/light.py', function set_color
I am still not able to change color from the RGB in domoticz, i can turn off and on the light and can dim. If someone has a solution please let me know :D
Why do you have tuyaha in you Domoticz plug-in directory?
Where else should it be ? :)
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 »

manjh wrote: Wednesday 31 March 2021 22:42 I ran the git line in my R-Pi. No change. Should I do something to force renewal of the lamps?
Already disabled and enabled the Tuya HW line in Domoticz. No effect.
Sorry, yes you hsve to delete the 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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Wednesday 31 March 2021 23:06
manjh wrote: Wednesday 31 March 2021 22:42 I ran the git line in my R-Pi. No change. Should I do something to force renewal of the lamps?
Already disabled and enabled the Tuya HW line in Domoticz. No effect.
Sorry, yes you hsve to delete the device 😅
Delete the device in Domoticz only, so leave it alone in Tuya?
Hans
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 »

Yes restart the plug-in by update in the hardware tab.
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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

OK, I deleted the device in Domoticz, then disabled the Tuya HW entry, and enabled it again.
In the log I saw the lamp come in again with the Tuya name, and enabled it into Domoticz.
It is stil RGB...
Hans
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 »

manjh wrote: Wednesday 31 March 2021 23:14 OK, I deleted the device in Domoticz, then disabled the Tuya HW entry, and enabled it again.
In the log I saw the lamp come in again with the Tuya name, and enabled it into Domoticz.
It is stil RGB...
What version of the plug-in do it show?
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 »

Vomera wrote: Wednesday 31 March 2021 22:42 Where else should it be ? :)
The second tuyaha is not needed with my version of the plug-in. I was mislead with the naming of the directory. You are using the version of guino in that version is has limited control of RGB. Can you try my version of the plug[in. https://github.com/Xenomes/Domoticz-TUYA-Plugin.
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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Thursday 01 April 2021 20:54
manjh wrote: Wednesday 31 March 2021 23:14 OK, I deleted the device in Domoticz, then disabled the Tuya HW entry, and enabled it again.
In the log I saw the lamp come in again with the Tuya name, and enabled it into Domoticz.
It is stil RGB...
What version of the plug-in do it show?
V.1.0.4
Hans
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 »

manjh wrote: Thursday 01 April 2021 21:37 V.1.0.4
That is not the latest version ... Delete devices and update the plug-in, restart Domoticz and see the new detection.

Edit: Just push a new version
(⚠ RGBW(W) lights must be on a colour for correct detection ⚠)
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
manjh
Posts: 708
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by manjh »

Xenomes wrote: Thursday 01 April 2021 22:06
manjh wrote: Thursday 01 April 2021 21:37 V.1.0.4
That is not the latest version ... Delete devices and update the plug-in, restart Domoticz and see the new detection.

Edit: Just push a new version
(⚠ RGBW(W) lights must be on a colour for correct detection ⚠)
OK, now getting version 6.
Deleted one lamp, disabled/enabled Tuya, now get this error in the log:

Code: Select all

Error: (Tuya devices) handleThread: Expecting value: line 1 column 1 (char 0) line 198
Also:

Code: Select all

Error: (Tuya devices) handleThread: login rate limited line 195
Hans
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest