homebridge-switchbot
homebridge-switchbot copied to clipboard
BUG: [SwitchBot] Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500
Describe the Bug
When attempting to interact with WoIOSensor (Kitchen Sensor) and Smart Lock (LightBolt) devices using the homebridge-switchbot plugin, I receive an "Internal Server Error" with a status code of 500. Additionally, an "Unknown statusCode: undefined" error is logged. This suggests an unexpected error on the SmartThings servers.
To Reproduce
- Install and configure the homebridge-switchbot plugin.
- Add WoIOSensor (Kitchen Sensor) and Smart Lock (LightBolt) devices to the configuration.
- Observe the error logs when Homebridge attempts to interact with these devices.
Expected Behavior
The plugin should successfully interact with the WoIOSensor and Smart Lock devices without encountering server errors.
Relevant Log Output
[4/7/2024, 12:10:02 AM] [SwitchBot] WoIOSensor: Kitchen Sensor Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500
[4/7/2024, 12:10:02 AM] [SwitchBot] WoIOSensor: Kitchen Sensor Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug
[4/7/2024, 12:10:13 AM] [SwitchBot] Smart Lock: LightBolt Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500
[4/7/2024, 12:10:13 AM] [SwitchBot] Smart Lock: LightBolt Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug
[4/7/2024, 12:25:15 AM] [SwitchBot] Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500
[4/7/2024, 12:25:15 AM] [SwitchBot] Unknown statusCode, statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug
Config for homebridge-switchbot
{
"name": "SwitchBot",
"credentials": {
"token": "REDACTED",
"secret": "REDACTED",
"notice": "Keep your Token & Secret a secret!"
},
"options": {
"devices": [
{
"deviceId": "REDACTED",
"configDeviceName": "Kitchen Sensor",
"hide_device": false,
"configDeviceType": "WoIOSensor",
"connectionType": "OpenAPI",
"webhook": true,
"lock": {
"activate_latchbutton": false
},
"history": true,
"firmware": "0.4",
"external": true
},
{
"deviceId": "REDACTED",
"configDeviceName": "LightBolt",
"hide_device": false,
"configDeviceType": "Smart Lock",
"connectionType": "OpenAPI",
"webhook": true,
"lock": {
"activate_latchbutton": false
},
"firmware": "2.1.1",
"refreshRate": 20,
"external": false,
"logging": "standard"
},
{
"deviceId": "REDACTED",
"configDeviceName": "LightHub 2",
"hide_device": true,
"lock": {
"activate_latchbutton": false
}
}
],
"refreshRate": 60
},
"_bridge": {
"username": "REDACTED,"
"port": REDACTED
},
"platform": "SwitchBot"
}
Screenshots
No response
Device and Model
Outdoor Thermohygrometer, SmartLock
Node.js Version
v20.12.1
NPM Version
v10.5.0
Homebridge Version
v1.7.0
Homebridge Switchbot Plugin Version
v3.4.0
Homebridge Config UI X Plugin Version
v4.56.1
Operating System
macOS
Just adding a +1 to this - seeing the same thing in my instance. Let me know if there are any helpful details I can provide.
Sorry nothing I can do about this. This is all the SwitchBot API. SwitchBot will have to resolve this.
And no I don't work for switchBot, I just manage this plugin.
I just updated to 3.4.0 from 2.12.1 and had this error. I rolled back to 2.12.1 and things are fine again.
I see a ton of these and my blinds do not operate reliably anymore:
Maybe a backoff/retry loop in there?
[4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 1 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 1 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 2 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 2 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 3 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 3 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 4 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:19:34 AM] [SwitchBot] Blind Tilt: Blind 4 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:19:54 AM] [HttpWebHooks] Change HomeKit value for temperature sensor to '25.625'. [4/30/2024, 6:19:58 AM] [Lutron] Button /button/178 on Pico remote Jeremy office Controller Pico got action Press [4/30/2024, 6:19:58 AM] [Lutron] Button /button/178 on Pico remote Jeremy office Controller Pico got action Release [4/30/2024, 6:19:59 AM] [Lutron] button /button/178 got a short press [4/30/2024, 6:20:02 AM] [HttpWebHooks] Change HomeKit value for temperature sensor to '20.013'. [4/30/2024, 6:20:03 AM] [HttpWebHooks] Change HomeKit value for humidity sensor to '49.95829564303247'. [4/30/2024, 6:20:03 AM] [HttpWebHooks] Change HomeKit value for temperature sensor to '19.910'. [4/30/2024, 6:20:03 AM] [HttpWebHooks] Change HomeKit value for humidity sensor to '92.4650363188'. [4/30/2024, 6:20:07 AM] [HttpWebHooks] Change HomeKit value for humidity sensor to '25.73'. [4/30/2024, 6:20:31 AM] [SwitchBot] Blind Tilt: Blind 1 Checking Status ... [4/30/2024, 6:20:33 AM] [SwitchBot] Blind Tilt: Blind 2 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:20:33 AM] [SwitchBot] Blind Tilt: Blind 2 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:20:34 AM] [HttpWebHooks] Change HomeKit value for temperature sensor to '25.5625'. [4/30/2024, 6:20:34 AM] [SwitchBot] Blind Tilt: Blind 2 Checking Status ... [4/30/2024, 6:20:36 AM] [SwitchBot] Blind Tilt: Blind 4 Checking Status ... [4/30/2024, 6:20:48 AM] [SwitchBot] Blind Tilt: Blind 2 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:20:48 AM] [SwitchBot] Blind Tilt: Blind 2 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:20:54 AM] [SwitchBot] Blind Tilt: Blind 1 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:20:54 AM] [SwitchBot] Blind Tilt: Blind 1 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:20:54 AM] [SwitchBot] Blind Tilt: Blind 1 Checking Status ... [4/30/2024, 6:20:56 AM] [SwitchBot] Blind Tilt: Blind 2 Internal Server Error, An unexpected error on the SmartThings servers has occurred. These errors should be rare, statusCode: 500 [4/30/2024, 6:20:56 AM] [SwitchBot] Blind Tilt: Blind 2 Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug [4/30/2024, 6:21:01 AM] [HttpWebHooks] Change HomeKit value for temperature sensor to '20.018'. [4/30/2024, 6:21:01 AM] [HttpWebHooks] Change HomeKit value for humidity sensor to '49.807790798316574'.
I just updated to 3.4.0 from 2.12.1 and had this error. I rolled back to 2.12.1 and things are fine again.
I am thinking about rolling back as well. Maybe older version of this plugin is using an older version of Switchbot API?
The alternate option I suppose is to look at the new Switchbot Hub that supports Matter
The alternate option I suppose is to look at the new Switchbot Hub that supports Matter
I bought the new Hub when it was released specifically for this purpose, but it's unfortunately useless for me because the Switchbot Bots / Button Pushers will only show up in HomeKit (through Matter) as a Light Switch. So it defeats the whole purpose of the Bot and the different types of Press States etc. Switchbot says it's a Matter limitation right now.
I just updated to 3.4.0 from 2.12.1 and had this error. I rolled back to 2.12.1 and things are fine again.
I am thinking about rolling back as well. Maybe older version of this plugin is using an older version of Switchbot API?
I just rolled back from 3.4.0 to 2.12.1 and I now have access to my tilt blinds again. I thought it might be a hangup from switching from a docker(container) instance of homebridge to native on DS7, but it seems that's coincidental timing
I tried 2.12.1 and see the same lack of errors and better reliability.... of what its worth
Thank you very much y'all, 2.12.1 also saved my bacon.
Reverting to v3.1.3 also worked for me. After reverting the errors disappeared and IR worked again.
For what it's worth, I reverted to 2.12.1 and I'm still seeing the 500 error with my SwitchBot curtains. Only getting it when attempting to change state (i.e. open/close). I get 200s back when polling their status. Seems to just be my curtains though- I have a SwitchBot which has been working fine despite the curtain issue.
[5/2/2024, 4:39:36 AM] [SwitchBot] [DEBUG] Curtain: Curtains deviceStatus: {"message":"Internal server error"}
[5/2/2024, 4:39:36 AM] [SwitchBot] [DEBUG] Curtain: Curtains deviceStatus body: undefined
[5/2/2024, 4:39:36 AM] [SwitchBot] [DEBUG] Curtain: Curtains deviceStatus statusCode: undefined
[5/2/2024, 4:39:36 AM] [SwitchBot] Curtain: Curtains Unknown statusCode: 500, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug
[5/2/2024, 4:39:36 AM] [SwitchBot] Curtain: Curtains Unknown statusCode: undefined, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug
Edit: Also reset my developer token from the app and no dice.
I also reverted to 2.12.1 and I'm still seeing the 500 error with my Smart Lock Series 1.
This is an issue directly with Switchbot API v1.1. I've tested it myself on Postman and I saw the same 500 status code.
I did the same test on Switchbot API v1.0 and that seemed to be working. Haven't received any 500 status code but I did not test it that much since I have Curtain 3 and it only works with Switchbot API v1.1 What I saw was if you try to do the request again after a while it succeeds. So I implemented a retry mechanism myself and it worked. Received status code 100 after several tries.
Nice @sametguzeldev, would you be willing to submit a PR?
I am not a typescript expert at all 😄 I only changed it for Curtain device and modified openAPIRefreshStatus method just to test the theory. I think it would be better if we can wrap the request function completely and handle this retry mechanism directly inside the request and put maximumRetry and delayBetweenRetries inside config settings or something. Here is the code that I modified. But this is a bad practice to apply one by one to all devices and all openApi methods.
async openAPIRefreshStatus(): Promise<void> {
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
let retryCount = 0;
const maxRetries = 5; // Maximum number of retries
const delayBetweenRetries = 5000; // Delay between retries in milliseconds
while (retryCount < maxRetries) {
try {
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
headers: this.platform.generateHeaders(),
});
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
const deviceStatus: any = await body.json();
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
this.OpenAPI_CurrentPosition = deviceStatus.body.slidePosition;
this.OpenAPI_InMotion = deviceStatus.body.moving;
this.OpenAPI_CurrentAmbientLightLevel = deviceStatus.body.brightness;
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
this.openAPIparseStatus();
this.updateHomeKitCharacteristics();
break;
} else {
this.statusCode(statusCode);
this.statusCode(deviceStatus.statusCode);
if (statusCode === 500) {
retryCount++;
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName}statusCode: ${statusCode} Attempt ${retryCount} of ${maxRetries}`);
await sleep(delayBetweenRetries);
}
}
} catch (e: any) {
retryCount++;
this.apiError(e);
this.errorLog(
`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}` +
` Connection, Error Message: ${JSON.stringify(e.message)}`,
);
}
}
}
Thanks, I will see what I can do
@donavanbecker Since I saw every device has access to platform, I wrote this function to platform.ts file. (logs can be removed) For some reason when I build the library locally, the plugin's config does not open for me visually so I put maxRetries and delayBetweenRetries inside this function. I am also making it retry even if an error happens, maybe we could just break the loop there as well.
async retryRequest(url: string | URL | UrlObject,
options?: { dispatcher?: Dispatcher } & Omit<Dispatcher.RequestOptions,
'origin' | 'path' | 'method'> & Partial<Pick<Dispatcher.RequestOptions, 'method'>>): Promise<{ body: any; statusCode: number }> {
let retryCount = 0;
const maxRetries = 5; // Maximum number of retries
const delayBetweenRetries = 3000; // Delay between retries in milliseconds
while (retryCount < maxRetries) {
try {
const { body, statusCode } = await request(url, options);
if (statusCode === 200 || statusCode === 100) {
return { body, statusCode };
} else {
this.debugLog(`Received status code: ${statusCode}`);
}
} catch (error: any) {
this.errorLog(`Error making request: ${error.message}`);
}
retryCount++;
this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`);
await sleep(delayBetweenRetries);
}
return { body: null, statusCode: -1 };
}
then I made all devices to call this method. For example for openAPIRefreshStatus, it became from
const { body, statusCode } = await request(`${Devices}/${this.device.deviceId}/status`, {
headers: this.platform.generateHeaders(),
});
to
const { body, statusCode } = await this.platform.retryRequest(`${Devices}/${this.device.deviceId}/status`, {
headers: this.platform.generateHeaders(),
});
I'll be running it like this on my environment for now. Maybe this could give you some kind of idea to how to implement it better.
Thanks @sametguzeldev, I have added this to the latest beta. maxRetries and delayBetweenRetries are both customizable in the config.
I've been getting these unknown statuscode errors constantly across all my devices (meters, curtains, etc.) on v3.4.0. (had opened a separate issue a while ago). The latest beta V3.5.0-beta22 seems to have fixed it.
Thanks!
Been following this for a while. Thanks for the input and progress so far! The 500 errors are now gone. However, after updating to the newest beta’s .22 and .23 my curtains are unresponsive.
Fresh install from 3.4.0 will detect the hub mini and curtains after inputting token with intermittent issues and 500 errors
Updating from 3.4.0 to the beta’s results in the curtains being unresponsive.
Fresh beta install .22 and .23 will not detect the hub mini and curtains
Same for me with the Smart Lock. The 500 errors are solved, but newest betas .22 and .23 cause the Lock to become entirely unresponsive. Similar troubleshooting re: version installations yields the same result. Fresh install from 3.4.0 will detect the hub mini and curtains after inputting token with intermittent issues and 500 errorsUpdating from 3.4.0 to the beta’s results in the curtains being unresponsive.Fresh beta install .22 and .23 will not detect the hub mini and curtainsOn May 7, 2024, at 3:27 AM, Ave87 @.***> wrote: Been following this for a while. Thanks for the input and progress so far! The 500 errors are now gone. However, after updating to the newest beta’s .22 and .23 my curtains are unresponsive. Fresh install from 3.4.0 will detect the hub mini and curtains after inputting token with intermittent issues and 500 errors Updating from 3.4.0 to the beta’s results in the curtains being unresponsive. Fresh beta install .22 and .23 will not detect the hub mini and curtains
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
I am not using the latest beta. I am still using my own solution and I can confirm my Smart Lock and my Curtain 3 are still working. If you want @donavanbecker I can install the beta version and see how it interacts with my devices? I can enable debug and check it out.
500 errors gone, but curtains unresponsive on the latest betas as ave87 posted.
I am not using the latest beta. I am still using my own solution and I can confirm my Smart Lock and my Curtain 3 are still working. If you want @donavanbecker I can install the beta version and see how it interacts with my devices? I can enable debug and check it out.
Yes please
500 errors gone, but curtains unresponsive on the latest betas as ave87 posted.
Do you have logs?
Yes. Logs attached. I've enabled debug logging. Logs don't seem to show much. Not only are my curtains unresponsive, but even my meters don't seem to be updating.
@switchbot_homebridge-switchbot.log (1).txt
Yes. Logs attached. I've enabled debug logging. Logs don't seem to show much. Not only are my curtains unresponsive, but even my meters don't seem to be updating. @switchbot_homebridge-switchbot.log (1).txt
I think you need to run it for a while for it to trigger openAPIRefreshStatus and also try execute some stuff on the curtain. If this log is sent after you've tried to execute some stuff on the curtain device, than the request is not going through at all
From my testing, sometimes even 5 tries are not enough. (Max tries = 5, delay = 3 seconds)
This is from my own solution. I'll try the beta now.
@donavanbecker I can confirm nothing is responding. I don't see any request log to anything in debug mode when using the latest beta.