Python Plugin: TUYA

Python and python framework

Moderator: leecollings

cache
Posts: 2
Joined: Thursday 17 March 2022 22:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by cache »

adelafug wrote: Wednesday 01 September 2021 19:28 Hello


I install plugin tuyaha and configure params. But when plugin call skill api i no receibe my devices. I used Tuya Smart with iphone.. And i have 1 device registred ( sensor door ).

I test api with Postman y receive the same response..

https://px1.tuyaeu.com/homeassistant/sk ... dVersion=1
BodY: {'header': {'name': 'Discovery', 'namespace': 'discovery', 'payloadVersion': 1}, 'payload': {'accessToken': 'EUheu16305128439555U07k8PoLsNpHsU'}}

Response.

{"payload":{"devices":[],"scenes":[]},"header":{"code":"SUCCESS","payloadVersion":1}}



Any idea?

Thanks.
Anyone managed to get it working? Same situation here but with a RGBW LED stripe.

Local connection is not implemented nor will it? Always using tuya cloud services?
cache
Posts: 2
Joined: Thursday 17 March 2022 22:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by cache »

cache wrote: Thursday 17 March 2022 23:02
adelafug wrote: Wednesday 01 September 2021 19:28 Hello


I install plugin tuyaha and configure params. But when plugin call skill api i no receibe my devices. I used Tuya Smart with iphone.. And i have 1 device registred ( sensor door ).

I test api with Postman y receive the same response..

https://px1.tuyaeu.com/homeassistant/sk ... dVersion=1
BodY: {'header': {'name': 'Discovery', 'namespace': 'discovery', 'payloadVersion': 1}, 'payload': {'accessToken': 'EUheu16305128439555U07k8PoLsNpHsU'}}

Response.

{"payload":{"devices":[],"scenes":[]},"header":{"code":"SUCCESS","payloadVersion":1}}



Any idea?

Thanks.
Anyone managed to get it working? Same situation here but with a RGBW LED stripe.

Local connection is not implemented nor will it? Always using tuya cloud services?
OK I got it working. Anyone facing the same issue: dont use tuyaha but tinytuya. Works like a charme in pure local mode. No cloud required. Could even implement the music mode provided by the LED stripe
manjh
Posts: 748
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 »

cache wrote: Saturday 19 March 2022 18:03
OK I got it working. Anyone facing the same issue: dont use tuyaha but tinytuya. Works like a charme in pure local mode. No cloud required. Could even implement the music mode provided by the LED stripe
How does thie TinyTuya interface with Domoticz?
Hans
manjh
Posts: 748
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 »

cache wrote: Saturday 19 March 2022 18:03 OK I got it working. Anyone facing the same issue: dont use tuyaha but tinytuya. Works like a charme in pure local mode. No cloud required. Could even implement the music mode provided by the LED stripe
Can you provide a pointer to TinyTuya? How to install, and how to interface to Domoticz?
Hans
cobra045
Posts: 46
Joined: Friday 12 February 2016 20:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Contact:

Re: Python Plugin: TUYA

Post by cobra045 »

Yes, a step-by-step plan, that would be great.

I think many Domoticz users will thank you
manjh
Posts: 748
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 »

cobra045 wrote: Saturday 14 May 2022 20:43 Yes, a step-by-step plan, that would be great.

I think many Domoticz users will thank you
I found some instructions online, but it is not as simple as the usual plugin install. You need to create a developer account with Tuya, to start with. The steps are not simple. I think I will stick to the plugin for now.

Edit: I decided to give it another try, and it turns out to be much more straightforward. I now have a full list of devices, along with their properties.
Hans
arjan93
Posts: 25
Joined: Friday 16 November 2018 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by arjan93 »

Hii all,

Since a couple of days I have problems with my Tuya plugin on domoticz. Normaly I only use led bulbs from Tuya
in my house but since a couple of days I`ve add a Tuya wall switch to my system. From that moment I saw that
it takes a while before the status of the devices has been updated. For lights it not a big deal, but for a switch
it`s important that the status is updated directly.

Is this a know issue or did I something wrong in the set-up?

I`m using Domoticz version 2022.1 on a Raspberry Pi 4 with OS Raspbian GNU/Linux 10 (buster)
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 »

arjan93 wrote: Wednesday 01 June 2022 20:59 Hii all,

Since a couple of days I have problems with my Tuya plugin on domoticz. Normaly I only use led bulbs from Tuya
in my house but since a couple of days I`ve add a Tuya wall switch to my system. From that moment I saw that
it takes a while before the status of the devices has been updated. For lights it not a big deal, but for a switch
it`s important that the status is updated directly.

Is this a know issue or did I something wrong in the set-up?

I`m using Domoticz version 2022.1 on a Raspberry Pi 4 with OS Raspbian GNU/Linux 10 (buster)
The APIv1 doesn't allow to read a status two times in a minute.

Maybe this is a solution for you, Tuya as local device with MQTT.
Spoiler: show
EXPERIMENTAL only On/Off for devices is working!! But status changes will be almost instant in Domoticz.

Eclipse Mosquitto is required as a service.
Install tuya-mqtt and setup as mentioned in the description.
To extract the ID and Key, see link.

To run tuya-mqtt as a service
sudo nano /etc/systemd/system/tuya-mqtt.service

Code: Select all

[Unit]
Description=tuya-mqtt
After=mosquitto.target

[Service]
ExecStart=/usr/bin/node /opt/tuya-mqtt/tuya-mqtt.js
WorkingDirectory=/opt/tuya-mqtt
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi
Group=pi

[Install]
WantedBy=multi-user.target
sudo systemctl enable tuya-mqtt.service
sudo systemctl start tuya-mqtt.service

Setup 'MQTT Discovery' in Domoticz, give the same 'topic' as in the config.conf file.
Enable new device detection and hit update in the plugin setting of 'MQTT Discovery' and your devices in the devices.conf file will be detected.

Debug:
cd /opt/tuya-mqtt
DEBUG=tuya-mqtt:* node tuya-mqtt.js

http://mqtt-explorer.com/
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
luk085
Posts: 1
Joined: Wednesday 13 July 2022 11:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by luk085 »

Hi,
I have problem with login timeouts to API.

Code: Select all

 2022-07-13 11:12:58.212 Status: Klimatyzacja: Started.
2022-07-13 11:12:59.688 Klimatyzacja: Waiting 60 seconds to connect TuyaApi login error timeout
2022-07-13 11:12:59.689 Klimatyzacja: Waiting 50 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:12:59.684 Status: Klimatyzacja: Initialized version 1.0.13, author 'Wagner Oliveira contributed Xenomes'
2022-07-13 11:13:09.699 Klimatyzacja: Waiting 40 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:13:19.706 Klimatyzacja: Waiting 30 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:13:29.707 Klimatyzacja: Waiting 20 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:13:39.708 Klimatyzacja: Waiting 10 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:13:49.710 Klimatyzacja: Waiting 0 seconds to connect TuyaApi (Tuya Plug-in)
2022-07-13 11:13:59.711 Klimatyzacja: TUYA plugin started
2022-07-13 11:13:59.273 Error: Klimatyzacja hardware (3) thread seems to have ended unexpectedly
2022-07-13 11:14:01.841 Error: Domoticz(pid:12839, tid:13109('Klimatyzacja')) received fatal signal 11 (Segmentation fault)
2022-07-13 11:14:01.841 Error: siginfo address=0x3227, address=(nil) 
debug_discovery.py script passes succesfully, I see my device and id.
What can I do now?
verysingh45
Posts: 1
Joined: Wednesday 13 July 2022 13:09
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by verysingh45 »

I have made the changes that allow the plugin to be configured for SmartLife or Jinvoo Smart app (as well as Tuya). Simply select the app from the drop down in the hardware settings (Options are: Tuya, Smart Life or Jinvoo Smart) and it should automatically detect the devices from the app in question. The link on the original post has been updated with the latest version of the plugin.

19216811.bid
panorama charter com
Last edited by verysingh45 on Friday 22 July 2022 9:08, edited 1 time in total.
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 »

cobra045 wrote: Saturday 14 May 2022 20:43 Yes, a step-by-step plan, that would be great.

I think many Domoticz users will thank you
That would be great! +1
lamama1234
Posts: 14
Joined: Tuesday 17 October 2017 9:02
Target OS: Windows
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by lamama1234 »

EDIT: Solved after installing Xenomes' Domoticz-TUYA-Plugin.


Hi and many thanks for this plugin.

I've just added it to my Domoticz server and getting an error within my log, see below. I have 2 devices added to my Smart Life app, and one of them is intentionally offline. Could that be the issue? The online device is working ok from within Domoticz.

Thanks

Code: Select all

Error: (Tuya Smartlife) handleThread: ('Connection aborted.', TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None)) line 185
Last edited by lamama1234 on Friday 05 August 2022 13:44, edited 1 time in total.
lamama1234
Posts: 14
Joined: Tuesday 17 October 2017 9:02
Target OS: Windows
Domoticz version:
Contact:

Re: Python Plugin: TUYA

Post by lamama1234 »

manjh wrote: Wednesday 13 October 2021 8:35
But also:

Code: Select all

2021-10-13 08:30:48.671 Error: Bluetooth beacon hardware (20) thread seems to have ended unexpectedly
2021-10-13 08:30:48.671 Error: Xiaomi flowermate hardware (21) thread seems to have ended unexpectedly
2021-10-13 08:30:48.671 Error: Tuya_devices hardware (22) thread seems to have ended unexpectedly
Hi manjh. Were you able to solve those plugins failures? I'm also getting the same log errors for my other plugins after installing Xenomes' Domoticz-TUYA-Plugin.

tnx
Sarcas
Posts: 86
Joined: Wednesday 11 October 2017 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1ß
Location: Friesland
Contact:

Re: Python Plugin: TUYA

Post by Sarcas »

Hi there,

I recently bought my first Tuya-driven product and I am trying to integrate it in Domoticz. It doesnt use the Tuya, Smart or Jinvoo app though, but they have their own app ('create'). I tried my login credentials with every setting anyway, but no luck.

Code: Select all

 2022-08-09 15:39:39.353 Error: TUYA: handleThread: Get accesstoken failed. Username or password error! line 207 
Any suggestions?

Thanks!

S.
--

Domoticz on rPi4 - RFXCOM RFXtrx433 USB - ZW090 Z-Stick Gen5 EU - IKEA Tradfri - Philips HUE - YouLess meter - SolarEdge
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 »

Sarcas wrote: Wednesday 10 August 2022 10:14 I recently bought my first Tuya-driven product and I am trying to integrate it in Domoticz.
The chance that this device will work with the old API is very very small.
Sarcas wrote: Wednesday 10 August 2022 10:14 It doesnt use the Tuya, Smart or Jinvoo app though, but they have their own app ('create'). I tried my login credentials with every setting anyway, but no luck.

Code: Select all

 2022-08-09 15:39:39.353 Error: TUYA: handleThread: Get accesstoken failed. Username or password error! line 207 
Normally you can pair a Tuya device in one of the three mentioned apps, you need a new account for the different apps. The Custom App is properly a rebranded Tuya app.
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
waltervl
Posts: 5846
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python Plugin: TUYA

Post by waltervl »

Sarcas wrote: Wednesday 10 August 2022 10:14 Hi there,

I recently bought my first Tuya-driven product and I am trying to integrate it in Domoticz. It doesnt use the Tuya, Smart or Jinvoo app though, but they have their own app ('create'). I tried my login credentials with every setting anyway, but no luck.

Code: Select all

 2022-08-09 15:39:39.353 Error: TUYA: handleThread: Get accesstoken failed. Username or password error! line 207 
Any suggestions?

Thanks!

S.
Solved by a workaround through RFXCOM
Sarcas wrote: Sunday 14 August 2022 14:53 After discovering that my ceiling fan with TUYA can't be added to Domoticz, I accidentally stumbled upon this post. Tried my remote and I'll be damned! My 433 picks it up :D
Thanks for posting!
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
dgilbert2
Posts: 95
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: UK
Contact:

Re: Python Plugin: TUYA

Post by dgilbert2 »

itguy78 wrote: Wednesday 15 July 2020 19:51
DarkG wrote: Tuesday 14 July 2020 22:06 Is there a way to change temperature for my AC? I can only turn on and off.
.... The API has functions to read and set the 'target' temperature and to read the 'current' temperature, but I have no way to test these features. Someone with access to the device should be able to add in a new device that displays current temperature and allows changing the target temperature. Only way I could work on this is if you sent me your app account information (private message) so I could configure it and add it to the plugin -- obviously you'd have to not mind me messing with the settings for development.....
Has it been determined if it is possible to read temperature values into Domoticz using this plugin? My setup works fine with on/off devices but I could do with adding a thermometer into Smartlife also.

Thanks
dgilbert2
Posts: 95
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: UK
Contact:

Re: Python Plugin: TUYA

Post by dgilbert2 »

I'm trying to get the TUYA plugin to read the Thermometer below and show the "current_temperature" in Domoticz;

Code: Select all

                                    {   'data': {   'current_temperature': 206,
                                                  'max_temper': 700,
                                                  'min_temper': 150,
                                                  'online': True,
                                                  'state': 'true',
                                                  'temperature': 155},
                                      'dev_type': 'climate',
                                      'ha_type': 'climate',
                                      'icon': 'https://images.tuyaeu.com/smart/program_category_icon/wk.png',
                                      'id': 'bf98439ce4381bxxxxxxx',
                                      'name': 'Smart Controller'},
 
So far I've added the lines below which have now made the Thermometer appear in Domoticz Devices:

Code: Select all

   elif dev_type == "climate":
                        Domoticz.Device(Name=dev.name(), Unit=unit, Type=244, Subtype=73, Switchtype=0, Image=16, DeviceID=dev.object_id()).Create()
                        if dev.data.get("current_temperature") is not None:
                            unit = nextUnit()
                            Domoticz.Device(Name=dev.name(), Unit=unit, Type=80, Subtype=5, Switchtype=0, DeviceID=dev.object_id()).Create()   
                         
But now I'm stuck, as the "current_temperature" value is not being passed, or updated, in Domoticz, ie, it just displays 0.0.
Any ideas on the lines I need to add/change to read over the "current_temperature" value into Domoticz?
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 »

dgilbert2 wrote: Friday 23 September 2022 22:25 I'm trying to get the TUYA plugin to read the Thermometer below and show the "current_temperature" in Domoticz;

CODE

So far I've added the lines below which have now made the Thermometer appear in Domoticz Devices:

CODE

But now I'm stuck, as the "current_temperature" value is not being passed, or updated, in Domoticz, ie, it just displays 0.0.
Any ideas on the lines I need to add/change to read over the "current_temperature" value into Domoticz?
Hi, That part of the plugin not complete, I don't have a tuya temp device so i was depended for data from a other user witch stopped replaying. For updating you need to add code below here:

Code: Select all

                # Update device
                if dev.state() == False:
                    UpdateDevice(unit, 0, 'Off', not dev.available())
                elif dev.state() == True:
                    UpdateDevice(unit, 1, 'On', not dev.available())
                else:
                    Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' State update skiped. status = '+str(dev.state()))

                #if dev.device_type() == 'cover' and dev.state() != 'Stop':
                #    UpdateDevice(unit, 1, 'Stop', not dev.available())

                if dev.state() == True and not dev.available():
                    UpdateDevice(unit, 0, 'Off', not dev.available())
                    Domoticz.Log('DeviceID='+Devices[unit].DeviceID+' Turned off because device is offline.')
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
dgilbert2
Posts: 95
Joined: Wednesday 16 August 2017 8:08
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: UK
Contact:

Re: Python Plugin: TUYA

Post by dgilbert2 »

Xenomes wrote: Saturday 24 September 2022 16:32 Hi, That part of the plugin not complete, I don't have a tuya temp device so i was depended for data from a other user witch stopped replaying. For updating you need to add code below here:
Thank you for your reply. I am making some progress and will post back where I end up. Coding is not my strong point so takes a little time ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest