[REQUEST] Plugin for Tuya

Python and python framework

Moderator: leecollings

tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

I'm trying to configure a teckin sp22 plug but I get this message:

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin $ ./get_dps.py 192.168.0.171 60417563840d8e68fe98
Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug State Information:
b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug DPS List:
Traceback (most recent call last):
File "./get_dps.py", line 58, in <module>
for key in data['dps'].keys():
TypeError: byte indices must be integers or slices, not str



I've got some more configured(not this model) and not had had any problems

Any suggest ?
pipiche
Posts: 1977
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: France
Contact:

Re: [REQUEST] Plugin for Tuya

Post by pipiche »

My understanding is that the tuya devices ( sensors ) or zigbee compliant and have been tested on Zigate.
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices

If the plugin provides you value, you can support me with a donation Paypal.

Wiki is available here.

Zigbee for Domoticz FAQ
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

No, these are not zigbee.
It seems as the output was different from what it expected.
pipiche
Posts: 1977
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: France
Contact:

Re: [REQUEST] Plugin for Tuya

Post by pipiche »

tete wrote:No, these are not zigbee.
It seems as the output was different from what it expected.
Indeed , you are right plug and bulb are not zigbee


Envoyé de mon iPhone en utilisant Tapatalk
Zigbee for Domoticz plugin / RPI3B+ / Electrolama ZZH-P / 45 devices

If the plugin provides you value, you can support me with a donation Paypal.

Wiki is available here.

Zigbee for Domoticz FAQ
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

And some more time later ...

I've solved the mistery.

I was working with pytuya 7.0.3, but now I've seen that there is a 7.0.4 that includes support for 3.3 protocol while the previous one was just for 3.1.

Now, using that pytuya and adding a device.set_version(3.3) in the get_dps.py just before the device.status call it seems to work fine
Spoiler: show
Plug State Information:
{'devId': 'xxxxxxxxxxxxxxxxxx', 'dps': {'2': False, '25': 1300, '21': 1, '10': 0, '20': 2327, '24': 16000, '23': 28250, '1': False, '9': 0, '19': 0, '22': 602, '18': 0}}

Plug DPS List:
2;1
Now I have modified my copy of tixi_sincze plugin to set the protocol of my devices to 3.3.

Now I'll try the plugin, but the right solution would be to include this option as a parameter in Domoticz.

merlot wrote: Sunday 16 June 2019 10:51 Simw time later ...

I have returned the previous smart plug and I've bought a new one, a double one for 16A.

And I'm having the same problems :(

So, let's start form the begining.

Is a packet like the one below correct to get the devId and localkey?

Is this a packet that belongs to a tuya device that can be used by this plugin?

Thank you very much indeed
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: [REQUEST] Plugin for Tuya

Post by sincze »

merlot wrote: Sunday 04 August 2019 16:29 And some more time later ...

I've solved the mistery.

I was working with pytuya 7.0.3, but now I've seen that there is a 7.0.4 that includes support for 3.3 protocol while the previous one was just for 3.1.

Now, using that pytuya and adding a device.set_version(3.3) in the get_dps.py just before the device.status call it seems to work fine
Spoiler: show
Plug State Information:
{'devId': 'xxxxxxxxxxxxxxxxxx', 'dps': {'2': False, '25': 1300, '21': 1, '10': 0, '20': 2327, '24': 16000, '23': 28250, '1': False, '9': 0, '19': 0, '22': 602, '18': 0}}

Plug DPS List:
2;1
Now I have modified my copy of tixi_sincze plugin to set the protocol of my devices to 3.3.

Now I'll try the plugin, but the right solution would be to include this option as a parameter in Domoticz.
We could look into that integration indeed with a dropdown box 3.1 / 3.3 for now ?
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

sincze wrote: Sunday 04 August 2019 17:05

We could look into that integration indeed with a dropdown box 3.1 / 3.3 for now ?
Will you do? Or are you asking me to do it? I can try, but I'm a newbie in git and I'm not sure how to contribute.

Anyway, after solving this issue, now, with the tixi_sincze plugin, after adding a dual plug, I get this error
Spoiler: show
2019-08-04 22:49:13.262 Status: (Endoll Garatge) Entering work loop.
2019-08-04 22:49:13.262 Status: (Endoll Garatge) Initialized version 1.0.0, author 'tixi_sincze'
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:2) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:3) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:4) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:5) already exists in Domoticz.
I have set DPS=1;2 and ID Amp;Watt;Volt =18;19;20 (I've got the ID's from Packet capture)

And in devices, this is what I get

Image

2 Usage in W, the Voltage =0 (although get_dps_py returns 2325 for the ID=20) and not the second switch

have I configured something wrong in the parameters?

Thank you
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

tete wrote: Sunday 28 July 2019 19:30 I'm trying to configure a teckin sp22 plug but I get this message:

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin $ ./get_dps.py 192.168.0.171 60417563840d8e68fe98
Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug State Information:
b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug DPS List:
Traceback (most recent call last):
File "./get_dps.py", line 58, in <module>
for key in data['dps'].keys():
TypeError: byte indices must be integers or slices, not str



I've got some more configured(not this model) and not had had any problems

Any suggest ?
payload=b'3.3 indicates your device is using protocol 3.3. So, which version of pytuya are you using? You need 7.0.4
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

merlot wrote: Sunday 04 August 2019 23:15
sincze wrote: Sunday 04 August 2019 17:05

We could look into that integration indeed with a dropdown box 3.1 / 3.3 for now ?
Will you do? Or are you asking me to do it? I can try, but I'm a newbie in git and I'm not sure how to contribute.

Anyway, after solving this issue, now, with the tixi_sincze plugin, after adding a dual plug, I get this error
Spoiler: show
2019-08-04 22:49:13.262 Status: (Endoll Garatge) Entering work loop.
2019-08-04 22:49:13.262 Status: (Endoll Garatge) Initialized version 1.0.0, author 'tixi_sincze'
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:2) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:3) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:4) already exists in Domoticz.
2019-08-04 22:49:13.270 Error: (Endoll Garatge) Device creation failed, Hardware/Unit combination (5:5) already exists in Domoticz.
I have set DPS=1;2 and ID Amp;Watt;Volt =18;19;20 (I've got the ID's from Packet capture)

And in devices, this is what I get

Image

2 Usage in W, the Voltage =0 (although get_dps_py returns 2325 for the ID=20) and not the second switch

have I configured something wrong in the parameters?

Thank you
I answer myself. The problem for a dual socket plug is in this code
Spoiler: show
for val in self.__unit2dps_id_list:

if(val <= max_dps): #single socket dps
Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create()
Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create()
Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create()
Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create()
Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create()
Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.")
If in the dps_ide_list I have 1 and 2, as it's my case, in the first loop it tries to create Unit 1 to 5, and in the second one 2 to 6.

It should be something like this
Spoiler: show
for val in self.__unit2dps_id_list:

if(val <= max_dps): #single socket dps
Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create()
Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.")
if(val == max_dps):
Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create()
Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create()
Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create()
Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create()
Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.")
I think that the else statment for the group should also be corrected, but I'm setting to None, so I don't mind

Thank you
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

merlot wrote: Sunday 04 August 2019 23:17
tete wrote: Sunday 28 July 2019 19:30 I'm trying to configure a teckin sp22 plug but I get this message:

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin $ ./get_dps.py 192.168.0.171 60417563840d8e68fe98
Unexpected status() payload=b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug State Information:
b'3.3\x00\x00\x00\x00\x00\x00\x9d\xa4\x00\x00\x00\x01N\xcc\x8f\xb0>@,B=\xbe\xe9 \xcf\xd2\x8f\\M\xce\xd4)U\xbe\xdb#x\x8dIF_\xd989\xc6\xd7x\x90\x00\xa8\xfa\xaf\x7f\xfb\xb0\x9a(\xf3\xa0\xb5\xad\x82\xd6\x06-\xa6)M\xcb\xffL\xf1u\x0cm\xf5\n\xeb\x8d\x94F\xd0\x8a\x9a\x1b\\^\xd2\x02\xe1\r\xea\xb1r\x08\x12}\xa0\xe5y3\xe9P\x07\x8f\xa5\xc0\xc3'

Plug DPS List:
Traceback (most recent call last):
File "./get_dps.py", line 58, in <module>
for key in data['dps'].keys():
TypeError: byte indices must be integers or slices, not str



I've got some more configured(not this model) and not had had any problems

Any suggest ?
payload=b'3.3 indicates your device is using protocol 3.3. So, which version of pytuya are you using? You need 7.0.4

Hi merlot,
I don't know what version I am using. How can I find out the version? How can I update it?
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

tete wrote: Monday 05 August 2019 9:53

Hi merlot,
I don't know what version I am using. How can I find out the version? How can I update it?
sudo pip3 show pytuya

Unfortunately, I couldnn't upgrade using the --upgrade option in pip3 and I had to copy/paste the __init from the project git site.
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

merlot wrote: Monday 05 August 2019 11:06
tete wrote: Monday 05 August 2019 9:53

Hi merlot,
I don't know what version I am using. How can I find out the version? How can I update it?
sudo pip3 show pytuya

Unfortunately, I couldnn't upgrade using the --upgrade option in pip3 and I had to copy/paste the __init from the project git site.
Hi,
I ran this command but nothing appears, but I have installed it during the plugin installation (git clone https://github.com/clach04/python-tuya.git)

If I run the test.py file of the pytuya installation, I get this output


pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/python-tuya $ ./tests.py
INFO:pytuya:pytuya version 7.0.4
INFO:pytuya:Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
INFO:pytuya:Using PyCrypto (2, 6, 1, 'final', 0)
INFO:pytuya:Using PyCrypto from '/home/pi/.local/lib/python3.5/site-packages/Crypto/__init__.py'
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

tete wrote: Monday 05 August 2019 11:51
Hi,
I ran this command but nothing appears, but I have installed it during the plugin installation (git clone https://github.com/clach04/python-tuya.git)

If I run the test.py file of the pytuya installation, I get this output


pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/python-tuya $ ./tests.py
INFO:pytuya:pytuya version 7.0.4
INFO:pytuya:Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
INFO:pytuya:Using PyCrypto (2, 6, 1, 'final', 0)
INFO:pytuya:Using PyCrypto from '/home/pi/.local/lib/python3.5/site-packages/Crypto/__init__.py'
Then you can add device.set_version(3.3) in the get_dps.py after creating the device and the get_dps.py should work
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

merlot wrote: Monday 05 August 2019 12:31
tete wrote: Monday 05 August 2019 11:51
Hi,
I ran this command but nothing appears, but I have installed it during the plugin installation (git clone https://github.com/clach04/python-tuya.git)

If I run the test.py file of the pytuya installation, I get this output


pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/python-tuya $ ./tests.py
INFO:pytuya:pytuya version 7.0.4
INFO:pytuya:Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
INFO:pytuya:Using PyCrypto (2, 6, 1, 'final', 0)
INFO:pytuya:Using PyCrypto from '/home/pi/.local/lib/python3.5/site-packages/Crypto/__init__.py'
Then you can add device.set_version(3.3) in the get_dps.py after creating the device and the get_dps.py should work
Sorry, could you tell me how to do it?

Thanks in advance.
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

merlot wrote: Monday 05 August 2019 0:02

I answer myself. The problem for a dual socket plug is in this code
Spoiler: show
for val in self.__unit2dps_id_list:

if(val <= max_dps): #single socket dps
Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create()
Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create()
Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create()
Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create()
Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create()
Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.")
If in the dps_ide_list I have 1 and 2, as it's my case, in the first loop it tries to create Unit 1 to 5, and in the second one 2 to 6.

It should be something like this
Spoiler: show
for val in self.__unit2dps_id_list:

if(val <= max_dps): #single socket dps
Domoticz.Device(Name="Tuya SmartPlug (Switch)", Unit=val, TypeName="Switch").Create()
Domoticz.Log("Tuya SmartPlug Device (Switch) #" + str(val) +" created.")
if(val == max_dps):
Domoticz.Device(Name="Tuya SmartPlug (A)" , Unit=val+1, TypeName="Current (Single)").Create()
Domoticz.Log("Tuya SmartPlug Device (A) #" + str(val+1) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (kWh)", Unit=val+2, TypeName="kWh").Create()
Domoticz.Log("Tuya SmartPlug Device kWh #" + str(val+2) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (V)", Unit=val+3, TypeName="Voltage").Create()
Domoticz.Log("Tuya SmartPlug Device (V) #" + str(val+3) +" created.")
Domoticz.Device(Name="Tuya SmartPlug (W)", Unit=val+4, TypeName="Usage").Create()
Domoticz.Log("Tuya SmartPlug Device (W) #" + str(val+4) +" created.")
I think that the else statment for the group should also be corrected, but I'm setting to None, so I don't mind

Thank you
@sincze I have modified the code and requested a pull in github.

This afternoon I'll try to create a new params (Port or SerialPort) to select 3.1 or 3.3 protocol.

Anyway, I think the plugin is not working for 3.3 (I get no data in the devices) and I think that it's because the plugin is not using the pytuya methods to get the status
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

merlot wrote: Monday 05 August 2019 12:31
tete wrote: Monday 05 August 2019 11:51
Hi,
I ran this command but nothing appears, but I have installed it during the plugin installation (git clone https://github.com/clach04/python-tuya.git)

If I run the test.py file of the pytuya installation, I get this output


pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin/python-tuya $ ./tests.py
INFO:pytuya:pytuya version 7.0.4
INFO:pytuya:Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
INFO:pytuya:Using PyCrypto (2, 6, 1, 'final', 0)
INFO:pytuya:Using PyCrypto from '/home/pi/.local/lib/python3.5/site-packages/Crypto/__init__.py'
Then you can add device.set_version(3.3) in the get_dps.py after creating the device and the get_dps.py should work
I've added the line in the get_dps.py and it doesn't works.

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin $ sudo ./get_dps.py 192.168.0.171 60417563840d8e68fe98
Traceback (most recent call last):
File "./get_dps.py", line 49, in <module>
data = device.status()
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlugMaster-Plugin/pytuya/__init__.py", line 279, in status
payload = self.generate_payload('status')
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlugMaster-Plugin/pytuya/__init__.py", line 219, in generate_payload
json_payload = self.cipher.encrypt(json_payload, False)
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlugMaster-Plugin/pytuya/__init__.py", line 64, in encrypt
cipher = AES.new(self.key, mode=AES.MODE_ECB)
File "/usr/lib/python3/dist-packages/Crypto/Cipher/AES.py", line 94, in new
return AESCipher(key, *args, **kwargs)
File "/usr/lib/python3/dist-packages/Crypto/Cipher/AES.py", line 59, in __init__
blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
File "/usr/lib/python3/dist-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
self._cipher = factory.new(key, *args, **kwargs)
ValueError: Key cannot be the null string
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

merlot wrote: Monday 05 August 2019 13:37
@sincze I have modified the code and requested a pull in github.

This afternoon I'll try to create a new params (Port or SerialPort) to select 3.1 or 3.3 protocol.

Anyway, I think the plugin is not working for 3.3 (I get no data in the devices) and I think that it's because the plugin is not using the pytuya methods to get the status
Yesterday, before introducing the version param, I tried to get it working by replicating the pytuya code for 3.3 protocol to extract_status, but without success.

I don't know the reason why the plugin was developed using connection and onMessage strategy, but I'll try a different approach: just using the self.__device.send_receive method when sending a command, in the onCommand cal, and self.__device.status() to get the status on each hearbeat. In the get_dps.py it works this status() method, so I hope it also does in the plugin, and it seems to me a cleaner solution, or at least simpler.

I'll keep you informed

Thank you
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

Got it

Image

The only problem is that I get this error after switching on or off the plug. But it is turned on or off
Spoiler: show
2019-08-07 18:53:31.532 Error: (Plug Cuina) 'onCommand' failed 'ValueError':'Input strings must be a multiple of 16 in length'.
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 531 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function onCommand
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 471 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function onCommand
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 300 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function __command_to_execute
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 315 in '/usr/local/lib/python3.5/dist-packages/pytuya/__init__.py', function status
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 89 in '/usr/local/lib/python3.5/dist-packages/pytuya/__init__.py', function decrypt
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 295 in '/usr/lib/python3/dist-packages/Crypto/Cipher/blockalgo.py', function decrypt
I'll keep investigating, but any suggestion is welcome

The code in my pytuya-device branch

https://github.com/merlot-dev/Domoticz- ... uya-device
merlot
Posts: 33
Joined: Saturday 13 April 2019 16:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by merlot »

My modified plugin works fine, with the mentioned errors, for multisocket plug

Image

Some weird problems

You can see that V*A != W. But I have observed that I get the same values in Smart Life app. It's like the W is calculated for 110V not the real one. So, perhaps I'll modify to set the W as a calculation, not from the corresponding DPS.

If I plug something it takes much time (5 or more minutes) to get the right information. I haven't tried with the Smart Life app, but the get_dps.py gets the same zero values for A and W DPS

Comments are welcome
tete
Posts: 8
Joined: Tuesday 11 September 2018 13:08
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [REQUEST] Plugin for Tuya

Post by tete »

merlot wrote: Wednesday 07 August 2019 19:24 Got it

Image

The only problem is that I get this error after switching on or off the plug. But it is turned on or off
Spoiler: show
2019-08-07 18:53:31.532 Error: (Plug Cuina) 'onCommand' failed 'ValueError':'Input strings must be a multiple of 16 in length'.
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 531 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function onCommand
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 471 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function onCommand
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 300 in '/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin2/plugin.py', function __command_to_execute
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 315 in '/usr/local/lib/python3.5/dist-packages/pytuya/__init__.py', function status
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 89 in '/usr/local/lib/python3.5/dist-packages/pytuya/__init__.py', function decrypt
2019-08-07 18:53:31.532 Error: (Plug Cuina) ----> Line 295 in '/usr/lib/python3/dist-packages/Crypto/Cipher/blockalgo.py', function decrypt
I'll keep investigating, but any suggestion is welcome

The code in my pytuya-device branch

https://github.com/merlot-dev/Domoticz- ... uya-device
Bon dia Merlot,
I have tested your code and I receive the same error as before.
I am doing something wrong ?

pi@domoticz:~/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device $ ./get_dps.py 192.168.0.171 60417563840d8e68fe98
Traceback (most recent call last):
File "./get_dps.py", line 51, in <module>
data = device.status()
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/pytuya/__init__.py", line 279, in status
payload = self.generate_payload('status')
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/pytuya/__init__.py", line 219, in generate_payload
json_payload = self.cipher.encrypt(json_payload, False)
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/pytuya/__init__.py", line 64, in encrypt
cipher = AES.new(self.key, mode=AES.MODE_ECB)
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/Crypto/Cipher/AES.py", line 95, in new
return AESCipher(key, *args, **kwargs)
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/Crypto/Cipher/AES.py", line 59, in __init__
blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
File "/home/pi/domoticz/plugins/Domoticz-Tuya-SmartPlug-Plugin-pytuya-device/Crypto/Cipher/blockalgo.py", line 141, in __init__
self._cipher = factory.new(key, *args, **kwargs)
ValueError: Key cannot be the null string
Post Reply

Who is online

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