Closed amddeus closed 10 months ago
Happening to me too since the new keys have been assigned by Tuya.
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?
Fix is pretty easy, if you don't mind editing the plugin.
Assuming you're running homebridge on a docker instance:
//
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!
Thanks, that fixed it.
Yup that fixed it!
@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.
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
@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!)
Fix is pretty easy, if you don't mind editing the plugin.
Assuming you're running homebridge on a docker instance:
- Go to docker/homebridge/node_modules/homebridge-tuya
- 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
Fix is pretty easy, if you don't mind editing the plugin.
Assuming you're running homebridge on a docker instance:
- Go to docker/homebridge/node_modules/homebridge-tuya
- 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.
- 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.
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)
@purgethegabe thank you! I found my index.js at: /usr/local/.node/lib/node_modules/homebridge-tuya
Fix is pretty easy, if you don't mind editing the plugin.
Assuming you're running homebridge on a docker instance:
- Go to docker/homebridge/node_modules/homebridge-tuya
- 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.
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
@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
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!
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?
@AnonymousPea run in terminal sudo find / -type d -name 'homebridge-tuya'
@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 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.
👍
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!
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)
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..
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))
ahh, Nice work @jconsolatti ! Is this something that could be rolled into the code at some point?
For me the workaround to exclude the line as mentioned above is also not working. :( any other ideas or fixes?
daviddr17,
It looks like from what I can tell and I am not even 5% clear on how homebridge is passing variables at this point.. While the ^^^ mentioned comment out line 99, prevents the error from being tossed. When it tries to pass the local_key with special characters, it is failing silently..
I debugged with tinytuya and had to force the local_key to be a string, so it would successfully login to the switch and could pull status / set a dP ..
Bottom Line: The homebridge-tuya plugin needs to be updated to handle the new local_key special characters / complex password before this is going to work, if your local_key is anything other than [a-f,0-9] at this point without making the change in homebridge/config/node_modules/homebridge-tuya/index.js:99 and getting past that doesn't mean the rest of the code can handle the special characters.. If I had a better understanding of the homebridge code, I would give it a shot myself. In my case there is a single quote in the local_key, that seems to be causing the problem, if it was just specials characters without the single quote, I have a feeling the line 99 fix would work.
index.js:99 - //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);^M
Example local_key that is failing: X6SE)%$A'hACm:ts
Cheers, JC
On Tue, Aug 8, 2023 at 4:02 PM daviddr17 @.***> wrote:
For me the workaround to exclude the line as mentioned above is also not working. :( any other ideas or fixes?
— Reply to this email directly, view it on GitHub https://github.com/iRayanKhan/homebridge-tuya/issues/409#issuecomment-1670424913, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT2DAFVH6D7IMBPV6N7BZEDXULAO5ANCNFSM6AAAAAAX6FGFFM . You are receiving this because you were mentioned.Message ID: @.***>
@jconsolatti thanks for your reply. I get what you mean. Am I right that there is no option to change the tuya key manually?
daviddr17,
That is an interesting question.. That I don't have an answer to currently. Definitely worth the effort to investigate.. Let me see if I can figure out a way to change the local_key.. Given that it changes during the app pairing process, it seems likely that it could be manipulated.. Thanks for the idea .. I have gone full rouge and am building some automation on a different platform that I will hook into homebridge via the http-accessory plugin.. Funny enough I am working with some network automation products and I am using my current struggles with the homebridge-tuya plugin as my dev project to figure things out.. Webhooks and Actions that call tinytuya to change the fan 0/1 / [1-4] and light 0/1 [0-100] ..
:0 - Coach ?? So you are saying there is a change ??
On Fri, Aug 11, 2023 at 5:29 PM daviddr17 @.***> wrote:
@jconsolatti https://github.com/jconsolatti thanks for your reply. I get what you mean. Am I right that there is no option to change the tuya key manually?
— Reply to this email directly, view it on GitHub https://github.com/iRayanKhan/homebridge-tuya/issues/409#issuecomment-1675565899, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT2DAFQPKYSXBYDNSK6TOX3XU3E7BANCNFSM6AAAAAAX6FGFFM . You are receiving this because you were mentioned.Message ID: @.***>
@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. :(
@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..
@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..
This needs to be merged soon. +1
Commenting the line fixed for me!
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.
Commenting the mentioned line worked well for me. Found the file on my Synology at /volume1/homebridge/node_modules/homebridge-tuya
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):
Plugin Version: 2.0.1
Accessory Type: plug Config file: `
`
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