Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a valid local key #409

Closed
amddeus opened this issue May 11, 2023 · 37 comments · Fixed by #418
Closed

Not a valid local key #409

amddeus opened this issue May 11, 2023 · 37 comments · Fixed by #418
Assignees
Labels
bug Something isn't working

Comments

@amddeus
Copy link

amddeus commented May 11, 2023

Describe the bug
Iy9Ps(D;f*******, key for test (1024050068c63*******), is not a valid key.

To Reproduce
Steps to reproduce the behavior:
Reset the tuya device and use the new tuya local key from the tuya iot platform

Environment (please complete the following information):

  • OS: Mac OS

  • iOS version: 16.4.1

  • Homehubs: Homepod (new), Homepd mini, 2x Apple TV 4K2

  • Node Version: 18.16.0

  • Plugin Version: 2.0.1

  • Accessory Type: plug
    Config file:
    `

         "type": "Outlet",
         "name": "test",
         "id": "1024050068c63*******",
         "key": "Iy9Ps(D;f********",
         "manufacturer": "CSL"
    

`

Additional context
When using "old" key:

[5/11/2023, 1:42:12 PM] [homebridge-tuya] Discovered test (1024050068c63*******) identified as Outlet (3.3)
[Tuya] Changing ping gap for test to 9s
[Tuya DEBUG] reconnect called for test
[Tuya] Discovery ended.
[5/11/2023, 1:42:12 PM] [homebridge-tuya] Connected to test
[Tuya] Sending first query to test (3.3)
[Tuya] Odd message from test with command 10: \�J��q{?u���:f���G��#����~
[Tuya] Raw message from test (3.3) with command 10: 000055aa000000010000000a0000002c000000015ca24af9ae717b3f75f606a18e3a0c6697be8747ed1f7fbc23b092d510f1897e76eb92340000aa55
[Tuya DEBUG] decrementing this._connectionAttempts, currently 2
[Tuya DEBUG] decrementing this._connectionAttempts, currently 1

@amddeus amddeus added the bug Something isn't working label May 11, 2023
@skumancer
Copy link

Happening to me too since the new keys have been assigned by Tuya.

@doncarajo
Copy link

I have the exact same issue. New keys seem to be using special characters ("&", "^", etc) that I don't think the plug in likes. Any solutions?

@skumancer
Copy link

Fix is pretty easy, if you don't mind editing the plugin.

Assuming you're running homebridge on a docker instance:

  1. Go to docker/homebridge/node_modules/homebridge-tuya
  2. Open index.js and edit line 99 to comment out the whole if statement by using // before the if.

//if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

I can't guarantee this will always work, you're basically removing the checks on the device local key, so if they fail, or you enter it wrong, it may crash the process. It's up to you!

@doncarajo
Copy link

Thanks, that fixed it.

@amddeus
Copy link
Author

amddeus commented May 12, 2023

Yup that fixed it!

@amddeus amddeus closed this as completed May 12, 2023
@dibsies
Copy link

dibsies commented May 13, 2023

@skumancer you are an unwinged angel. Thank you so much, I’ve been pulling my hair out trying to figure this out. This worked perfectly.

Hopefully one day @iRayanKhan will find some time to implement a few of these important fixes.

@dibsies
Copy link

dibsies commented May 13, 2023

Also a note of reference for users who are using homebridge on Rasbian, the index.js file you need to edit to apply @skumancer's fix should be located in /usr/local/lib/node_modules/homebridge-tuya

@tmarigold
Copy link

@skumancer @dibsies would either of you know how I can make this change in HOOBS?

I'm good at following instructions, but I'm not particularly tech savvy (well, maybe for your average person, but not for the types that hang out on github!)

@GoanSausage
Copy link

Fix is pretty easy, if you don't mind editing the plugin.

Assuming you're running homebridge on a docker instance:

  1. Go to docker/homebridge/node_modules/homebridge-tuya
  2. Open index.js and edit line 99 to comment out the whole if statement by using // before the if.

//if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

I can't guarantee this will always work, you're basically removing the checks on the device local key, so if they fail, or you enter it wrong, it may crash the process. It's up to you!

Thank you! Worked perfectly

@leedoubleukay
Copy link

Fix is pretty easy, if you don't mind editing the plugin.

Assuming you're running homebridge on a docker instance:

  1. Go to docker/homebridge/node_modules/homebridge-tuya
  2. Open index.js and edit line 99 to comment out the whole if statement by using // before the if.

//if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

I can't guarantee this will always work, you're basically removing the checks on the device local key, so if they fail, or you enter it wrong, it may crash the process. It's up to you!

I'm running Homebridge on MacosX. Are you able to point me to where that particular file is? A search gives me a few hundred instances of index.js.

@weromemuero
Copy link

  1. docker/homebridge/node_modules/homebridge-tuya

Thanks a lot!! After a lot of adding and removing the bulb and also change it for another one i had lying around this fix the issue.

@purgethegabe
Copy link

hi, @leedoubleukay the specific path is: /usr/local/lib/node_modules/homebridge-tuya

(you need to show hidden folders, as it won't show up in the search)

@leedoubleukay
Copy link

@purgethegabe thank you!
I found my index.js at: /usr/local/.node/lib/node_modules/homebridge-tuya

@CaaioSB
Copy link

CaaioSB commented Jun 8, 2023

Fix is pretty easy, if you don't mind editing the plugin.

Assuming you're running homebridge on a docker instance:

  1. Go to docker/homebridge/node_modules/homebridge-tuya
  2. Open index.js and edit line 99 to comment out the whole if statement by using // before the if.

//if (!/^[0-9a-f]+$/i.test(device.key)) return this.log.error('%s, key for %s (%s), is not a valid key.', device.key.replace(/.{4}$/, '****'), device.name || 'unnamed device', device.id);

I can't guarantee this will always work, you're basically removing the checks on the device local key, so if they fail, or you enter it wrong, it may crash the process. It's up to you!

Works for me!

If do you don't know where is is your homebridge installation location, the default folders can be found here. Just select your SO and scroll down.

crux153 added a commit to crux153/homebridge-tuya that referenced this issue Jun 17, 2023
@MarkM500
Copy link

MarkM500 commented Jun 18, 2023

didn't worked for me. New started my synology with docker, but still: ***, key for Rolladen (xxxxxxxxxxxxxx), is not a valid key. Other ideas?
Thanks

@Akury83
Copy link

Akury83 commented Jun 29, 2023

@skumancer @dibsies would either of you know how I can make this change in HOOBS?

@tmarigold I use the plugin that this one is based on (Tuya Lan) in HOOBS. For me, I found the index.js file at /var/lib/hoobs/tuyalanbridge/node_modules/homebridge-tuya-lan/index.js

@fate8383
Copy link

fate8383 commented Jul 2, 2023

Genius! Banging my head on the wall all day and I found this...saved the device being thrown out of the window. Thanks a lot!

@AnonymousPea
Copy link

AnonymousPea commented Jul 4, 2023

Also a note of reference for users who are using homebridge on Rasbian, the index.js file you need to edit to apply @skumancer's fix should be located in /usr/local/lib/node_modules/homebridge-tuya

I tried this on mine and in the node_modules folder I can only find the Homebridge Tuya platform (the offical tuya one, which I use for other lights), feel like I've looked quite a few places and can't find the folder I need. Any help would be much appreciated?

@justerror
Copy link
Contributor

@AnonymousPea run in terminal sudo find / -type d -name 'homebridge-tuya'

@justerror
Copy link
Contributor

justerror commented Jul 7, 2023

@amddeus i created the PR, can you reopen this issue please? Cause now it's workaround, and it would be better if that fixed in repo and released.

@amddeus
Copy link
Author

amddeus commented Jul 17, 2023

@amddeus i created the PR, can you reopen this issue please? Cause now it's workaround, and it would be better if that fixed in repo and released.

👍

@amddeus amddeus reopened this Jul 17, 2023
@Raiden38
Copy link

Raiden38 commented Aug 3, 2023

Hi, any news on this? I tried the release and the beta version and the fix has not been applied. Any idea when it will be released? I tried the fix by skumancer and it does work well but wondering if we will see it in an official release soon :)
Thanks!

@RoboChopp
Copy link

RoboChopp commented Aug 6, 2023

Did this and the error went away (fix just disables the error message popup I think and allows connection process to continue) - looks the plugin isn't able to work with the different key format or a different encryption is being used for this bulb as I'm getting this error for a new Smart bulb (connected the same way as my previous 'older' bulbs) which I've called Basement stairs 1:

Socket had a problem and will reconnect to Basement stairs 1 (Error: ERR_PING_TIMED_OUT)

@jconsolatti
Copy link

Having the same issue with a Treatlife DS03 fanLight .. Debugging with tinytuya and it is failing as well ..

Seems the local_key formatting a recently changed and the parsing engines don't like some of the special characters .. Especially the "'".. Single quote for obvious reasons..

Seems the local_key changed and the underlying tooling / utilities / python modules haven't caught it.. Only thing I can think of is to readd the device and see if you get lucky on a a local_key string that doesn't cause by special characters..

Looking for a fix / workaround..

@jconsolatti
Copy link

Little python debugging and it seems to confirm the parsing issue..

Orginal and broken:

d = tinytuya.OutletDevice('12345eb1f71e050cetfww', '100.88.55.77', '12345%$A'hACm:ts')

Working:
local_key = "12345%$A'hACm:ts"

d = tinytuya.OutletDevice('12345eb1f71e050cetfww', '100.88.55.77', str(local_key))

@RoboChopp
Copy link

ahh, Nice work @jconsolatti ! Is this something that could be rolled into the code at some point?

@daviddr17
Copy link

For me the workaround to exclude the line as mentioned above is also not working. :( any other ideas or fixes?

@jconsolatti
Copy link

jconsolatti commented Aug 9, 2023 via email

@daviddr17
Copy link

@jconsolatti thanks for your reply. I get what you mean. Am I right that there is no option to change the tuya key manually?

@jconsolatti
Copy link

jconsolatti commented Aug 12, 2023 via email

@daviddr17
Copy link

@jconsolatti I had a closer look at the tuya developer platform, it seems not to be possible to change anything on the platform...

I just changed a few bulbs in my home, now half of it is working and half not...in my living room. Thats really annoying.

Do you have any other recommendations to control those bulbs locally via homekit? When using the official plugin there is always a delay when turning the lights on and off, so the local control was great..until now. :(

@jconsolatti
Copy link

@daviddr17 .. Given that the local_key is changed each time it is paired. I would try to pair it a couple times and see if you get lucky and get a random new local_key that doesn't include a special character that homebridge-tuya doesn't get tripped up on.. Might be a pain but, depending on how many devices you are having issues with might be worth it.. Also depends on how much heat you are taking from others in the house. I ran into the issue on the first of six and I am replacing a non-smart device. So I am currently no worse off and am actually better off as the DS3 switch doesn't generate nearly as much noise from ceiling fan motor than the switch it replaced..

I am working around it and making a little "knock off the rust of coding" project of my own out of it.. I will contribute whatever I can back based on my dev efforts..

@jconsolatti
Copy link

@daviddr17 Looks like you can make these changes locally while we wait for a release with the fixes .. https://github.com/iRayanKhan/homebridge-tuya/pull/418/files .. The cli-decode must be failing in the background..

@ayushsharma82
Copy link

This needs to be merged soon. +1

@fvalle1
Copy link

fvalle1 commented Nov 11, 2023

Commenting the line fixed for me!

@theriverlethe
Copy link

Also having this problem with a couple Feit bulbs I bought recently. I have them working fine in Home Assistant for now, but I'm hoping to move everything to Homebridge since I don't need most of HA.

@Lohengrin99
Copy link

Lohengrin99 commented Nov 24, 2023

Commenting the mentioned line worked well for me. Found the file on my Synology at /volume1/homebridge/node_modules/homebridge-tuya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.