Python Plugin: TUYA

Python and python framework

Moderator: leecollings

User avatar
Varazir
Posts: 434
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: TUYA

Post by Varazir »

Xenomes wrote: Tuesday 15 June 2021 19:08
Varazir wrote: Tuesday 15 June 2021 18:43 I have bought a Cleverio AF-F100 and installed this plugin.
The plugin finds it as a fan and can turn it off and on but the fan has more features.
Is there a way I can add them ?
Maybe there are more functions to control, can you configure and run the "debug_discovery.py" in the tool directory and list the json output here.

Code: Select all

Getting credentials
Got credentials
{   'access_token': 'EUheu16231687409295xK52o0uYN6nH70',
    'expires_in': 864000,
    'refresh_token': 'EUheu16231687409295xK52Yju31YxZbj',
    'token_type': 'bearer'}
Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'online': True,
                                                  'state': 'false'},
                                      'dev_type': 'fan',
                                      'ha_type': 'fan',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/ay1541396207188PFb5m/1606371614d15f3241523.png',
                                      'id': '43035720e098061d58bc',
                                      'name': 'Cleverio AF-F100'}],
                   'scenes': []}}
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Varazir wrote: Tuesday 15 June 2021 19:13

Code: Select all

Getting credentials
Got credentials
{   'access_token': 'EUheu16231687409295xK52o0uYN6nH70',
    'expires_in': 864000,
    'refresh_token': 'EUheu16231687409295xK52Yju31YxZbj',
    'token_type': 'bearer'}
Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'online': True,
                                                  'state': 'false'},
                                      'dev_type': 'fan',
                                      'ha_type': 'fan',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/ay1541396207188PFb5m/1606371614d15f3241523.png',
                                      'id': '43035720e098061d58bc',
                                      'name': 'Cleverio AF-F100'}],
                   'scenes': []}}
The only command to control is the 'state' that is on/off, noting we can do about that on this side. You can ask Tuya support to support your device in their /homeassistant API. (The Domoticz plug in use the same API/script)
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
User avatar
Varazir
Posts: 434
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Python Plugin: TUYA

Post by Varazir »

Xenomes wrote: Tuesday 15 June 2021 19:29
Varazir wrote: Tuesday 15 June 2021 19:13

Code: Select all

Getting credentials
Got credentials
{   'access_token': 'EUheu16231687409295xK52o0uYN6nH70',
    'expires_in': 864000,
    'refresh_token': 'EUheu16231687409295xK52Yju31YxZbj',
    'token_type': 'bearer'}
Getting devices
Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'online': True,
                                                  'state': 'false'},
                                      'dev_type': 'fan',
                                      'ha_type': 'fan',
                                      'icon': 'https://images.tuyaeu.com/smart/icon/ay1541396207188PFb5m/1606371614d15f3241523.png',
                                      'id': '43035720e098061d58bc',
                                      'name': 'Cleverio AF-F100'}],
                   'scenes': []}}
The only command to control is the 'state' that is on/off, noting we can do about that on this side. You can ask Tuya support to support your device in their /homeassistant API. (The Domoticz plug in use the same API/script)
Okay thanks
Raspberry PI 2 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Hi All,

i'm really happy that the Curtain Switch is also working perfectly, it open and close the roller blind like it should..!
I have only one question, why is the stop (pause) button not working?
Is it possible to do also the roller blind open half (50%) for example?
It works only with full OPEN or full CLOSE (On / Off) but the stop (pause) button is doing nothing :(
Ofcourse in the Tuya app the Pause is working correctly..
I have this Tuya:
https://www.amazon.nl/VISLONE-Intellige ... 47&sr=8-45
rol1.jpg
rol1.jpg (9.8 KiB) Viewed 1674 times
I hope someone has the answer! :D
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

BarryT wrote: Friday 09 July 2021 21:54 Hi All,

i'm really happy that the Curtain Switch is also working perfectly, it open and close the roller blind like it should..!
I have only one question, why is the stop (pause) button not working?
Is it possible to do also the roller blind open half (50%) for example?
It works only with full OPEN or full CLOSE (On / Off) but the stop (pause) button is doing nothing :(
Ofcourse in the Tuya app the Pause is working correctly..
I have this Tuya:
https://www.amazon.nl/VISLONE-Intellige ... 47&sr=8-45
rol1.jpg
I hope someone has the answer! :D
The stop command was not programed jet in the plugin, i add it in the new version 1.0.11. I can't send percentage to the Tuya api, maybe you can make a time script to run 30 sec if 1 min is full open. 😅
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Friday 09 July 2021 22:40
BarryT wrote: Friday 09 July 2021 21:54 Hi All,

i'm really happy that the Curtain Switch is also working perfectly, it open and close the roller blind like it should..!
I have only one question, why is the stop (pause) button not working?
Is it possible to do also the roller blind open half (50%) for example?
It works only with full OPEN or full CLOSE (On / Off) but the stop (pause) button is doing nothing :(
Ofcourse in the Tuya app the Pause is working correctly..
I have this Tuya:
https://www.amazon.nl/VISLONE-Intellige ... 47&sr=8-45
rol1.jpg
I hope someone has the answer! :D
The stop command was not programed jet in the plugin, i add it in the new version 1.0.11. I can't send percentage to the Tuya api, maybe you can make a time script to run 30 sec if 1 min is full open. 😅
Great job, going to test tomorrow..
After writing this reply i updated the plugin, it seems to be on 1.0.11 now ;)
I will let you know, thanks!
Ps, is there a way to change the venetian blinds eu into venetian blinds inverted?
In standby the plugin read its state as closed while it is open..
Or do i have to change the motor into reversed mode, and change the wheel / roller?
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Stop is still not working :cry:
I'm using it as venetian eu, or did i do something wrong?
How can i use the stop?
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

BarryT wrote: Friday 09 July 2021 23:36 Ps, is there a way to change the venetian blinds eu into venetian blinds inverted?
Current you can only change it directly in the database. 😅
BarryT wrote: Saturday 10 July 2021 7:59 Stop is still not working :cry:
I'm using it as venetian eu, or did i do something wrong?
How can i use the stop?
Can you set the debugging of the plugin on All and do some stops and post the logging of Domoticz here. I can't test it my self i don't have a device that use this function.
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Code: Select all

2021-07-10 09:37:46.443  Status: User: Admin initiated a switch command (2622/Rolgordijn Keuken/On)
2021-07-10 09:37:46.443  Tuya: (Tuya) Pushing 'onCommandCallback' on to queue
2021-07-10 09:37:46.476  (Tuya) Processing 'onCommandCallback' message
2021-07-10 09:37:46.476  Tuya: (Tuya) Calling message handler 'onCommand' on 'module' type object.
2021-07-10 09:37:46.476  Tuya: (Tuya) onCommand called for Unit 1: Parameter 'On', Level: 0
2021-07-10 09:37:46.477  Tuya: (Tuya) Sending command for DeviceID=00***

2021-07-10 09:37:50.710  Status: User: Admin initiated a switch command (2622/Rolgordijn Keuken/Stop)
2021-07-10 09:37:50.710  Tuya: (Tuya) Pushing 'onCommandCallback' on to queue
2021-07-10 09:37:50.727  (Tuya) Processing 'onCommandCallback' message
2021-07-10 09:37:50.727  Tuya: (Tuya) Calling message handler 'onCommand' on 'module' type object.
2021-07-10 09:37:50.727  Tuya: (Tuya) onCommand called for Unit 1: Parameter 'Stop', Level: 0
2021-07-10 09:37:50.727  Tuya: (Tuya) Sending command for DeviceID=00****
2021-07-10 09:37:52.030  Tuya: (Tuya) Pushing 'onHeartbeatCallback' on to queue
2021-07-10 09:37:52.080  (Tuya) Processing 'onHeartbeatCallback' message
2021-07-10 09:37:52.080  Tuya: (Tuya) Calling message handler 'onHeartbeat' on 'module' type object.
2021-07-10 09:37:52.080  Tuya: (Tuya) onHeartbeat called time=1625902672.0804992

2021-07-10 09:37:52.105  Status: User: Admin initiated a switch command (2622/Rolgordijn Keuken/Off)
2021-07-10 09:37:52.106  Tuya: (Tuya) Pushing 'onCommandCallback' on to queue
2021-07-10 09:37:52.130  (Tuya) Processing 'onCommandCallback' message
2021-07-10 09:37:52.130  Tuya: (Tuya) Calling message handler 'onCommand' on 'module' type object.
2021-07-10 09:37:52.130  Tuya: (Tuya) onCommand called for Unit 1: Parameter 'Off', Level: 0
2021-07-10 09:37:52.131  Tuya: (Tuya) Sending command for DeviceID=00***
2021-07-10 09:37:52.179  (Rolgordijn Keuken) Updating device from 1:'On' to have values 0:'Off'.
2021-07-10 09:37:52.192  Tuya: (Tuya) Update 0:'Off' (Rolgordijn Keuken) TimedOut=False
I did a close (on) then STOP (didnt work), then open (Off) again..
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

BarryT wrote: Saturday 10 July 2021 9:42

Code: Select all

2021-07-10 09:37:50.727  Tuya: (Tuya) onCommand called for Unit 1: Parameter 'Stop', Level: 0
Damn... make a typo in de code used 'stop' instead of 'Stop'. update the plug-in again and test again.
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Saturday 10 July 2021 15:41
BarryT wrote: Saturday 10 July 2021 9:42

Code: Select all

2021-07-10 09:37:50.727  Tuya: (Tuya) onCommand called for Unit 1: Parameter 'Stop', Level: 0
Damn... make a typo in de code used 'stop' instead of 'Stop'. update the plug-in again and test again.
Lol... Hold'on a couple minutes!

Code: Select all

 remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/Xenomes/Domoticz-TUYA-Plugin
   400781d..1b8fa09  master     -> origin/master
Updating 400781d..1b8fa09
Fast-forward
 plugin.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

so far no errors..
Edit* You did a great job! It's working now! :)

Thanks!
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Xenomes wrote: Saturday 10 July 2021 8:39
BarryT wrote: Friday 09 July 2021 23:36 Ps, is there a way to change the venetian blinds eu into venetian blinds inverted?
Current you can only change it directly in the database. 😅
I got a idea, if _inv is added to the end of the name of cover in the Tuya based app the control will be inverted. Can you test this special patch https://github.com/Xenomes/Domoticz-TUY ... /plugin.py
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Saturday 10 July 2021 16:23
Xenomes wrote: Saturday 10 July 2021 8:39
BarryT wrote: Friday 09 July 2021 23:36 Ps, is there a way to change the venetian blinds eu into venetian blinds inverted?
Current you can only change it directly in the database. 😅
I got a idea, if _inv is added to the end of the name of cover in the Tuya based app the control will be inverted. Can you test this special patch https://github.com/Xenomes/Domoticz-TUY ... /plugin.py
Let me clearly say that the device in domoticz is not inverted at all, it works exactly what it has to do, open is open and close is close, but only the 'state' in domoticz in standby mode (after 60 sec) is always going to to close (instead of open)..
My screen is open right now :
Screenshot_20210710-165645.jpg
Screenshot_20210710-165645.jpg (31.52 KiB) Viewed 1611 times
Imo, i used the motor direction switch in tuya otherwise the knobs on the hardware where wrong.. ;)
It should go to open when status is open or better maybe to stop.. if it is possible
For example, when i open the blind, the knob open will be activated and hold for 60 seconds, after that the state goes back to closed while it is open.
It is not that bad at all, but in tuya the last (%) status is always shown, that is not in domoticz.
Screenshot_20210710-170912_Tuya Smart.jpg
Screenshot_20210710-170912_Tuya Smart.jpg (51.04 KiB) Viewed 1600 times
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

BarryT wrote: Saturday 10 July 2021 16:56 Let me clearly say that the device in domoticz is not inverted at all, it works exactly what it does, but only the 'state' in domoticz in standby mode (after 30 sec) is always going to to close (instead of open)..
O sorry, didn't mention that you need to remove the device and let it rediscovered. The standby mode (after 30 sec) I don't know yet.
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Saturday 10 July 2021 17:11
BarryT wrote: Saturday 10 July 2021 16:56 Let me clearly say that the device in domoticz is not inverted at all, it works exactly what it does, but only the 'state' in domoticz in standby mode (after 30 sec) is always going to to close (instead of open)..
O sorry, didn't mention that you need to remove the device and let it rediscovered. The standby mode (after 30 sec) I don't know yet.
I edited it later, pardon me.. it is after 60 seconds when the motor is finished doing its job.
Maybe this is an domoticz related thing, not your plugin?
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

I don't have devices with movement and stop... So closed and open are going to closed after 60 seconds, can you look what the debug tool give what the state is? (in tools and edit the file to fill in your credentials and run it with python3 )
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Saturday 10 July 2021 19:03 I don't have devices with movement and stop... So closed and open are going to closed after 60 seconds, can you look what the debug tool give what the state is? (in tools and edit the file to fill in your credentials and run it with python3 )
Sure, will do asap!
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

BarryT wrote: Saturday 10 July 2021 19:15
Xenomes wrote: Saturday 10 July 2021 19:03 I don't have devices with movement and stop... So closed and open are going to closed after 60 seconds, can you look what the debug tool give what the state is? (in tools and edit the file to fill in your credentials and run it with python3 )
Sure, will do asap!
Ps, no it works correctly!
After opening it stays open,but the only thing is that the switch in domoticz is going to close after 60 seconds, but its only the state of the switch, no command is followed after it. the blind stays open.. only the switch goes back to close.
Example:
I click on 'open', the blind is going to open.. the button i pressed, stays on 'open' for 60 seconds, after that it goes to 'close' and stays on 'close'. But the blind stay open, so no command is send after opening, only the state of the switch is changing to close..
Can you follow me? Haha
The close button works correctly.
User avatar
Xenomes
Posts: 416
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

BarryT wrote: Saturday 10 July 2021 20:20 Can you follow me? Haha
Yes I understand ... can you try https://github.com/Xenomes/Domoticz-TUY ... tch-BarryT
HP T630 (256GB SSD/8GB Mem) - Ubuntu 24.04.2 LTS (64Bit) - Domoticz 2025.1 (Docker) Machinon theme - RFLink - KaKu - Sonoff - Tasmota - Shelly - MQTT2Zigbee - OpenTherm Gateway - Tinytuya - IR Blaster - P1 Smart Meter - NPN Watermeter - Google Assistant
BarryT
Posts: 369
Joined: Tuesday 31 March 2015 22:06
Target OS: Linux
Domoticz version: 2024.3
Location: east netherlands
Contact:

Re: Python Plugin: TUYA

Post by BarryT »

Xenomes wrote: Saturday 10 July 2021 20:49
BarryT wrote: Saturday 10 July 2021 20:20 Can you follow me? Haha
Yes I understand ... can you try https://github.com/Xenomes/Domoticz-TUY ... tch-BarryT
unfortunately there is no change..
i click on open, the blind (stays) open and the button is saying open. So far so good, but after 60 seconds the state is back to close(d)..
i can make a video, hold on then you know what i mean :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest