homebridge-tuya-web: After long uptime no longer able to control devices until hoobs restarted

Describe the bug After weeks of consistent uptime, I will be unable to control my devices until I restart hoobs. In the log, I see this error: 11/11/2020, 4:26:02 PM [TuyaWebPlatform] [Bistro Lights] - Unsetting debouncedDeviceStateRequestPromise 11/11/2020, 4:26:02 PM [TuyaWebPlatform] [Bistro Lights] - [GET] No valid token 11/11/2020, 4:26:02 PM [TuyaWebPlatform] [House Christmas Lights] - Unsetting debouncedDeviceStateRequestPromise 11/11/2020, 4:26:02 PM [TuyaWebPlatform] [House Christmas Lights] - [GET] No valid token

And after restarting I get normal operation and see

11/11/2020, 4:26:03 PM [TuyaWebPlatform] [Bistro Lights] - Requesting device state 11/11/2020, 4:26:03 PM [TuyaWebPlatform] [Bistro Lights] - Creating new debounced promise 11/11/2020, 4:26:03 PM [TuyaWebPlatform] [Bistro Lights] - Triggering debouncedDeviceStateRequest

Steps To Reproduce Obviously difficult to reproduce given the long uptime. I’m happy to throw in some debug statements or something and update when it happens again

Plugin Version 0.4.8

Homebridge Config

{
   "server": {
       "port": 8585,
       "origin": "*",
       "autostart": 15,
       "home_setup_id": "redacted",
       "polling_seconds": 5
   },
   "client": {
       "default_route": "status",
       "inactive_logoff": 30,
       "theme": "hoobs-dark",
       "locale": "en",
       "temp_units": "fahrenheit",
       "country_code": "US",
       "postal_code": "redacted",
       "latitude": "redacted",
       "longitude": "redacted"
   },
   "bridge": {
       "name": "HOOBS",
       "port": 51826,
       "pin": "redacted",
       "username": "redacted"
   },
   "description": "",
   "ports": {},
   "accessories": [
       {
           "accessory": "PurpleAir",
           "purpleID": 5,
           "updateFreq": 90,
           "name": "PurpleAir Air Quality",
           "plugin_map": {
               "plugin_name": "homebridge-purpleair",
               "index": 0
           }
       },
       {
           "accessory": "Chamberlain",
           "plugin_map": {
               "plugin_name": "homebridge-chamberlain",
               "index": 0
           },
           "name": "Garage Door",
           "username": "redacted",
           "password": "redacted",
           "deviceId": "redacted"
       }
   ],
   "platforms": [
       {
           "platform": "TuyaWebPlatform",
           "plugin_map": {
               "plugin_name": "homebridge-tuya-web"
           },
           "name": "TuyaWebPlatform",
           "scenes": false,
           "options": {
               "platform": "smart_life",
               "username": "redacted",
               "password": "redacted",
               "countryCode": "1"
           }
       }
   ]
}

Device Config

Getting credentials Got credentials { ‘access_token’: ‘AZhaz1575155944565PvF8vZqSW8yaPyt’, ‘expires_in’: 864000, ‘refresh_token’: ‘AZhaz1575155944565PvF8vWxktsTlBjR’, ‘token_type’: ‘bearer’} Getting devices Got devices { ‘header’: {‘code’: ‘SUCCESS’, ‘payloadVersion’: 1}, ‘payload’: { ‘devices’: [ { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d244ec_1’, ‘name’: ‘Front Yard Christmas Tree’}, { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d244ec_2’, ‘name’: ‘Switch 2’}, { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d24305_1’, ‘name’: ‘Garage Christmas Lights’}, { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d24305_2’, ‘name’: ‘Switch 2’}, { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d242d7_1’, ‘name’: ‘Trellis Christmas Lights’}, { ‘data’: {‘online’: False, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d242d7_2’, ‘name’: ‘Switch 2’}, { ‘data’: {‘online’: True, ‘state’: True}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d23963_1’, ‘name’: ‘House Christmas Lights’}, { ‘data’: {‘online’: True, ‘state’: False}, ‘dev_type’: ‘switch’, ‘ha_type’: ‘switch’, ‘icon’: ‘https://images.tuyaus.com/smart/icon/1511839633_0.png’, ‘id’: ‘37677666600194d23963_2’, ‘name’: ‘Bistro Lights’}], ‘scenes’: []}}

Additional Context

Happy to help debug on this

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (6 by maintainers)

Most upvoted comments

Tuya uses so called “access tokens”. I use your username and password to request one of these access tokens from the tuya server. Whenever I want to do something with your devices, I need to send the access token along to ensure tuya that the request is coming from the owner of the device.

These access-tokens are valid for… you guessed it… 10 days.

Previous versions of this library used to request a new token after just under 10 days to ensure that you always have a fresh token. Somewhere in a code change; that code that refreshes the token got removed by me (don’t ask me why 😛, I don’t know) and thus your token won’t be valid after 10 days and you get the error.

I once again added some code that refreshes your token after 9 days and 23 hours to ensure that you once more always have a fresh token.

And this is now released in pre-release version 0.5.4.

If you want to; you can update to this pre-release.

Please let me know if you have any issues!

  1. Stop HOOBS
  2. Run these commands in the terminal
cd ~/.hoobs/
npm install @milo526/homebridge-tuya-web@0.5.4
  1. Restart HOOBS