[REQUEST] Plugin for Tuya

Python and python framework

Moderator: leecollings

Post Reply
frenchyyii
Posts: 53
Joined: Saturday 24 September 2016 18:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by frenchyyii »

Sorry for my "non replying" but I do not receive notifications for a long time, I f needed I may help/test .
I'll try to look at this post more often now .

Désolé pour ma "non réponse" je ne recois aucune notif du forum depuis quelques temps.... :cry:
S'il faut faire des tests ou aider j'essaierai de passer plus régulièrement
User avatar
dinamitemic
Posts: 5
Joined: Thursday 11 October 2018 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by dinamitemic »

tixi7 wrote: Saturday 13 October 2018 16:21 Can you provide more details:
- the plugin: plug or bulb?
- the version of the plugin, since the post I patch the bulb plugin to avoid a similar behavior
- some logs information
- device informations,

Can you try with the latest stable version of domoticz? I observe that some beta version causes problems: a bug report for domoticz is on my todo list.
Hi tixi7! Sorry for the very late reply. It was a stupid mistake with the wifi net that I was using.
Maybe you can check if it is possible that if you try to add a switch that is offline it create some strange behaviour and make domoticz crash.
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

Hi all,

I just push a new version on github (master branch) for the smartplug plugin.
Now the plugin support single and multi socket devices.

For single socket plug, you have to provide the IP, devID and local key (do not change the default value of other parameters)

For multi socket devices, you have to provide the same information and at least the DPS parameter.
It is now possible to create switches that group multiple sockets with DPS group parameter.
You can also specify sockets to be always on (like usb) with DPS always ON parameter.

As usual bug reports and suggestion are welcome.
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

jslegers, for sure the plugin is not define for it and i don't know if the library can get it or not. Can you send me the result of the script get_dps.py.

Hi sorry for my late reaction but i had some issues with my domoticz that I had to take care of first.
I have installed the plug-in and tried the get_dps.py script. But I only get an error :

Code: Select all

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin $ ./get_dps.py 192.168.1.126 00621010cc50e3c3d408
A problem occur please retry...
I have found the device ID under the Device Information of the Smart Life app on an iPhone. I don't know if the DevID is correct. I found this under Virtual ID in the app.

What else can I do to get the right info for you ?
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

Can you try to extract the devID with this method:
https://github.com/codetheweb/tuyapi/bl ... s/SETUP.md

To be sure you have the correct information.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: [REQUEST] Plugin for Tuya

Post by freijn »

I have found its a little easier on an Iphone than Android to configure. Although it should be same in basics.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

I've been able to use this plugin for the following products:
http://www.aihomestyle.com/content/151.html
http://www.aihomestyle.com/content/147.html

and

http://www.aihomestyle.com/content/170.html

However, for the dimmer, I need to use the Tuya SmartBulb, which shows also a switch with RGB.

It is not RGB, is just a dimmer.

I'm wondering if i can modify the SmartBulb-Plugin, to avoid showing the RGB thing, and instead allowing just dimming/on/off ?

I'm not a programmer, but looking into the code I see this:
Domoticz.Device(Name="Tuya SmartBulb", Unit=1, Type=241, Subtype=2, Switchtype=7).Create()

I'm guessing that the type/subtype/switchtype paremeters can make it?

Any hint ?

Thanks !
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

Responding to myself.

I edited the line:
Domoticz.Device(Name="Tuya SmartBulb", Unit=1, Type=241, Subtype=2, Switchtype=7).Create()

to be

Domoticz.Device(Name="Tuya SmartBulb", Unit=1, Type=241, Subtype=3, Switchtype=7).Create()

It works. There is only one issue that I'm not sure (because I don't have any other dimmer to test).

When I move the dimmer bar, it gets the right bright. If I click to "switch off", it switch off, but the bulb picture still shows "orange" as it was on. If I click to switch on, it happens the reverse.

I'm guessing something is needed to make this to be properly updated on the status of the dimmer ?

I'm happy to test for the developers if anything is needed.

Thanks!
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

One more issue I just discovered, with the dimmer.

Because I've also the Alexa skill for those devices, when Domoticz has done some action with those devices, seems that Alexa is not working with them, unless I shutdown Domoticz.

I think it will be necessary to make sure that after a few seconds, Domoticz "disconnects" from the device IP, and only connects from time to time to know the "status".

I think the problem is the same for the switch (need more testing). So the smartplug code needs also some modification to work correctly with the switch ...
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

Thanks, but it is not a bug.

Unfortunately this is mandatory to not disconnect the connection between the device and the plugin to avoid unexpected behavior for some tuya devices.
You can have a look at this thread: https://github.com/codetheweb/tuyapi/issues/84

Moreover, have in mind that only one connection is possible. That's why it is not possible to have the tuya app running and the domoticz plugin. And the same for Alexa. A way to handle it is to use Alexa with domoticz.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

I guessed so, but with the smart plug and the switch module, I don't have this problem, so I don't really understand why is happening only with the dimmer module.

