Page 19 of 19

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 16 June 2020 21:42
by rogdlm
jforum wrote: Monday 25 May 2020 13:11 Recently, I found a plugin that don’t require you to flash the Tuya firmware. It works similar to the Homeassistant Tuya Plugin.
Created a video to show you how to integrate it and make it work with Tuya Smart Life App. As of today, this plugin need a little code to make it work with the Smart Life App else it will just work with Tuya App.

https://youtu.be/pBJZcwIDOUY

Hope this help. Thanks.
Hello,

This plugin can be compliant with Tuya Wifi Motion Sensor ?

Thanks by advance

Re: [REQUEST] Plugin for Tuya

Posted: Wednesday 08 July 2020 18:25
by nono212
I prefer not to use cloud solution

Re: [REQUEST] Plugin for Tuya

Posted: Wednesday 08 July 2020 20:42
by Xenomes
For those who have realtek chips RGB bulbs and want to control them in Domoticz, check out this git hub page.
https://github.com/guino/tuyaha

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 05 July 2022 17:47
by yannig
Hello,
I never succeeded to get info consumption from my Tuya smart plugs with existing plugins.
But I've find a workaround that I posted here https://easydomoticz.com/forum/viewtopi ... 69#p105469 in French.

The result is below :
Tuya smart plug infos
Tuya smart plug infos
Capture d’écran 2022-07-05 à 17.26.14.png (277.43 KiB) Viewed 1730 times

Re: [REQUEST] Plugin for Tuya

Posted: Monday 11 July 2022 9:24
by edwin1234
I have installed the plugin for tuya smart plug on raspberry pi4 buster
And filled everything in correctly, when i try get_dps.py i get the correct values but still
Got nothing in domoticz devices, in the log i see a bunch of hex numbers and no errors.

What can be wrong?

Re: [REQUEST] Plugin for Tuya

Posted: Wednesday 13 July 2022 20:23
by edwin1234
I did the script by yanning, now i have some values but there is a 0, in front of the value
Can someone help to find the cause of it?
See screenshot.

Image

This is the used script from yanning:

Code: Select all

#!/usr/bin/python3

########################################################################################
#       Domoticz Tuya Smart Plug Python script                                         #
#                                                                                      #
#                                                                                      #
#                                                                                      #
#       Copyright (c) 2022 Wallb35                                                     #
#                                                                                      #
#       Permission is hereby granted, free of charge, to any person obtaining a copy   #
#       of this software and associated documentation files (the "Software"), to deal  #
#       in the Software without restriction, including without limitation the rights   #
#       to use, copy, modify, merge, publish, distribute, sublicense, and/or sell      #
#       copies of the Software, and to permit persons to whom the Software is          #
#       furnished to do so, subject to the following conditions:                       #
#                                                                                      #
#       The above copyright notice and this permission notice shall be included in all #
#       copies or substantial portions of the Software.                                #
#                                                                                      #
#       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR     #
#       IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,       #
#       FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    #
#       AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER         #
#       LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  #
#       OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  #
#       SOFTWARE.                                                                      #
#                                                                                      #
########################################################################################

#v0.6 - 5 JUL 2022

import sys
import pytuya
import socket #needed for socket.timeout exception
import urllib.request
import base64

UPDATEOK = "success"
UPDATEFAILED = "FAILED"

DOMSERVER   = "http://192.168.2.127:9091" # domoticz local IP + port
DOMUSER = "domoticzuser" # !!!
DOMPASS = "Domoticzpassword" # !!!

BASE64STR = base64.encodebytes(('%s:%s' % (DOMUSER, DOMPASS)).encode()).decode().replace('\n', '')

def domrequest (url):
  request = urllib.request.Request(url)
  request.add_header("Authorization", "Basic %s" % BASE64STR)
  response = urllib.request.urlopen(request)
  return response.read()

if(len(sys.argv)!=8):
        print("usage: " + sys.argv[0] + " <IP> <DevID> <DevKey> <butwatid> <butvolid> <butintid> <butkwhid>")
        exit(1)

ip       = sys.argv[1]
devid    = sys.argv[2]
devkey   = sys.argv[3]
butwatid = sys.argv[4]
butvolid = sys.argv[5]
butintid = sys.argv[6]
butkwhid = sys.argv[7]

device   = pytuya.OutletDevice(devid,ip,devkey)

data = 0 #stub for the try except
try:
        device.set_version(3.3)
        data = device.status()
except (ConnectionResetError, socket.timeout, OSError)  as e:
        print("A problem occur please retry...")
        exit(1)

values = data["dps"]
amp = int(values["18"])/1000
watt = int(values["19"])/10
volt= int(values["20"])/10

req = domrequest(
     DOMSERVER + "/json.htm?type=command&param=udevice&idx=" + butwatid + "&nvalue=0&svalue=" 
     + str(watt) 
    )

if "OK" in str(req):
     res = "OK"
else:
     res = "FAILED"
     
req = domrequest(
     DOMSERVER + "/json.htm?type=command&param=udevice&idx=" + butkwhid + "&nvalue=0&svalue=" 
     + str(watt) + ";0"
    )

if "OK" in str(req):
     res = "OK"
else:
     res = "FAILED"

print("watts : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))

req = domrequest(
     DOMSERVER + "/json.htm?type=command&param=udevice&idx=" + butvolid + "&nvalue=0&svalue="
     + str(volt)
    )

if "OK" in str(req):
     res = "OK"
else:
     res = "FAILED"

print("volt : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))

req = domrequest(
     DOMSERVER + "/json.htm?type=command&param=udevice&idx=" + butintid + "&nvalue=0&svalue="
     + str(amp)
    )

if "OK" in str(req):
     res = "OK"
else:
     res = "FAILED"

print("amp : domoticz update =>", (UPDATEOK if "OK" in str(req) else UPDATEFAILED))



Re: [REQUEST] Plugin for Tuya

Posted: Wednesday 03 August 2022 11:56
by Beastie
Hi

Same for me. No update of the devices, get_dps.py OK
Plug State Information:
{'dps': {'1': True, '9': 0, '17': 100, '18': 1321, '19': 3037, '20': 2271, '21': 1, '22': 602, '23': 31906, '24': 17362, '25': 2390, '26': 0, '41': '', '42': ''}}

Plug DPS List:
1

I get this but i think data is not understood
2022-08-03 12:28:41.087 Tuya: Calling message handler 'onMessage' on 'module' type object.
2022-08-03 12:28:41.087 Tuya: onMessage called: 192.168.249.113:6668 b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x017\x13I2&\x84\xa0}\xec\xc6\xa0w\xc4\xf9\x1d\xf1\xb2$\x1f\xd8\xe6\x7f\xbe\xb5\xf2\xa8?\xf0)\x92\x95\xc9d\xc3\xa9{\x00\x00\xaaU'

Re: [REQUEST] Plugin for Tuya

Posted: Saturday 03 September 2022 10:14
by yannig
Since devices’s firmware upgrade in v1.1.12 (was working in v1.1.8) get_dps.py doesn’t work anymore… I’ll try to have a look next week.

Re: [REQUEST] Plugin for Tuya

Posted: Monday 05 September 2022 9:08
by yannig
Here is the error from get_dps :

original get_dps.py (without v3.3 protocol) error message as follow :
Unexpected status() payload=b''

Plug State Information:
b''

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
get_dps.py modified with 3.3 protocol :
Traceback (most recent call last):
File "./get_dpsv2.py", line 48, in <module>
data = device.status()
File "/volume1/homes/yannig/domoticz/scripts/python/pytuya/__init__.py", line 305, in status
result = cipher.decrypt(result, False)
File "/volume1/homes/yannig/domoticz/scripts/python/pytuya/__init__.py", line 92, in decrypt
plain_text += cipher.feed() # flush final block
File "/usr/lib/python3.8/site-packages/pyaes/blockfeeder.py", line 169, in feed
result = self._final(self._buffer, self._padding)
File "/usr/lib/python3.8/site-packages/pyaes/blockfeeder.py", line 77, in _block_final_decrypt
return strip_PKCS7_padding(self.decrypt(data))
File "/usr/lib/python3.8/site-packages/pyaes/aes.py", line 349, in decrypt
raise ValueError('ciphertext block must be 16 bytes')
ValueError: ciphertext block must be 16 bytes
No Idea how to correct this :(

-- Edit Sept 8 : looks like there's a v3.4 protocol now. not supported yet.

Re: [REQUEST] Plugin for Tuya

Posted: Monday 05 September 2022 9:20
by yannig
Beastie wrote: Wednesday 03 August 2022 11:56 Hi

Same for me. No update of the devices, get_dps.py OK
Plug State Information:
{'dps': {'1': True, '9': 0, '17': 100, '18': 1321, '19': 3037, '20': 2271, '21': 1, '22': 602, '23': 31906, '24': 17362, '25': 2390, '26': 0, '41': '', '42': ''}}

Plug DPS List:
1

I get this but i think data is not understood
2022-08-03 12:28:41.087 Tuya: Calling message handler 'onMessage' on 'module' type object.
2022-08-03 12:28:41.087 Tuya: onMessage called: 192.168.249.113:6668 b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00,\x00\x00\x00\x017\x13I2&\x84\xa0}\xec\xc6\xa0w\xc4\xf9\x1d\xf1\xb2$\x1f\xd8\xe6\x7f\xbe\xb5\xf2\xa8?\xf0)\x92\x95\xc9d\xc3\xa9{\x00\x00\xaaU'
Hi Beastie,
is original get-dps.py result or modified one with v3.3 protocol ?
Your IDs looks same to me : with 18, 19, 20 respectively with Amp, Watts and Volts.

Re: [REQUEST] Plugin for Tuya

Posted: Friday 30 September 2022 8:19
by Meki333
Hi,
I have smart plug from aliexpress, on and off work in Domoticz normally. I need to read conpsumtion, but without sucesss. I cant read data with get_dps.py. Tuya-cli print device ID and key, but get_dps end with error "invalid padding byte".



Any idea, how to fix this?


Edit:

I managed to get get_dps.py working. I'm probably getting the information right:
get_dps.png
get_dps.png (52.97 KiB) Viewed 1365 times
If I use Tinytuya scan, it says that the device version is v3.3.

tinytuya.png
tinytuya.png (167.91 KiB) Viewed 1365 times
In tuya smart plugs settings I have this:
domoticz_settings.png
domoticz_settings.png (337.79 KiB) Viewed 1365 times
Until then, everything would probably be fine. But of course I don't see any data (watt, volt...) in Domoticz. In the log I found an attempt to communicate with the plug, but there is no list of values ​​like in get_dps:

2022-10-05 15:37:18.651 Domca_stolek: Pushing 'onMessageCallback' on to queue
2022-10-05 15:37:18.651 Domca_stolek: Acquiring GIL for 'ReadEvent'
2022-10-05 15:37:18.651 Domca_stolek: Processing 'ReadEvent' message
2022-10-05 15:37:18.651 Domca_stolek: Acquiring GIL for 'ReadEvent'
2022-10-05 15:37:18.651 Domca_stolek: Received 188 bytes of data
2022-10-05 15:37:18.651 Domca_stolek: 00 00 55 aa 00 00 00 00 00 00 00 0a 00 00 00 ac 00 00 00 00 ..Uʮ..........̮...
2022-10-05 15:37:18.651 Domca_stolek: 6b e8 f3 9c 3a 43 66 cc 62 77 aa 1a dc 20 59 c4 d5 6b d8 73 k賜:Cf̢wʮܮYĕkس
2022-10-05 15:37:18.651 Domca_stolek: ac 4e 3d c2 5c 50 5f 43 8e ce 6e 24 a9 5c ea 77 d3 38 69 47 ̎=œP_CΎn$ɜ귓8iG
2022-10-05 15:37:18.651 Domca_stolek: e5 92 f4 67 08 cd fe 5e e5 57 11 e8 fb 8e 5a c4 ad 29 1e df 咴g.;^嗮軎Zĭ).�
2022-10-05 15:37:18.651 Domca_stolek: 4d 5b 67 f6 88 f2 4b 2e fe 69 28 9f 90 13 ad 50 92 8c 9a d9 M[g򈲋.�i(ߐ.͐Ҍڙ
2022-10-05 15:37:18.651 Domca_stolek: 6e 48 da 06 c0 60 1a 96 9b f5 0b 69 de 29 74 a2 bb e3 fa 8a nHڮ�.֛񮩞)t»㺊
2022-10-05 15:37:18.652 Domca_stolek: 89 47 d3 65 fc 7d 17 df 56 c0 05 36 1a 79 59 da 25 72 45 c3 ɇӥ�}.ߖ�6.yYڥrE�
2022-10-05 15:37:18.652 Domca_stolek: ba 99 49 0b a2 03 05 ce ab 24 02 3f ab 9a 79 dc 37 72 2e 75 ڙI.®.Ϋ$.?˚yܷr.u
2022-10-05 15:37:18.652 Domca_stolek: 0a b9 99 52 91 1b f8 6f 5f 63 4f ed 33 30 67 f9 9b 67 2c ef .ٙRѮ�o_cO�g�ۧ,�
2022-10-05 15:37:18.652 Domca_stolek: e2 c5 6d 01 00 00 aa 55 .. .. .. .. .. .. .. .. .. .. .. .. Ⅽ...ʕ
2022-10-05 15:37:18.652 Domca_stolek: Pushing 'onMessageCallback' on to queue
2022-10-05 15:37:18.652 Domca_stolek: Acquiring GIL for 'ReadEvent'
2022-10-05 15:37:18.652 Domca_stolek: Processing 'onMessageCallback' message
2022-10-05 15:37:18.652 Domca_stolek: Acquiring GIL for 'onMessageCallback'
2022-10-05 15:37:18.652 Domca_stolek: Calling message handler 'onMessage' on 'module' type object.
2022-10-05 15:37:18.652 Domca_stolek: onMessage called: 192.168.1.210:6668 b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\xac\x00\x00\x00\x00k\xe8\xf3\x9c:Cf\xccbw\xaa\x1a\xdc Y\xc4\xd5k\xd8s\xacN=\xc2\\P_C\x8e\xcen$\xa9\\\xeaw\xd38iG\xe5\x92\xf4g\x08\xcd\xfe^\xe5W\x11\xe8\xfb\x8eZ\xc4\xad)\x1e\xdfM[g\xf6\x88\xf2K.\xfei(\x9f\x90\x13\xadP\x92\x8c\x9a\xd9nH\xda\x06\xc0`\x1a\x96\x9b\xf5\x0bi\xde)t\xa2\xbb\xe3\xfa\x8a\x89G\xd3e\xfc}\x17\xdfV\xc0\x056\x1ayY\xda%rE\xc3\xba\x99I\x0b\xa2\x03\x05\xce\xab$\x02?\xab\x9ay\xdc7r.u\n\xb9\x99R\x91\x1b\xf8o_cO\xed30g\xf9\x9bg,\xef\xe2\xc5m\x01\x00\x00\xaaU'
2022-10-05 15:37:18.655 Domca_stolek: Pushing 'WriteDirective' on to queue
2022-10-05 15:37:18.655 Domca_stolek: Acquiring GIL for 'onMessageCallback'
2022-10-05 15:37:18.655 Domca_stolek: Processing 'onMessageCallback' message
2022-10-05 15:37:18.655 Domca_stolek: Acquiring GIL for 'onMessageCallback'
2022-10-05 15:37:18.655 Domca_stolek: Calling message handler 'onMessage' on 'module' type object.
2022-10-05 15:37:18.655 Domca_stolek: onMessage called: 192.168.1.210:6668 b'\x00\x00U\xaa\x00\x00\x00\x00\x00\x00\x00\n\x00\x00\x00\xac\x00\x00\x00\x00k\xe8\xf3\x9c:Cf\xccbw\xaa\x1a\xdc Y\xc4\xd5k\xd8s\xacN=\xc2\\P_C\x8e\xcen$\xa9\\\xeaw\xd38iG\xe5\x92\xf4g\x08\xcd\xfe^\xe5W\x11\xe8\xfb\x8eZ\xc4\xad)\x1e\xdfM[g\xf6\x88\xf2K.\xfei(\x9f\x90\x13\xadP\x92\x8c\x9a\xd9nH\xda\x06\xc0`\x1a\x96\x9b\xf5\x0bi\xde)t\xa2\xbb\xe3\xfa\x8a\x89G\xd3e\xfc}\x17\xdfV\xc0\x056\x1ayY\xda%rE\xc3\xba\x99I\x0b\xa2\x03\x05\xce\xab$\x02?\xab\x9ay\xdc7r.u\n\xb9\x99R\x91\x1b\xf8o_cO\xed30g\xf9\x9bg,\xef\xe2\xc5m\x01\x00\x00\xaaU'
2022-10-05 15:37:18.656 Domca_stolek: Pushing 'WriteDirective' on to queue
2022-10-05 15:37:18.656 Domca_stolek: Acquiring GIL for 'onMessageCallback'
2022-10-05 15:37:18.656 Domca_stolek: Processing 'WriteDirective' message
2022-10-05 15:37:18.656 Domca_stolek: Acquiring GIL for 'WriteDirective'
2022-10-05 15:37:18.656 Domca_stolek: Sending 104 bytes of data
2022-10-05 15:37:18.656 Domca_stolek: 00 00 55 aa 00 00 00 00 00 00 00 0a 00 00 00 58 64 23 91 b1 ..Uʮ..........Xd#ѱ
2022-10-05 15:37:18.656 Domca_stolek: b5 2d d4 18 47 bb c6 89 6a 71 b5 f1 cb 01 67 ca 78 1b cc f2 խԮGۆɪqձˮgʸ.̲
2022-10-05 15:37:18.656 Domca_stolek: 2c df 95 0f eb 38 1f ca 7a c1 eb cb bc 8f 19 ce 55 11 a9 78 ,ߕ.븮ʺ�˼ϮΕ.ɸ
2022-10-05 15:37:18.656 Domca_stolek: 66 17 54 0d 8b 80 69 01 e6 17 23 62 e4 9f 02 ac 29 df 0f 42 f.T.ˀi.殣b䟮̩߮B
2022-10-05 15:37:18.656 Domca_stolek: c8 2b 2b 3f 17 f9 9f c3 b0 68 41 c8 a8 68 75 32 1e 20 0c 28 ȫ+?.�߃ШAȨhu2...(
2022-10-05 15:37:18.656 Domca_stolek: 00 00 aa 55 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..ʕ
2022-10-05 15:37:18.656 Domca_stolek: Acquiring GIL for 'WriteDirective'
2022-10-05 15:37:18.656 Domca_stolek: Processing 'WriteDirective' message
2022-10-05 15:37:18.656 Domca_stolek: Acquiring GIL for 'WriteDirective'
2022-10-05 15:37:18.656 Domca_stolek: Sending 104 bytes of data
2022-10-05 15:37:18.656 Domca_stolek: 00 00 55 aa 00 00 00 00 00 00 00 0a 00 00 00 58 64 23 91 b1 ..Uʮ..........Xd#ѱ
2022-10-05 15:37:18.656 Domca_stolek: b5 2d d4 18 47 bb c6 89 6a 71 b5 f1 cb 01 67 ca 78 1b cc f2 խԮGۆɪqձˮgʸ.̲
2022-10-05 15:37:18.656 Domca_stolek: 2c df 95 0f eb 38 1f ca 7a c1 eb cb bc 8f 19 ce 55 11 a9 78 ,ߕ.븮ʺ�˼ϮΕ.ɸ
2022-10-05 15:37:18.656 Domca_stolek: 66 17 54 0d 8b 80 69 01 e6 17 23 62 e4 9f 02 ac 29 df 0f 42 f.T.ˀi.殣b䟮̩߮B
2022-10-05 15:37:18.656 Domca_stolek: c8 2b 2b 3f 17 f9 9f c3 b0 68 41 c8 a8 68 75 32 1e 20 0c 28 ȫ+?.�߃ШAȨhu2...(
2022-10-05 15:37:18.656 Domca_stolek: 00 00 aa 55 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..ʕ
2022-10-05 15:37:18.656 Domca_stolek: Acquiring GIL for 'WriteDirective'
2022-10-05 15:37:18.664 Domca_stolek: Acquiring GIL for 'CPluginTransportTCP::handleRead'
2022-10-05 15:37:18.664 Domca_stolek: Pushing 'ReadEvent' on to queue
2022-10-05 15:37:18.675 Domca_stolek: Acquiring GIL for 'CPluginTransportTCP::handleRead'



What am I doing wrong?

Try to kick me.

Re: [REQUEST] Plugin for Tuya

Posted: Monday 10 October 2022 15:56
by Meki333
It's kind of dead here...

Re: [REQUEST] Plugin for Tuya

Posted: Tuesday 11 October 2022 11:07
by FearNaBoinne
I'm not sure the plugin is still maintained, but even before, the author rarely dropped in, you may have more success opening a ticket on the repo...

Re: [REQUEST] Plugin for Tuya

Posted: Wednesday 18 January 2023 19:24
by jvm1000