The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit with Homebridge.
@switchbot/homebridge-switchbot
You can now configure global OpenAPI polling and rate-limiting options directly from the Homebridge UI:
Click Save Advanced Settings to apply changes. These settings match the options available in config.schema.json and can be overridden per device.
token to Clipboardtoken into the config parametersecret to Clipboardsecret into the config parameterdeviceIddeviceId into the Device Configbluetoothctl must be installed on the device, otherwise it cannot communicate via Bluetooth. Enable it with sudo bluetoothctl power on.
If errors occur, while enabling it, restart the process:
rfkill block bluetoothrfkill unblock bluetoothAlso make sure, that the computer can discover the SwitchBot device:
sudo bluetoothctlscan onThis lists all discovered Bluetooth devices. The BLE address of the SwitchBot device should be included in this list, otherwise your computer does not discover it.
Security & Privacy -> Privacy to the node executable, eg /usr/local/bin/node
(This is what is intended in documentation for the noble bluetooth package prerequisites by "Add terminal app", however for HomeBridge it is node that needs the permission granted, not terminal.
Without this step, then you will receive the following error when the swichbot plugin launches, which will cause Homebridge or the child bridge process to restart:Error: Failed to initialize the Noble object: unauthorized
at Noble.<anonymous> (file:///usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/src/switchbot.ts:244:19)
at Object.onceWrapper (node:events:629:26)
at Noble.emit (node:events:514:28)
at Noble.onStateChange (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/@stoprocent/noble/lib/noble.js:92:8)
at NobleMac.emit (node:events:514:28)
deviceId & deviceName to Device ConfigEnable Bluetooth Low Energy (BLE) Connection on Device ConfigdeviceId & deviceName to Device ConfigEnable Bluetooth Low Energy (BLE) Connection on Device ConfigdeviceId & deviceName to Device ConfigEnable Bluetooth Low Energy (BLE) Connection on Device ConfigdeviceId & deviceName to Device ConfigEnable Bluetooth Low Energy (BLE) Connection on Device ConfigOn or OffdeviceId & deviceName to Device ConfigEnable Bluetooth Low Energy (BLE) Connection on Device ConfigSome SwitchBot devices (notably newer locks, curtains, and select sensors) require a BLE encryption key and keyId for secure Bluetooth communication. This plugin supports configuring these fields for each device.
In the Homebridge UI, when adding or editing a SwitchBot device, enter the Encryption Key and Key ID in the provided fields. These values will be securely used for BLE communication with your device.
Example device config excerpt:
{
"deviceId": "E7F8A1B2C3D4",
"deviceName": "SwitchBot Lock",
"enableBLE": true,
"encryptionKey": "0123456789abcdef0123456789abcdef",
"keyId": "01"
}
If you are unsure, check your device's info in the SwitchBot app. If the fields are present, copy them into the plugin config.
Note: If you enter an incorrect key or keyId, BLE communication will fail for that device. Double-check values if you encounter connection issues.
By default, the Matter platform uses a single batched refresh to update device status. You can tune or override this behavior with the following options under options:
matterBatchEnabled (boolean, default true): enable/disable platform-level batched refresh. Devices with a per-device refreshRate still run their own timers.matterBatchRefreshRate (number, seconds): batch interval (falls back to options.refreshRate, then 300 if not set).matterBatchConcurrency (number): limit of parallel OpenAPI status calls during a batch (default 5).matterBatchJitter (number, seconds): random startup delay before the first batch to reduce synchronized spikes.Device-level override:
refreshRate in its config, it uses a per-device timer and is excluded from the platform batch.Reliability and rate-limiting:
These controls keep API usage smooth and predictable while preserving per-device control when needed.
Matter-first: when Homebridge Matter is available the plugin now prefers registering Matter accessories (with HAP fallback).
Hybrid client: the plugin uses node-switchbot@^4.0.0 with BLE + OpenAPI discovery and OpenAPI fallback.
OpenAPI credentials: cloud discovery and cloud fallback paths require both openApiToken and openApiSecret.
UI always served: the plugin UI is packaged into dist/homebridge-ui and is always served when Homebridge UI support is present; there is no platform-level opt-out.
OpenAPI hardening: OpenAPI calls have AbortController timeouts, jittered exponential backoff, per-device retry limits and cooldowns, and safe response parsing for resilient behavior.
v4 resilience enabled in discovery: plugin discovery enables retry, circuit-breaker, and connection-intelligence flags from node-switchbot v4.
Write coalescing (debounce): command writes to the same device are coalesced by default to avoid command floods. Configure with writeDebounceMs (milliseconds, default 100). Set to 0 to disable coalescing.
See MIGRATION.md for migration notes and recommended upgrade steps.
To prevent hitting SwitchBot’s daily OpenAPI limit, the plugin provides several platform-level options under options:
dailyApiLimit (number, default 10000): maximum OpenAPI requests per day that the plugin will allow.dailyApiReserveForCommands (number, default 1000): requests reserved for user actions so background polling pauses before the hard limit.webhookOnlyOnReserve (boolean, default false): when remaining budget reaches the reserve, pause background polling/discovery; webhooks and commands continue until the hard limit.dailyApiResetLocalMidnight (boolean, default false): if true, resets the daily counter at local midnight; when false, resets at UTC midnight.Example (excerpt):
{
"options": {
"dailyApiLimit": 10000,
"dailyApiReserveForCommands": 1000,
"webhookOnlyOnReserve": false,
"dailyApiResetLocalMidnight": true
}
}
Run unit tests:
npm run test
Notes:
node-switchbot v4.