misenhower / homebridge-wyze-connected-home

Wyze Connected Home plugin for Homebridge
MIT License
70 stars 52 forks source link

On Raspberry Pi, long restart processes causes 2FA code to expire #11

Open seecoolguy opened 4 years ago

seecoolguy commented 4 years ago

Hi,

This plugin works pretty awesome, so thank you. I don't know what a good polling interval should be since 5 seconds seems way too long for motion sensors for automation tasks.

When I first tried setting up the Wyze plugin when I have 2FA turned on, the homebridge on raspberry pi 1 restarts really slow, almost 2 minutes before I see the log and my 2FA is expired by then. This causes my login to get locked due to failed attempts because the pin is now no longer valid.

I suppose a solution would be to get a CPU cooler for the raspberry PI and overclock it.

[6/17/2020, 9:28:44 AM] [HB Supervisor] Sending SIGTERM to Homebridge [6/17/2020, 9:28:44 AM] Got SIGTERM, shutting down Homebridge... [6/17/2020, 9:28:50 AM] [HB Supervisor] Homebridge Process Ended. Code: 143, Signal: null [6/17/2020, 9:28:55 AM] [HB Supervisor] Restarting Homebridge... [6/17/2020, 9:28:55 AM] [HB Supervisor] Starting Homebridge with extra flags: -I [6/17/2020, 9:28:55 AM] [HB Supervisor] Started Homebridge v1.1.0 with PID: 3311 [6/17/2020, 9:29:27 AM] Loaded config.json with 0 accessories and 3 platforms. [6/17/2020, 9:29:28 AM] --- [6/17/2020, 9:30:01 AM] Loaded plugin: homebridge-config-ui-x@4.22.0 [6/17/2020, 9:30:01 AM] Registering platform 'homebridge-config-ui-x.config' [6/17/2020, 9:30:01 AM] --- [6/17/2020, 9:30:01 AM] Loaded plugin: homebridge-delay-switch@2.1.2 [6/17/2020, 9:30:01 AM] Registering accessory 'homebridge-delay-switch.DelaySwitch' [6/17/2020, 9:30:01 AM] --- [6/17/2020, 9:30:07 AM] Loaded plugin: homebridge-platform-wemo@1.5.6 [6/17/2020, 9:30:07 AM] Registering platform 'homebridge-platform-wemo.BelkinWeMo' [6/17/2020, 9:30:07 AM] --- [6/17/2020, 9:30:07 AM] Loaded plugin: homebridge-wyze-connected-home@0.5.1 [6/17/2020, 9:30:08 AM] Registering platform 'homebridge-wyze-connected-home.WyzeConnectedHome' [6/17/2020, 9:30:08 AM] --- [6/17/2020, 9:30:08 AM] Loading 3 platforms... [6/17/2020, 9:30:08 AM] [Config] Initializing config platform... [6/17/2020, 9:30:09 AM] [Config] Running in Service Mode [6/17/2020, 9:30:09 AM] [Wyze] Initializing WyzeConnectedHome platform...

pjotal commented 4 years ago

hi @seecoolguy, sorry for the late response. i've been busy with other stuff. indeed homebridge is pretty CPU intensive in its boot and on limited hardware like a raspberry pi it can take longer to start to the point that your wyze 2FA pin is no longer valid. this can also be the case for people who has tons of plugins and devices plugged to homebridge.

here are two a workarounds i suggest you try. WORKAROUND 1:

  1. stop the homebridge service
  2. open your config.json and be ready to type your 2FA pin as soon as it changes (so you maximize the time it's valid)
  3. start the homebridge service via command line in debug mode
  4. check in the logs if the authentication was made successufly. if so, problem solved. otherwise, try the next approach.

NOTE 1: i noticed that restarting the service via the config ui can take much longer than via command line. NOTE 2: it could be that due to your hardware limitation your pin changes again before your wyze authentication is done. if so, try the next approach which is a little more hard core.

WORKAROUND 2

  1. stop your homebridge
  2. make a copy of your config.json and save it somewhere. you'll need it again in the last step
  3. open your config.json and remove all other platforms and accessories leaving just the wyze one (we want to make sure that homebridge has nothing else but this to do)
  4. type your 2FA pin as soon as it changes (so you maximize the time it's valid)
  5. start the homebridge service via command line in debug mode
  6. check in the logs if the authentication was made successufly. if so, problem solved. otherwise, sorry buddy but your hardware is not fast enough so you make the cut for 2FA and there is nothing else we can do to help :(
  7. stop homebridge
  8. bring back your original config.json with all other platforms and accessories (the pin is no longer relevant as next time we'll reuse your authentication token instead)
  9. start homebridge

NOTE 1: once you authenticate with 2FA once, a token is generated and we'll reuse it from that time on so you don't need to mind using the pin everytime you need to restart homebridge. clever, right?

i hope one of those solve your problem. if not and you're ok dropping the 2FA in favour or the integration with homebridge, your hardware limitation won't be a problem as you won't be limited to those 20-30 seconds.

best regards. let us know if it worked :) we wish you luck!

seecoolguy commented 4 years ago

Thanks I’ll try these steps to see if i can beat the clock

town3r commented 4 years ago

Needed to disable 2FA until I can get an updated Pi that is fast enough to boot up within 20-30 seconds.

You might be able to copy what they did w/ the homebridge-ring plugin during the authentication step of the setup process

https://github.com/dgreif/ring/tree/master/homebridge

sirloon commented 1 year ago

It's 2022, almost 2023, not sure if what I'm doing is relevant, but this is what I did to fix the same issue (running on a Pi Zero W, takes too long, MFA code expires). The idea is to manually fetch and store the access/refresh tokens. I used python wyze_sdk.

We need to store these tokens in the wyze persist file. It's somewhere in ~pi/.homebridge/persist/ and looks like wyze-....json. Edit the JSON file, replace the access_token by what you got in client._token, same for the refresh one, save, restart the bridge. It should work.