OpenWonderLabs / homebridge-switchbot

The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit. Homebridge.
https://openwonderlabs.github.io/homebridge-switchbot/
ISC License
239 stars 51 forks source link

Plugin crashes if BLE is enabled on Curtain 3 #952

Closed harrisbooks closed 2 months ago

harrisbooks commented 6 months ago

Describe Your Problem

Hello. If I set the connection type of my Curtain 3 to BLE or BLE/OpenAPI, the plugin continuously crashes while starting. The plugin is running on a 2023 Mac Mini.

Relevant log output

[3/12/2024, 11:37:45 AM] [SwitchBot] Launched child bridge with PID 79080
[3/12/2024, 11:37:45 AM] Registering platform '@switchbot/homebridge-switchbot.SwitchBot'
[3/12/2024, 11:37:45 AM] [SwitchBot] Loaded @switchbot/homebridge-switchbot v3.4.0 child bridge successfully
[3/12/2024, 11:37:45 AM] Loaded 1 cached accessories from cachedAccessories.[redacted].
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Platform Config: {"logging":"debug"}
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Using Config Logging: debug
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Plugin Version: 3.4.0
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Finished initializing platform: SwitchBot
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Verifying Config
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Platform Config: {"logging":"debug"}
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Using Default Refresh Rate (2 minutes).
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Using Default Push Rate.
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Config OK
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Loading accessory from cache: Conservatory Curtain
[3/12/2024, 11:37:45 AM] [SwitchBot] [DEBUG] Executed didFinishLaunching callback
[3/12/2024, 11:37:45 AM] Homebridge v1.7.0 (HAP v0.11.1) (SwitchBot) is running on port 42225.
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] statusCode: 200
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] devicesAPI: {"statusCode":100,"body":{"deviceList":[{"deviceId":"[redacted]","deviceName":"Curtain 3","deviceType":"Curtain3","enableCloudService":true,"hubDeviceId":"[redacted]","curtainDevicesIds":["[redacted]"],"calibrate":true,"group":false,"master":true,"openDirection":"left"},{"deviceId":"[redacted]","deviceName":"Hub Mini 3E","deviceType":"Hub Mini","enableCloudService":true,"hubDeviceId":"000000000000"}],"infraredRemoteList":[]},"message":"success"}
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] devicesAPI Body: {"deviceList":[{"deviceId":"[redacted]","deviceName":"Curtain 3","deviceType":"Curtain3","enableCloudService":true,"hubDeviceId":"[redacted]","curtainDevicesIds":["[redacted]"],"calibrate":true,"group":false,"master":true,"openDirection":"left"},{"deviceId":"[redacted]","deviceName":"Hub Mini 3E","deviceType":"Hub Mini","enableCloudService":true,"hubDeviceId":"000000000000"}],"infraredRemoteList":[]}
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] devicesAPI StatusCode: 100
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] statusCode: 200 & devicesAPI StatusCode: 100
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] DeviceLists: [{"deviceId":"[redacted]","deviceName":"Curtain 3","deviceType":"Curtain3","enableCloudService":true,"hubDeviceId":"[redacted]","curtainDevicesIds":["[redacted]"],"calibrate":true,"group":false,"master":true,"openDirection":"left"},{"deviceId":"[redacted]","deviceName":"Hub Mini 3E","deviceType":"Hub Mini","enableCloudService":true,"hubDeviceId":"000000000000"}]
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] DeviceLists Length: 2
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] SwitchBot Device Config Set: [{"deviceId":"[redacted]","configDeviceName":"Conservatory Curtain","configDeviceType":"Curtain3","connectionType":"BLE","curtain":{"set_min":5,"set_max":95,"setOpenMode":"0","setCloseMode":"0","hide_lightsensor":true},"history":true,"logging":"debug"}]
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] SwitchBot Devices: [{"deviceId":"[redacted]","configDeviceName":"Conservatory Curtain","configDeviceType":"Curtain3","connectionType":"BLE","curtain":{"set_min":5,"set_max":95,"setOpenMode":"0","setCloseMode":"0","hide_lightsensor":true},"history":true,"logging":"debug","deviceName":"Curtain 3","deviceType":"Curtain3","enableCloudService":true,"hubDeviceId":"[redacted]","curtainDevicesIds":["[redacted]"],"calibrate":true,"group":false,"master":true,"openDirection":"left"},{"deviceId":"F37FC4DE193E","deviceName":"Hub Mini 3E","deviceType":"Hub Mini","enableCloudService":true,"hubDeviceId":"000000000000"}]
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Discovered Curtain3 Conservatory Curtain: [redacted]
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Discovered Hub Mini: [redacted]
[3/12/2024, 11:37:46 AM] [SwitchBot] Total SwitchBot Devices Found: 2
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] IR Device Config Not Set: undefined
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Total IR Devices Found: 0
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] deviceName: Conservatory Curtain deviceId: [redacted], curtainDevicesIds: [redacted], master: true, group: false, disable_group: undefined, connectionType: BLE
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] deviceName: Conservatory Curtain [Curtain3 Config] device.master: true, device.group: false connectionType; BLE
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Device: Conservatory Curtain registerCurtains: true
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Device: Conservatory Curtain Curtain3 registerDevice: true
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Device: Conservatory Curtain connectionType: BLE, will display in HomeKit
[3/12/2024, 11:37:46 AM] [SwitchBot] Restoring existing accessory from cache: Conservatory Curtain DeviceID: [redacted]
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Using Device Config Logging: debug
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Using Platform Config refreshRate: 120
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Using Default Curtain updateRate: 7
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Using Default scanDuration: 7
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Config: {"set_min":5,"set_max":95,"setOpenMode":"0","setCloseMode":"0","hide_lightsensor":true,"connectionType":"BLE","logging":"debug"}
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain BLERefreshStatus
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Removing Light Sensor Service
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3 uuid: [redacted]-Curtain3, ([redacted])
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain updateCharacteristic CurrentPosition: 100
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain updateCharacteristic PositionState: 2
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain updateCharacteristic TargetPosition: 100
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain HoldPosition: undefined
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain updateCharacteristic BatteryLevel: 16
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain updateCharacteristic StatusLowBattery: 0
[3/12/2024, 11:37:46 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain BLE Address: [redacted]
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:238: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/@abandonware/noble/lib/noble.js:92:8)
    at NobleMac.emit (node:events:514:28)
[3/12/2024, 11:37:46 AM] [SwitchBot] Child bridge process ended
[3/12/2024, 11:37:46 AM] [SwitchBot] Process Ended. Code: 1, Signal: null
[3/12/2024, 11:37:53 AM] [SwitchBot] Restarting Process...

Config for homebridge-switchbot

{
            "name": "SwitchBot",
            "credentials": {
                "token": "[redacted]",
                "secret": "secret removed",
                "notice": "Keep your Token & Secret a secret!"
            },
            "options": {
                "devices": [
                    {
                        "deviceId": "[redacted]",
                        "configDeviceName": "Conservatory Curtain",
                        "configDeviceType": "Curtain3",
                        "connectionType": "OpenAPI",
                        "curtain": {
                            "set_min": 5,
                            "set_max": 95,
                            "setOpenMode": "0",
                            "setCloseMode": "0",
                            "hide_lightsensor": true
                        },
                        "history": true,
                        "logging": "debug"
                    }
                ]
            },
            "_bridge": {
                "username": "[redacted]",
                "port": 42225
            },
            "platform": "SwitchBot"
        }

Screenshots

No response

Device & Model

Curtain 3

Node.js Version

20.9.0

NPM Version

10.1.0

Homebridge Version

1.7.0

Homebridge SwitchBot Plugin Version

3.4.0

Homebridge Config UI X Plugin Version

4.55.1

Operating System

macOS Sonoma

harrisbooks commented 6 months ago

Please note that I removed the colons from the BLE address because I wondered if that was the problem. With the colons the plugin still crashes.

Thanks for any help you can provide!

manavgabhawala commented 3 months ago

I had a similar issue in the past and was able to workaround it using the steps below. I believe the problem is around giving permissions to the process to use Bluetooth on your Mac. The way I resolved this was to:

  1. Open Settings -> Privacy & Security -> Bluetooth
  2. Hit the + icon
  3. Navigate to /usr/local/bin/node and add it
  4. Hit the + icon again
  5. Navigate to /usr/local/lib/node_modules/homebridge/bin/homebridge

Adding these two and restarting everything worked for me.

harrisbooks commented 3 months ago

That’s great, thank, you.

I had a similar issue in the past and was able to workaround it using the steps below. I believe the problem is around giving permissions to the process to use Bluetooth on your Mac. The way I resolved this was to:

  1. Open Settings -> Privacy & Security -> Bluetooth
  2. Hit the + icon
  3. Navigate to /usr/local/bin/node and add it
  4. Hit the + icon again
  5. Navigate to /usr/local/lib/node_modules/homebridge/bin/homebridge

Adding these two and restarting everything worked for me.

donavanbecker commented 3 months ago

v3.5.1 has been released, please install and let me know if this has been resolved.

harrisbooks commented 3 months ago

Thanks @donavanbecker. Unfortunately the issue persists with the latest update. However, I have not yet done what @manavgabhawala suggested.

The error in the log before the plugin crashes is as follows:

[6/28/2024, 8:26:54 AM] [SwitchBot] [DEBUG] Curtain3: Conservatory Curtain Scanning for WoCurtain3 devices... 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:633:26) at Noble.emit (node:events:518: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:518:28)

I have the full log if you need it, I’ll just need to go through and take out any sensitive information. Thanks for your help.

donavanbecker commented 2 months ago

Can you try the latest beta:

npm version

Click here to find out how to install Beta

donavanbecker commented 2 months ago

v3.6.0 has been released. If this issue isn't resolved please open a new issue.

harrisbooks commented 2 months ago

No, it still crashes unfortunately. Thanks for your efforts though!

donavanbecker commented 2 months ago

Can you try the latest beta and if that doesn't work open a new issue as closed issues will not be reviewed:

npm version

Click here to find out how to install Beta

harrisbooks commented 2 months ago

Will do. Thanks for all your work!