Also, as indicated in the previous message, it looks like the Domoticz dimmer bar and "bulb status" is not updated. I'm not sure if this is the way it should work with a dimmer (non-RGB), I don't have any other dimmer to test. However the RGB dimmer (I'm using it with the Xiaomi hub) doesn't have that issue.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

tixi7 wrote: Sunday 30 December 2018 19:52 Thanks, but it is not a bug.

Unfortunately this is mandatory to not disconnect the connection between the device and the plugin to avoid unexpected behavior for some tuya devices.
You can have a look at this thread: https://github.com/codetheweb/tuyapi/issues/84

Moreover, have in mind that only one connection is possible. That's why it is not possible to have the tuya app running and the domoticz plugin. And the same for Alexa. A way to handle it is to use Alexa with domoticz.
I've read all this thread. It mention something related to the firmware version. In my case both MCU & Wifi firmware are always the same, as follows:
- Smart Plug: 1.0.0 - it works both with Alexa and Domoticz, no issues after several hours testing
- Switch module: 1.0.3 - same as above, no issues at all
- Dimmer module: 1.0.0 - it work fine with Alexa or Domoticz, but not with both.

So I really wonder if the persistent socket is needed, if both the smart plug and the switch module are working fine.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

jordipalet wrote: Sunday 30 December 2018 20:33
tixi7 wrote: Sunday 30 December 2018 19:52 Thanks, but it is not a bug.

Unfortunately this is mandatory to not disconnect the connection between the device and the plugin to avoid unexpected behavior for some tuya devices.
You can have a look at this thread: https://github.com/codetheweb/tuyapi/issues/84

Moreover, have in mind that only one connection is possible. That's why it is not possible to have the tuya app running and the domoticz plugin. And the same for Alexa. A way to handle it is to use Alexa with domoticz.
I've read all this thread. It mention something related to the firmware version. In my case both MCU & Wifi firmware are always the same, as follows:
- Smart Plug: 1.0.0 - it works both with Alexa and Domoticz, no issues after several hours testing
- Switch module: 1.0.3 - same as above, no issues at all
- Dimmer module: 1.0.0 - it work fine with Alexa or Domoticz, but not with both.

So I really wonder if the persistent socket is needed, if both the smart plug and the switch module are working fine.
I've compared the code for the Tuya-SmartBulb plugin.py and the SmartPlug. It looks to me the Bulb one is not updated. I wonder if when the persistent socket issue was discovered, the SmartBulb code was also updated?

I know they are different, the SmartBulb handles RGB and dimming, but I think most of the code is probably very similar.

Again, I'm not a programmer (I programmed many years ago, but not recently), so I may be missing something, but wonder why the plug and switch work well and not the dimmer.

Thanks!
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

I read your post too quickly...

The bulb plugin also is using a persistent socket but it's true i worked more one the plug one since i added multisocket. Coding a new version of the bulb plugin is a good idea but for now i do not have enough spare time.

For the status of the dimmer, i do not know the impact of your code modification maybe it is related.

Can you send me the dps info of your dimmer?

Can you also try to use the plug plugin for your dimmer? If i got it correctly you just want to turn it on/off and it should work. Let me know if it works and if the problem with alexia persist or not.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

Not sure what is the DPS and how to get it.

I want the dimmer to be able to dim as well ... that's why I can't use the smartplug one (it works, but doesn't allow dimming).

This is the change I did in the bulb code for the dimmer to work (without colors, as it is not RGB, just dimmer):

it was:

Domoticz.Device(Name="Tuya SmartBulb", Unit=1, Type=241, Subtype=2, Switchtype=7).Create()


Now is:

Domoticz.Device(Name="Tuya SmartBulb", Unit=1, Type=244, Subtype=62, Switchtype=7).Create()

Thanks!
tixi7
Posts: 52
Joined: Monday 10 September 2018 23:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tixi7 »

jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

The dimmer shows (half dimmed):

Plug State Information:
{'dps': {'3': 140, '1': True}, 'devId': '07870772807d3a6d7959'}

Plug DPS List:
1

the value 140 becomes 255 if full dimmed, etc.

The switch (which is working configured as "plug", just for you info) is:
Plug State Information:
{'dps': {'7': 0, '1': True}, 'devId': '01058254cc50e32f746b'}

Plug DPS List:
1

(true becomes false when poweroff)

And just to confirm the smartplug shows (powered on):
Plug State Information:
{'dps': {'2': 0, '1': True}, 'devId': '4440225184f3eb0a9e9a'}

Plug DPS List:
1

Not sure what are the "dps" values, first one seems to be a "device type", then dimming value if supported, and then the status. Sure you know very well that.

Thanks !
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

tixi7 wrote: Thursday 20 December 2018 21:05 Can you try to extract the devID with this method:
https://github.com/codetheweb/tuyapi/bl ... s/SETUP.md

To be sure you have the correct information.
I have followed the steps but the app gives an network error when trying to refresh the devices.
Sorry that I can't help you with it.
jordipalet
Posts: 12
Joined: Sunday 09 December 2018 10:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jordipalet »

It worked for me, so you're probably missing some step or some required software is not properly installed?
jslegers
Posts: 34
Joined: Tuesday 23 February 2016 9:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: NL
Contact:

Re: [REQUEST] Plugin for Tuya

Post by jslegers »

I will test it on an other pi. So that I won't mess up my production pi.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests