Python Plugin: TUYA

Python and python framework

Moderator: leecollings

kalinkamaen
Posts: 52
Joined: Sunday 04 January 2015 15:57
Target OS: Windows
Domoticz version: 2022.2
Location: Norway
Contact:

Re: Python Plugin: TUYA

Post by kalinkamaen »

daveinhull wrote: Sunday 18 December 2022 8:27 Hi kalinkamaen,

Yes sorry I should have provided more detials, but wanted to see if I could find the problem myself. Here is the log, I've marked where it repeats, but I can't see anything unusal (except for the repeating of course :shock: :( )
Yeah that is strange. This is above my head. But If it was me I would start to dissable plugins one bye one and see if its a plugin problem.
I hope that someone else could help you with you problem.


Edit: Also suggested in another tread try do delete/clean cache in you browser.

Regards Kali
Windows 10, Domoticz 14784
Snarfdomoticz
Posts: 1
Joined: Saturday 14 December 2019 14:42
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by Snarfdomoticz »

Hello I have and Silvergear Smart plug with Energy monitor can see the smart plug and switch it in domoticz
but the energy measurement is not, is also a possibility for this
User avatar
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Snarfdomoticz wrote: Friday 13 January 2023 14:20 Hello I have and Silvergear Smart plug with Energy monitor can see the smart plug and switch it in domoticz
but the energy measurement is not, is also a possibility for this
In the Domoticz-TUYA-Plugin there is no energy data returning from tuya API v1 but the Domoticz-TinyTUYA-Plugin you can get energy data readouts.
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
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

daveinhull wrote: Sunday 18 December 2022 8:27 Hi kalinkamaen,

Yes sorry I should have provided more detials, but wanted to see if I could find the problem myself. Here is the log, I've marked where it repeats, but I can't see anything unusal (except for the repeating of course :shock: :( )
Did you enable debug in the plug in? There is not enough information in the log that i can help you.
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
HansLe
Posts: 25
Joined: Wednesday 13 January 2016 21:12
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.3530
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by HansLe »

TinyTuya plugin to get energy data readouts works great. See this post in the Dutch domoticz forum were I mentioned how to check it before you install it in Domoticz.

https://contactkring.nl/phpbb/viewtopic ... 0bcf#p4526

The text is in Dutch but wit Google Translate or Deepl.com it is easy translated ;)
Raspberry Pi B+ | Domoticz v3.4834 | RFXtrx433E | Action sockets and remote control (a cheap solution to start with)
Sonos device: control via Action remote control and EasySonos (via Domoticz scripts)
2 x Chresta TX320, Kaku sensoren, D-link camera
User avatar
rolandtwilt
Posts: 74
Joined: Monday 05 October 2020 18:55
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by rolandtwilt »

Xenomes wrote: Saturday 12 November 2022 15:22
rolandtwilt wrote: Saturday 12 November 2022 15:20 it works like a charm! thank you very much!
Perfect! Then i will push it to the main branch, thanks for reporting and testing!
Good morning, has something changed? I get a lot of error messages, via the Tuya app it works fine, but I don't Domoticz. After restarting Domoticz it works for a while and then error messages again, see log below;

2023-02-05 09:01:03.777 Error: tuya: Command for DeviceID=bf0a5da5baf87abfa7jtdd but device is not available.
2023-02-05 09:19:23.592 Error: tuya: handleThread: HTTPSConnectionPool(host='px1.tuyaeu.com', port=443): Max retries exceeded with url: /homeassistant/access.do?grant_type=refresh_token&refresh_token=EUheu163095134106254dqpcNUsR00ifv (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xa4d9d890>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')) line 215
2023-02-05 09:19:33.571 Error: tuya: handleThread: HTTPSConnectionPool(host='px1.tuyaeu.com', port=443): Max retries exceeded with url: /homeassistant/access.do?grant_type=refresh_token&refresh_token=EUheu163095134106254dqpcNUsR00ifv (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xa4d9d910>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')) line 215
2023-02-05 09:19:45.305 Error: tuya: handleThread: ('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer')) line 215

Please help :(
User avatar
heggink
Posts: 977
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by heggink »

Hey @Xenomes,
I noticed that there is a local API for HA. Have you considered adding that? It would allow controlling devices even if the internet connection is down...
Cheers,
Herman
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

heggink wrote: Wednesday 01 March 2023 10:22 Hey @Xenomes,
I noticed that there is a local API for HA. Have you considered adding that? It would allow controlling devices even if the internet connection is down...
Cheers,
Herman
Yes i know That is exist, also experimenting with it in the background with the other plugin.
I don't have a idea how to inplant the DP ID's to control devices switch 1 is easy on/off but the rest.
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
aldodemi
Posts: 25
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: TUYA

Post by aldodemi »

After upgrade to Ubuntu 23.04 error starting the plugin:
2023-05-04 09:59:21.873 Error: SmartLife: (tuya) failed to load 'plugin.py', Python Path used was '/home/domoticz/domoticz/plugins/tuyaha/:/usr/lib/python311.zip:/usr/lib/python3.11:/usr/lib/python3.11/lib-dynload:/usr/local/lib/python3.11/dist-packages:/usr/lib/python3/dist-packages:/usr/lib/python3.11/dist-packages'.
2023-05-04 09:59:21.881 Error: SmartLife: Traceback (most recent call last):
2023-05-04 09:59:21.881 Error: SmartLife: File "/home/domoticz/domoticz/plugins/tuyaha/plugin.py", line 65, in <module>
2023-05-04 09:59:21.881 Error: SmartLife: import tuyaha
2023-05-04 09:59:21.881 Error: SmartLife: ModuleNotFoundError: No module named 'tuyaha'

This is the only plugin that fails.
Path is: /home/domoticz/domoticz/plugins/tuyaha
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)
User avatar
waltervl
Posts: 5715
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by waltervl »

Support for Python 3.11 could be fixed in latest beta (but perhaps only for Windows). Are you running latest beta?

Edit. Else try to install the missing python module again, se the instructions on the plugin github repository.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
aldodemi
Posts: 25
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: TUYA

Post by aldodemi »

Yes, sorry, I'm on the last beta:
Info on Domoticz
Version: 2023.1 (build 15224)
Build Hash: 789a00d3b-modified
Compile Date: 2023-05-04 07:49:56
dzVents Version: 3.1.8
Python Version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]

domoticz@ns2server:~/domoticz/plugins/tuyaha$ pip3 install requests --break-system-package
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.28.1)
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)
User avatar
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

As mentioned by waltervl the module tuyaha is missing.

Code: Select all

2023-05-04 09:59:21.881 Error: SmartLife: ModuleNotFoundError: No module named 'tuyaha'
Domoticz runs under the root user in most cases the module need to be installed with sudo.
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
aldodemi
Posts: 25
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: TUYA

Post by aldodemi »

No way...

sudo pip3 install requests --break-system-package
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (2.28.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

:-(

please help....
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)
User avatar
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

You are missing the 'tuyaha' module.
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
aldodemi
Posts: 25
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: TUYA

Post by aldodemi »

'tuyaha' module was, and is, already installed...

domoticz@ns2server:~/domoticz/plugins/tuyaha$ pip3 install tuyaha --break-system-package
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: tuyaha in /usr/local/lib/python3.11/dist-packages (0.0.11)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from tuyaha) (2.28.1)

domoticz@ns2server:~/domoticz/plugins/tuyaha$ sudo pip3 install tuyaha --break-system-package
Requirement already satisfied: tuyaha in /usr/local/lib/python3.11/dist-packages (0.0.11)
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from tuyaha) (2.28.1)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)
User avatar
waltervl
Posts: 5715
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by waltervl »

tuyaha projct is not maintained anymore. https://github.com/PaulAnnekov/tuyaha
Does the tools\debug_discovery.py script working?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
aldodemi
Posts: 25
Joined: Tuesday 07 October 2014 17:43
Target OS: Linux
Domoticz version: 3.8275
Location: Genoa Italy
Contact:

Re: Python Plugin: TUYA

Post by aldodemi »

The debug_discovery.py script work without problem (but before Ubuntu upgrade all worked fine)
Server Domoticz 3.7243 (usually the last beta) on Debian Linux (Jessie) - Hw homemade with Atom CPU/4 GB RAM
RFXCom and ZWave Stick (Aeon)
User avatar
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

Work the debug_discovery.py with sudo?

Verstuurd vanaf mijn SM-A536B met Tapatalk

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
Xenomes
Posts: 396
Joined: Tuesday 27 November 2018 19:05
Target OS: Linux
Domoticz version: 2024.7
Location: Netherlands
Contact:

Re: Python Plugin: TUYA

Post by Xenomes »

aldodemi wrote: Friday 05 May 2023 13:43 The debug_discovery.py script work without problem (but before Ubuntu upgrade all worked fine)
Just installed Ubuntu 23.04
Installed the latest beta of Domoticz
Fixed start Domoticz with

Code: Select all

wget http://nz2.archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2.18_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2.18_amd64.deb
Cloned plugin and installed modules with

Code: Select all

sudo pip3 install tuyaha requests --break-system-packages

Code: Select all

 2023-05-06 17:57:48.810 Status: Domoticz V2023.1 (build 15230) (c)2012-2023 GizMoCuz
2023-05-06 17:57:48.813 Status: Build Hash: a0b31dfc5, Date: 2023-05-06 10:43:52
2023-05-06 17:57:48.813 Status: Startup Path: /home/pi/domoticz/
2023-05-06 17:57:48.851 Status: PluginSystem: Started, Python version '3.11.2', 2 plugin definitions loaded.
2023-05-06 17:57:48.855 Status: WebServer(HTTP) started on address: :: with port 8080
2023-05-06 17:57:48.859 Status: WebServer(SSL) startup failed on address :: with port: 443: bind: Permission denied, trying ::
2023-05-06 17:57:48.862 Status: WebServer(SSL) startup failed on address :: with port: 443: bind: Permission denied, trying 0.0.0.0
2023-05-06 17:57:48.864 Status: TCPServer: shared server started...
2023-05-06 17:57:48.866 Status: RxQueue: queue worker started...
2023-05-06 17:57:48.824 Error: Default admin password has NOT been changed! Change it asap!
2023-05-06 17:57:48.863 Error: WebServer(SSL) startup failed on address 0.0.0.0 with port: 443: bind: Permission denied
2023-05-06 17:57:48.863 Error: WebServer(SSL) check privileges for opening ports below 1024
2023-05-06 17:57:50.873 Tuya: Worker thread started.
2023-05-06 17:57:50.873 Status: Tuya: Started.
2023-05-06 17:57:50.873 Status: Tuya: Entering work loop.
2023-05-06 17:57:50.873 Status: NotificationSystem: thread started...
2023-05-06 17:57:50.874 Status: EventSystem: reset all events...
2023-05-06 17:57:50.875 Status: EventSystem: reset all device statuses...
2023-05-06 17:57:50.897 Status: Python EventSystem: Initializing event module.
2023-05-06 17:57:50.900 Status: EventSystem: Started
2023-05-06 17:57:50.900 Status: EventSystem: Queue thread started...
2023-05-06 17:57:51.129 Tuya: Waiting 60 seconds to connect TuyaApi login error timeout
2023-05-06 17:57:51.129 Tuya: Waiting 50 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:57:51.128 Status: Tuya: Initialized version 1.0.16, author 'Wagner Oliveira contributed Xenomes'
2023-05-06 17:57:51.343 Status: PluginSystem: 1 plugins started.
2023-05-06 17:58:01.136 Tuya: Waiting 40 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:58:11.138 Tuya: Waiting 30 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:58:21.168 Tuya: Waiting 20 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:58:31.207 Tuya: Waiting 10 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:58:41.214 Tuya: Waiting 0 seconds to connect TuyaApi (Tuya Plug-in)
2023-05-06 17:58:51.216 Tuya: TUYA plugin started
2023-05-06 17:58:51.216 Tuya: Debug logging mask set to: PYTHON CONNECTION
2023-05-06 17:58:51.216 Tuya: 'HardwareID':'2'
2023-05-06 17:58:51.216 Tuya: 'HomeFolder':'/home/pi/domoticz/plugins/Domoticz-TUYA-Plugin/'
2023-05-06 17:58:51.216 Tuya: 'StartupFolder':'/home/pi/domoticz/'
2023-05-06 17:58:51.216 Tuya: 'UserDataFolder':'/home/pi/domoticz/'
2023-05-06 17:58:51.216 Tuya: 'Database':'/home/pi/domoticz/domoticz.db'
2023-05-06 17:58:51.216 Tuya: 'Language':'en'
2023-05-06 17:58:51.216 Tuya: 'Version':'1.0.16'
2023-05-06 17:58:51.216 Tuya: 'Author':'Wagner Oliveira contributed Xenomes'
2023-05-06 17:58:51.216 Tuya: 'Name':'Tuya'
2023-05-06 17:58:51.216 Tuya: 'Port':'0'
2023-05-06 17:58:51.216 Tuya: 'Username':''
2023-05-06 17:58:51.216 Tuya: 'Password':''
2023-05-06 17:58:51.216 Tuya: 'Key':'tuya'
2023-05-06 17:58:51.216 Tuya: 'Mode1':'31'
2023-05-06 17:58:51.216 Tuya: 'Mode2':'smart_life'
2023-05-06 17:58:51.216 Tuya: 'Mode6':'18'
2023-05-06 17:58:51.216 Tuya: 'DomoticzVersion':'2023.1 (build 15230)'
2023-05-06 17:58:51.216 Tuya: 'DomoticzHash':'a0b31dfc5'
2023-05-06 17:58:51.216 Tuya: 'DomoticzBuildTime':'2023-05-06 10:43:52'
2023-05-06 17:58:51.216 Tuya: Device count: 2
2023-05-06 17:58:51.217 Tuya: Device: 1 - ID: 1, Name: 'Tuya - 3D Lamp', nValue: 0, sValue: 'Off'
2023-05-06 17:58:51.217 Tuya: Device ID: '1'
2023-05-06 17:58:51.217 Tuya: Device Name: 'Tuya - 3D Lamp'
2023-05-06 17:58:51.217 Tuya: Device nValue: 0
2023-05-06 17:58:51.217 Tuya: Device sValue: 'Off'
2023-05-06 17:58:51.217 Tuya: Device LastLevel: 0
2023-05-06 17:58:51.218 Tuya: in handlethread
2023-05-06 17:58:51.323 Tuya: onHeartbeat called time=1683395931.3230166
2023-05-06 17:58:51.323 Tuya: in handlethread
2023-05-06 17:58:51.323 Tuya: Device count: 1 
Conclusion is the the plugin works under python 3.11
The problem you have is a misconfiguration of your system.
Check if you pip3 is using the correct python version.
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
ricorico94
Posts: 94
Joined: Monday 26 October 2015 10:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by ricorico94 »

Hi,

I've been using the great pugin for long time now, with several switches devices : great job and thanks a lot !

I've just added through my android App Smart Life a new device, an "irrigation device" "ie this : https://fr.aliexpress.com/item/10050050 ... pt=glo2fra
It seems working well when using the android app.
However, when I stop/start the plugin in domoticz, it doesn't see that device. If I use the debug_discovery.py script, I can also see my other switching devices, but not that one.
Any idea of what I can try to get it listed and working ? (in practice the oly thing I'd like to do through Domoticz is to switch it on/off, like standard electric switches..)

br,
Ricorico94
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest