rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.83k stars 545 forks source link

Failed to add lights to integration. #303

Open szbbalint opened 3 years ago

szbbalint commented 3 years ago

Hi guys, firs i wish you a happy new year :) So my problem is that i cant add my devices to hassio with localtuya. I have 4 pcs martin jerry 3 way dimmer (not switch), they runing the latest firmware according to the tuya smart app. I have received the key and id pairs for each devices (with tuyacli). Installed localtuya in hacs, restart, then im trying to instal the localtuya integration. A window with a list of my devices with the correct IP adresses appear, i selected one of them (tried all of them), and then i named it "Folyosó" (its like hallway in my language, but i think it doesnt matter), copypaste the local key (1ffk56d065e19108 it looks like this), the host and the device id is already filled out with the correct value. Then i select the protocol, first i try with the 3.3, then i got this erroe: ----Failed to authenticate with device. Verify that device id and local key are correct.----- im really sure that the device id and the key is correct, then i try with protocol 3.1, with this error: -----An unknown error occurred. See log for details.---- and the logs (ther are thrre of them)

Traceback (most recent call last): File "/config/custom_components/localtuya/pytuya/init.py", line 510, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 457, in exchange payload = self._decode_payload(msg.payload) File "/config/custom_components/localtuya/pytuya/init.py", line 544, in _decode_payload payload = self.cipher.decrypt(payload, False) File "/config/custom_components/localtuya/pytuya/init.py", line 196, in decrypt return self._unpad(decryptor.update(enc) + decryptor.finalize()).decode() File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/ciphers/base.py", line 164, in finalize data = self._ctx.finalize() File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/ciphers.py", line 181, in finalize raise ValueError( ValueError: The length of the provided data is not a multiple of the block length.

Traceback (most recent call last): File "/config/custom_components/localtuya/pytuya/init.py", line 510, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 457, in exchange payload = self._decode_payload(msg.payload) File "/config/custom_components/localtuya/pytuya/init.py", line 554, in _decode_payload raise Exception(f"Unexpected payload={payload}") Exception: Unexpected payload=b'json obj data unvalid'

Traceback (most recent call last): File "/config/custom_components/localtuya/config_flow.py", line 279, in async_step_basic_info self.dps_strings = await validate_input(self.hass, user_input) File "/config/custom_components/localtuya/config_flow.py", line 192, in validate_input detected_dps = await interface.detect_available_dps() File "/config/custom_components/localtuya/pytuya/init.py", line 510, in detect_available_dps data = await self.status() File "/config/custom_components/localtuya/pytuya/init.py", line 472, in status status = await self.exchange(STATUS) File "/config/custom_components/localtuya/pytuya/init.py", line 457, in exchange payload = self._decode_payload(msg.payload) File "/config/custom_components/localtuya/pytuya/init.py", line 554, in _decode_payload raise Exception(f"Unexpected payload={payload}") Exception: Unexpected payload=b'json obj data unvalid'

And if i trying to add it manually in config.yaml, tha entiti does not work... no matter what parameters i have added in the config...

Im a bit nervous because of this, i think its a minor and easy problem but i cant figure it out. Is there anybody who can help me? Thank you :)

postlund commented 3 years ago

1ffk56d065e19108 is not a correct key, it's supposed to be hex only. Looks more like a product key to me. You should try extracting the key again, with whatever method you used.

szbbalint commented 3 years ago

i used tha tuyapi method (described in a link on localtuya github page) and gave me the same keys now... [ { name: 'Előszoba', id: 'bf448ea23275de725xxxxx', key: '0a77fe802bexxxxx' }, { name: 'Nappali', id: 'bf9706cdbd2406eexxxxx', key: '8ffc31c065dxxxx' }, { name: 'Folyosó ', id: 'bf73ac885f36a5c8cxxxxx', key: 'b1914e7bb4xxxxx' }, { name: 'Hálószoba ', id: 'bf76482f3c2783714xxxxx', key: '3e1b14207a0xxxxx' } ]

postlund commented 3 years ago

The key you pasted above contained a k though, which is not a valid key. The json obj data unvalid is something we see every now and then, not sure the reason for that. Currently I don't think we have a solution for it. With the correct config, it might work when being set up from YAML. But it's a bit tricky without the DP list. What did you try and what error did you get?

szbbalint commented 3 years ago

i wrote the k when i changed some letters and numbers in the key...