leeyuentuen / localtuya

local handling for Tuya devices
GNU General Public License v3.0
72 stars 17 forks source link

Нет проблем со чтением значений атрибутов в шлюзе 3.4, но невозможно записать значения атрибутов, что не имеет никакого эффекта. Как мне справиться с этим? #65

Closed yakish777 closed 1 year ago

yakish777 commented 1 year ago

2023-05-21 14:33:02.475 DEBUG (MainThread) [custom_components.localtuya] Device bfc6eb5c75b0938bcbcv3b found with IP 192.168.0.137 2023-05-21 14:33:02.802 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Sending command 9 (device type: v3.4) 2023-05-21 14:33:02.803 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Sending payload: b'{"gwId":"bfc6eb5c75b0938bcbcv3b","devId":"bfc6eb5c75b0938bcbcv3b"}' 2023-05-21 14:33:02.803 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] final payload for cmd 9: b'{"gwId":"bfc6eb5c75b0938bcbcv3b","devId":"bfc6eb5c75b0938bcbcv3b"}' 2023-05-21 14:33:02.805 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Dispatching sequence number -100 2023-05-21 14:33:02.805 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] payload b'\x00\x00U\xaa\x00\x00\xd0t\x00\x00\x00\t\x00\x00\x00t\xf9\xd1\xa8jA\xd1\xc4\xe9\x97|\xc6M\x82\xefdN\xfd\xef8|D\x86\xb9\x08\x18\x00rB\x96\xae\xfc\xfcsO\xfe\x1d\xe01\xce\xa4\xeb\xe1\x91?\xd5\xa2\x86 \xbf\xed\x0b7!<\xc1\xef\x96\x804\xd3\xfbI\x8fA%e\xe8\x10\xd2/o \xba\xef\xc3\xbf)\xc8\x13i\xd6E\xc7%\x08o\xa4\xbd9\x8ck\xcf\xc7\xff\xab)\x17\x8biR\x1e[\x85\xff`\xa7zl6<\xe8\x00\x00\xaaU' - MessagePayload(cmd=9, payload=b'{"gwId":"bfc6eb5c75b0938bcbcv3b","devId":"bfc6eb5c75b0938bcbcv3b"}') 2023-05-21 14:33:02.806 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Command 9 waiting for sequence number -100 2023-05-21 14:33:02.812 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Dispatching message CMD 9 TuyaMessage(seqno=53364, cmd=9, retcode=0, payload=b'', crc=b">\x03\xea\x95\x99\xfa}'\xfc\n@\xb4cB\xa0\x9d\xbe\xf8\x9cV\x1b\xc5!}b\x8d\x06\xfd\xcd\xb6\x86", crc_good=True) 2023-05-21 14:33:02.813 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Got heartbeat response 2023-05-21 14:33:02.814 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] ACK received for command 9: ignoring it 2023-05-21 14:33:02.959 DEBUG (MainThread) [custom_components.localtuya.common] [a4c...966] Dispatching request request_set_dp to gateway with content {'value': True, 'dp_index': 1} 2023-05-21 14:33:02.960 DEBUG (MainThread) [custom_components.localtuya.common] [bfc...v3b] Received request request_set_dp from a4c1381236902966 with content {'value': True, 'dp_index': 1} 2023-05-21 14:33:02.960 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Sending command 7 (device type: v3.4) 2023-05-21 14:33:02.961 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Sending payload: b'{"protocol":5,"t":1684668782,"data":{"dps":{"1":true}},"cid":"a4c1381236902966"}' 2023-05-21 14:33:02.961 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] final payload for cmd 13: b'3.4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{"protocol":5,"t":1684668782,"data":{"dps":{"1":true}},"cid":"a4c1381236902966"}' 2023-05-21 14:33:02.964 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Dispatching sequence number 53365 2023-05-21 14:33:02.965 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] payload b'\x00\x00U\xaa\x00\x00\xd0u\x00\x00\x00\r\x00\x00\x00\x840\x97\xdbJ\xef\xb0\xeb\x8d\x18\xa2\xb0\xbb\x1c\xf0\x16\xb4\x07\xef(H\xcb\xd7\xb3qQ\x19\x9e\xa2\x8f\xfc\xc1l\xa8\x1d4\xba\x08\xef\xc3{\xca2\x81$H\xc7\xafF\xe1\xf6\xb3\xccW\xbeP\xbf\xe1~\xa3\xf7c`\xe7j\xa6\xa0P\xd0c\x8fd\xbe\x19<\x0bMBTX\x1f\xe9#\x9e\x88\x8f\xdb\xecy\x02\xe8\xba\x1fe \xaeQ\x11\x9a\xd8z\xbb\x98\xb8Y\x8c\x95<\xb9\xea\s\xfc\x87\xb0\xda\t(#\xe6\xa5\x8e\xdd^|\xd3\x15\xeet\x00\x00\xaaU' - MessagePayload(cmd=13, payload=b'{"protocol":5,"t":1684668782,"data":{"dps":{"1":true}},"cid":"a4c1381236902966"}') 2023-05-21 14:33:02.967 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Command 13 waiting for sequence number 53365 2023-05-21 14:33:02.972 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Dispatching message CMD 13 TuyaMessage(seqno=53365, cmd=13, retcode=0, payload=b'', crc=b'\xa2\x99\xcd)\xe9\xdc\x8e8=|\x7ff\x82\xcb\xae\xe6\x87\xa6\x83\xec\xfe\xbd\xf9\x13[\xe3\xe9U\xd7\x0e\x9e9', crc_good=True) 2023-05-21 14:33:02.972 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] Dispatching sequence number 53365 2023-05-21 14:33:02.973 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfc...v3b] ACK received for command 13: ignoring it 2023-05-21 14:33:07.475 DEBUG (MainThread) [custom_components.localtuya] Device bfc6eb5c75b0938bcbcv3b found with IP 192.168.0.137

yakish777 commented 1 year ago

Hi! localtuya 3.7.0 Beta 10 ZigBee Gateway protocol 3.4 ZigBee device protocol 3.3

I can connect to the device without any problems, I see all its state, I see changes in states, but there is no way to affect the state!!! help me!

yakish777 commented 1 year ago

Everything works through tuyapi/cli!!!And through HA does not work!

VitalyAntonenko commented 1 year ago

I've got the same problem. In master branch not work. In 3.7.0 Beta 10 have state, but not set. 2023-05-24 20:59:18.200 DEBUG (MainThread) [custom_components.localtuya] Device хххххххххххххххххххххххх2 found with IP 192.168.1.119 2023-05-24 20:59:19.378 DEBUG (MainThread) [custom_components.localtuya.common] [a4c...926] Dispatching request request_set_dp to gateway with content {'value': False, 'dp_index': 1} 2023-05-24 20:59:19.379 DEBUG (MainThread) [custom_components.localtuya.common] [bfe...hb2] Received request request_set_dp from a4c13803667d8926 with content {'value': False, 'dp_index': 1} 2023-05-24 20:59:19.379 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Sending command 7 (device type: v3.4) 2023-05-24 20:59:19.380 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Sending payload: b'{"protocol":5,"t":1684951159,"data":{"dps":{"1":false}},"cid":"a4c13803667d8926"}' 2023-05-24 20:59:19.381 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] final payload for cmd 13: b'3.4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{"protocol":5,"t":1684951159,"data":{"dps":{"1":false}},"cid":"a4c13803667d8926"}' 2023-05-24 20:59:19.388 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Dispatching sequence number 29671 2023-05-24 20:59:19.389 DEBUG (MainThread) [customcomponents.localtuya.pytuya] [bfe...hb2] payload b'\x00\x00U\xaa\x00\x00s\xe7\x00\x00\x00\r\x00\x00\x00\x94\xcc\xa5\xb7\xaf\xe6NY\x10\xcc\xb8\x85\x8d\xa6\xa2\x80&\x16\x8c\xdf8&\xb5\xf2\xdb\xf8\x01\xbf\xd1\xf5\x8e1\xa9\x90by\xe2\x1e\x9e\xbb\xf2S\x99\x9c3\xc2\x82TY\xf87W\x99!\x89\x88\x9a4b\xad\x1d\xbf\xe2H.\xbbt!\xda\x99\xc9\x0c\x99\xe3\x17HN\xc2\x80\xcb\xfd\xdc\x1a\x9bP<)\x16\x06\x92!$\xd8\xe7\xbd\x97/\x0f\xd6p\x12xv\xe2(\x0bR\x18&?\x1c4\x14Ye\xe0DV\xb4\xa0\xbf\x9b\xb7\x15\xacC\xc6\xad\xcc\xf3H\xef\xeb\x86\xefo.\x92$\xde\xd6\x82\xbb\x00\x00\xaaU' - MessagePayload(cmd=13, payload=b'{"protocol":5,"t":1684951159,"data":{"dps":{"1":false}},"cid":"a4c13803667d8926"}') 2023-05-24 20:59:19.391 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Command 13 waiting for sequence number 29671 2023-05-24 20:59:19.523 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Dispatching message CMD 13 TuyaMessage(seqno=29671, cmd=13, retcode=0, payload=b'', crc=b'\x96\x8f\t\xdf\xf0\xce\x10\x1d:n\xf3aR\xe7\xe0\xea\x9eF\xfd):\x12\x08e\x9d|(\xaf\xc0\x83G', crc_good=True) 2023-05-24 20:59:19.524 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] Dispatching sequence number 29671 2023-05-24 20:59:19.525 DEBUG (MainThread) [custom_components.localtuya.pytuya] [bfe...hb2] ACK received for command 13: ignoring it

goodsale commented 1 year ago

CIAO! localtuya 3.7.0 Beta 10 Protocollo gateway ZigBee 3.4 Protocollo dispositivo ZigBee 3.3

Posso connettermi al dispositivo senza problemi, vedo tutto il suo stato, vedo cambiamenti negli stati, ma non c'è modo di influenzare lo stato!!! aiutami!

Me too, it seems there's a problem.... work in progress

yakish777 commented 1 year ago

It seems I managed to solve the problem!) It turns out that the request was sent in the wrong form {"protocol":5,"t":1687538023,"data":{"dps":{"1":false}},"cid":"a4xxxxxxxxxxx24"} and now so : {"protocol":5,"t":1687538023,"data":{"dps":{"1":false},"cid":"a4xxxxxxxxxxx24"}}

to solve the problem , I tweaked the code a little ....while it seems to be working: in the file "custom_components/localtuya/pytuya/init.py "


1373.        elif PARAMETER_DATA in json_data:
1374.                 json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
1375.             + if cid is not None:
1376.             +      json_data[PARAMETER_DATA][PARAMETER_CID] = cid
yakish777 commented 1 year ago

Thanks to the author of integration for his work!!!! I hope in the next edition they will correct this error more competently than I do))))

goodsale commented 1 year ago

Is it possible to have an upload of init.py patched?

I will try it.

Thanks

VitalyAntonenko commented 1 year ago

It seems I managed to solve the problem!) It turns out that the request was sent in the wrong form {"protocol":5,"t":1687538023,"data":{"dps":{"1":false}},"cid":"a4xxxxxxxxxxx24"} and now so : {"protocol":5,"t":1687538023,"data":{"dps":{"1":false},"cid":"a4xxxxxxxxxxx24"}}

to solve the problem , I tweaked the code a little ....while it seems to be working: in the file "custom_components/localtuya/pytuya/init.py "


1373.        elif PARAMETER_DATA in json_data:
1374.                 json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
1375.             + if cid is not None:
1376.             +      json_data[PARAMETER_DATA][PARAMETER_CID] = cid**

I edited file

        elif PARAMETER_DATA in json_data:
            json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
            #update from yakish777 
            if cid is not None:
                json_data[PARAMETER_DATA][PARAMETER_CID] = cid**
        else:
            json_data[PROPERTY_DPS] = data

and nothing change request still "protocol":5,"t":1688329377,"data":{"dps":{"1":false}},"cid":"a4xxxxxxxxxxxxxxx26"

What I'm doing wrong?

yakish777 commented 1 year ago

Кажется мне удалось решить проблему!) Получается, что запрос был отправлен в неправильном виде {"protocol":5,"t":1687538023,"data":{"dps":{"1":false}},"cid":"a4xxxxxxxxxxx24"}и теперь так:{"protocol":5,"t":1687538023,"data":{"dps":{"1":false},"cid":"a4xxxxxxxxxxx24"}} для решения проблемы немного подправил код....пока вроде работает: в файле "custom_components/localtuya/pytuya/ init.py "


1373.        elif PARAMETER_DATA in json_data:
1374.                 json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
1375.             + if cid is not None:
1376.             +      json_data[PARAMETER_DATA][PARAMETER_CID] = cid**

я редактировал файл

        elif PARAMETER_DATA in json_data:
            json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
            #update from yakish777 
            if cid is not None:
                json_data[PARAMETER_DATA][PARAMETER_CID] = cid**
        else:
            json_data[PROPERTY_DPS] = data

и запрос на изменение ничего не меняется по-прежнему "протокол": 5, "t": 1688329377, "data": {"dps": {"1": false}}, "cid": "a4xxxxxxxxxxxxxxx26"

Что я делаю неправильно?

` if PARAMETER_GW_ID in json_data: if gwId is not None: self.debug("1") json_data[PARAMETER_GW_ID] = gwId else: self.debug("2") json_data[PARAMETER_GW_ID] = self.id if PARAMETER_DEV_ID in json_data: if devId is not None: self.debug("3") json_data[PARAMETER_DEV_ID] = devId else: self.debug("4") json_data[PARAMETER_DEV_ID] = self.id if PARAMETER_UID in json_data: if uid is not None: self.debug("5") json_data[PARAMETER_UID] = uid else: self.debug("5") json_data[PARAMETER_UID] = self.id if cid is not None:

for Zigbee gateways, cid specifies the sub-device

        json_data[PARAMETER_CID] = cid
        self.debug("6")
        if PARAMETER_DATA in json_data:
            self.debug("7")
            json_data[PARAMETER_DATA][PARAMETER_DATA] = cid
            json_data[PARAMETER_DATA]["ctype"] = 0
    if PARAMETER_T in json_data:
        self.debug("8")
        if json_data[PARAMETER_T] == "int":
            self.debug("9")
            json_data[PARAMETER_T] = int(time.time())
        else:
            self.debug("10")
            json_data[PARAMETER_T] = str(int(time.time()))

    if data is not None:
        self.debug("11")
        if PARAMETER_DP_ID in json_data:
            self.debug("12")
            json_data[PARAMETER_DP_ID] = data
        elif PARAMETER_DATA in json_data:
            self.debug("13")
            json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
            if cid is not None:
                self.debug("THE CODE WAS ADDED HERE!!!!!!!!!!!!!")
                json_data[PARAMETER_DATA][PARAMETER_CID] = cid
        else:
            self.debug("14")
            json_data[PROPERTY_DPS] = data
    elif command == CONTROL_NEW:
        self.debug("16")
        if cid:
            self.debug("17")
            json_data[PROPERTY_DPS] = self.dps_to_request[cid]
        else:
            self.debug("18")
            json_data[PROPERTY_DPS] = self.dps_to_request
    elif self.dev_type == DEV_TYPE_0D and command == DP_QUERY:
        self.debug("19")
        json_data[PROPERTY_DPS] = self.dps_to_request

    if json_data == "":
        payload = ""
    else:
        self.debug("20")
        payload = json.dumps(json_data)`

try to place labels through the debug and track how the query is formed and determine whether you come to the newly added lines?

yakish777 commented 1 year ago

json_data[PARAMETER_DATA][PARAMETER_CID] = cid**

also hope you removed the ** after the CID

yakish777 commented 1 year ago

Кажется, мне удалось решить проблему! {"protocol":5,"t":1687538023,"data":{"dps":{"1":false}},"cid":"a4xxxxxxxxxxx24"}){"protocol":5,"t":1687538023,"data":{"dps":{"1":false},"cid":"a4xxxxxxxxxxx24"}} для решения проблемы немного подправил код....пока работает вроде: в файле "custom_components/localtuya/pytuya/ init.py "


1373.        elif PARAMETER_DATA in json_data:
1374.                 json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
1375.             + if cid is not None:
1376.             +      json_data[PARAMETER_DATA][PARAMETER_CID] = cid**

я редактировал файл

        elif PARAMETER_DATA in json_data:
            json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
            #update from yakish777 
            if cid is not None:
                json_data[PARAMETER_DATA][PARAMETER_CID] = cid**
        else:
            json_data[PROPERTY_DPS] = data

и запрос на изменение ничего не меняется по-прежнему "протокол": 5, "t": 1688329377, "data": {"dps": {"1": false}}, "cid": "a4xxxxxxxxxxxxxxx26"

Что я делаю неправильно?

json_data[PARAMETER_DATA][PARAMETER_CID] = cid
NOT "**" I wanted to attract attention with them, but not to mislead in any way.....sorry

goodsale commented 1 year ago

@yakish777 @leeyuentuen

After the code change it works perfectly for me.

Tested with simple switches, with 2-output switch (dual gang) and dimmer (all Zigbee with tuya hub)

With the dimmers you can adjust the brightness which is impossible with the official tuya integration (that's what I was looking for!)

Really thanks!!

This is what I simply added as indicated:

        elif PARAMETER_DATA in json_data:
            json_data[PARAMETER_DATA] = {PROPERTY_DPS: data}
            #START - update from yakish777 
            if cid is not None:
                json_data[PARAMETER_DATA][PARAMETER_CID] = cid
            #END - update from yakish777 
        else:
            json_data[PROPERTY_DPS] = data
goodsale commented 1 year ago

For me works also with: smoke sensor water sensor gas sensor

I say goodbye to official integration.....

leeyuentuen commented 1 year ago

can you submit them in merge request?

viny182 commented 1 year ago

Hello,

I also confirm that the patch works, and for any further reference, the correct file to patch is actually "/config/custom_components/localtuya/pytuya/init.py", considering you are using the release *"3.7.0 Beta 10"**

You should add only the lines below after line 1378:

                #START - update from yakish777 
                if cid is not None:
                    json_data[PARAMETER_DATA][PARAMETER_CID] = cid
                #END - update from yakish777 

Here is a screenshot on how it should look like: image

leeyuentuen commented 1 year ago

create here a new tag: https://github.com/leeyuentuen/localtuya/releases/tag/3.7.0-beta.12

alexualbu commented 9 months ago

@viny182, @yakish777 very late comment, but would you be able to help confirm 2 things you can replace the patch with this one and it still works: change line 1366 to this json_data[PARAMETER_DATA][PARAMETER_CID] = cid

image