Python Plugin: TUYA

Python and python framework

Moderator: leecollings

Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

Xenomes wrote: Thursday 03 September 2020 15:36 You need to Install a python Library 'requests'.

Code: Select all

pip3 install requests
On my synology that command is not found.

Code: Select all

login as: admin
[email protected]'s password:
admin@xxxxxx:~$ 
admin@xxxxxx:~$ sudo -i
root@xxxxxx:~# pip3 install requests
-ash: pip3: command not found
root@xxxxxx:~#
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

I don't have a Synology NAS but maybe

Code: Select all

python3 -m pip install requests
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
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

unfortunatelly that gives:

Code: Select all

root@xxxxxxx:~# python3 -m pip install requests
/usr/local/bin/python3: No module named pip
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

Is this the first plug-in you installed on your system? Many plug-ins uses python library's.

I think this site has a script to install pip. a you own risk, i am no NAS expert :D
https://primalcortex.wordpress.com/2016 ... installer/
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
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

Xenomes wrote: Thursday 03 September 2020 18:41 Is this the first plug-in you installed on your system? Many plug-ins uses python library's.

I think this site has a script to install pip. a you own risk, i am no NAS expert :D
https://primalcortex.wordpress.com/2016 ... installer/
This is the first plugin I'm trying to use.

Pip installation went fine, only one question here how can I update pip?
Or is it now updated?

You are using pip version 7.1.2, however version 20.2.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@xxxxxx:~# ^C
root@xxxxxx:~# pip install --upgrade pip
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/developme ... -2-support
Requirement already up-to-date: pip in /usr/lib/python2.7/site-packages (20.2.2)
root@xxxxxx:~#

For PY 3.5 I used the following commands to install:
python3.5 -m ensurepip
python3.5 -m pip install flask


After stopping and starting the domoticz package in Synology, and re-adding the TUYA hardware I get the follwoing error:

2020-09-04 07:31:36.985 Error: (tuya) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/tuyaha-master/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages'.
2020-09-04 07:31:36.985 Error: (SmartPlug-1) Module Import failed, exception: 'ImportError'
2020-09-04 07:31:36.985 Error: (SmartPlug-1) Module Import failed: ' Name: requests'
2020-09-04 07:31:36.985 Error: (SmartPlug-1) Error Line details not available.

Maybe it is wiser for me just to try and flash the TUYA smartplug with Tasmota, that seems to be more regular.
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

I see you default Python is version 2. So if you run this sudo python3 get-pip.py then it will be executed with Python version 3.
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
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

Ok, ran the PY 3 command:

Code: Select all

root@xxxxxx:~# sudo python3 get-pip.py
Collecting pip
  Using cached pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
Collecting wheel
  Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: pip, wheel
  Attempting uninstall: pip
    Found existing installation: pip 7.1.2
    Uninstalling pip-7.1.2:
      Successfully uninstalled pip-7.1.2
  WARNING: The scripts pip, pip3 and pip3.5 are 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.
  WARNING: The script wheel 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 pip-20.2.2 wheel-0.35.1
After stopping/starting the domoticz package on my synology, the log file still shows the error:

2020-09-04 11:22:19.435 Error: (tuya) failed to load 'plugin.py', Python Path used was '/usr/local/domoticz/var/plugins/tuyaha-master/:/volume1/@appstore/py3k/usr/local/lib/python35.zip:/volume1/@appstore/py3k/usr/local/lib/python3.5/:/volume1/@appstore/py3k/usr/local/lib/python3.5/plat-linux:/volume1/@appstore/py3k/usr/local/lib/python3.5/lib-dynload:/volume1/@appstore/py3k/usr/local/lib/python3.5/site-packages'.
2020-09-04 11:22:19.435 Error: (SmartPlug-1) Module Import failed, exception: 'ImportError'
2020-09-04 11:22:19.436 Error: (SmartPlug-1) Module Import failed: ' Name: requests'
2020-09-04 11:22:19.436 Error: (SmartPlug-1) Error Line details not available.
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

Did you install sudo python3 pip3 install requests ?
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
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

No, how do I install that?

Code: Select all

root@xxxxxx:~# sudo python3 pip3 install requests
python3: can't open file 'pip3': [Errno 2] No such file or directory
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

Then sudo python3 pip install requests
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
Chris12
Posts: 238
Joined: Tuesday 18 August 2020 8:41
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by Chris12 »

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.
Domoticz beta | Dashticz beta | Synology DS415+ | Wall tablet Teclast 11.6inch (Android) | TADO v3 controlled heating
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 »

The plugin requires requests, So without it will not run.
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
itguy78
Posts: 12
Joined: Friday 10 May 2019 17:43
Target OS: Raspberry Pi / ODroid
Domoticz version: 12184
Contact:

Re: Python Plugin: TUYA

Post by itguy78 »

Xenomes wrote: Wednesday 02 September 2020 5:50 Hi itguy78,

Is it possible that you change your github clone in a standalone project? called 'Domoticz-TUYA-Plugin' (as in the file) your script is only depending on tuyaha and not based on. I am running it now without the original files in the directory but installed sudo pip3 install tuyaha . An other benefit is that users can make issues/device support request and you can make a beta branch for developing. Others can clone and modify and make improvements. Think about it.

Greeting Xenomes
Sorry for the long delay, I haven't had a chance to do any work on this lately.
I did notice you went ahead and forked the project and added your changes -- everything looks good, so I will even recommend your fork for those that would like the extra features:
https://github.com/Xenomes/Domoticz-TUYA-Plugin
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 »

itguy78 wrote: Tuesday 06 October 2020 18:43 Sorry for the long delay, I haven't had a chance to do any work on this lately.
I did notice you went ahead and forked the project and added your changes -- everything looks good, so I will even recommend your fork for those that would like the extra features:
https://github.com/Xenomes/Domoticz-TUYA-Plugin
No problem, I opened the issue on the page to. So if you have suggesting please do and I hope you still make contributions to the plug-in.
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
DarkG
Posts: 89
Joined: Friday 15 September 2017 18:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10076
Location: Germany
Contact:

Re: Python Plugin: TUYA

Post by DarkG »

Can someone add climate to the plugin?

Code: Select all

Got devices
{   'header': {'code': 'SUCCESS', 'payloadVersion': 1},
    'payload': {   'devices': [   {   'data': {   'max_temper': 99,
                                                  'min_temper': 0,
                                                  'mode': 'hot',
                                                  'online': True,
                                                  'state': 'false',
                                                  'support_mode': [   'cold',
                                                                      'hot',
                                                                      'wind',
                                                                      'auto'],
                                                  'temp_unit': 'CELSIUS',
                                                  'temperature': 31},
                                      'dev_type': 'climate',
                                      'ha_type': 'climate',
RPi4 Shelly1 Shelly2.5 ESPEasy Tuya Domoticz Beta Dashticz 3.6
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,

For all Dutchies: Just bought some Calex lamps in Karwei. It also seems that Hema has introduced Tuya Lamps.
Pretty nice lamps if you ask me.

The Tuya-plugin seems to work pretty well. Except for two things:

1. I seem not to be able to import the scenes from the Tuya App. Do you guys have any clue how to fix this?
2. I'm trying to switch the color of the lamp (it is a white bulb / non-rgb). This seems not possible by using RGB functionality. Any clue how to change the color of the bulb in Domoticz?

Thanks in advance!
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: Sunday 01 November 2020 14:01 1. I seem not to be able to import the scenes from the Tuya App. Do you guys have any clue how to fix this?
Scenes are not included plugin, by running "debug discovery" scene, scene_1 to scene_4 are listed but for a proper function the speed is needed this is unfortunately missing.
Ruudhoevenaar wrote: Sunday 01 November 2020 14:01 2. I'm trying to switch the color of the lamp (it is a white bulb / non-rgb). This seems not possible by using RGB functionality.Any clue how to change the color of the bulb in Domoticz?
If it's a white bulb then only the brightness control will be available. can you post the outcome of 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
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 »

Thnx for your quick response!

Just to add on my post: the white bulb is a bulb which can also switch from cooler colors (blue-ish) to more warmer color (orange).

Also, I have no clue how to run "Debug Discovery".
Do I need to run a command or something?

Apologies for the noob-skills... ;)
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: Monday 02 November 2020 20:03 Just to add on my post: the white bulb is a bulb which can also switch from cooler colors (blue-ish) to more warmer color (orange).
That is also possible to use WWCW, witch version are you using?
What is the result of this:

Code: Select all

grep version ~/domoticz/plugins/Domoticz-TUYA-Plugin/plugin.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
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 »

I’m getting this in return (when I enter your suggested CLI)

<plugin key="tuya" name="TUYA" author="Wagner Oliveira" version="1.0.0" wikilink="http://www.domoticz.com/wiki/plugins/plugin.html" externallink="https://github.com/guino/Domoticz-TUYA">
# If Mode2 is not set (previous version didn't use it), set it
Post Reply

Who is online

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