OpenWonderLabs / homebridge-switchbot

The Homebridge SwitchBot plugin allows you to access your SwitchBot Device(s) from HomeKit. Homebridge.
https://www.switch-bot.com/
ISC License
229 stars 47 forks source link

Bug: SwitchBot not working with BLE and keep rebooting the child bridge #977

Open morning3tar opened 1 month ago

morning3tar commented 1 month ago

Describe the Bug

Hello, I am experiencing an issue with the plugin when attempting to use the bot in BLE mode. The plugin is not working correctly and keeps causing the child bridge to reboot.

To Reproduce

  1. Install Homebridge on a Raspberry Pi.
  2. Install the plugin.
  3. Configure the plugin to use BLE mode.

Expected Behavior

The plugin should be able to control the SwitchBot devices in BLE mode without causing the child bridge to reboot.

Relevant Log Output

[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Max Retries Not Set, Using: 5
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Delay Between Retries Not Set, Using: 3000
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Config: {"logging":"debug","scanDuration":10,"maxRetry":7,"connectionType":"BLE","mode":"switch","deviceType":"switch","allowPush":true,"doublePress":1}
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Model: SwitchBot S1, BLE Model: H
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot 3 FirmwareRevision: 3.5.0
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Firmware Version: 3.5.0
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot deviceVersion: 3.5.0
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Using Device Config scanDuration: 10
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Accessory Cache: switch
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Using Device Type: switch
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Using Bot Mode: switch
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Using Default Bot pushRatePress: 15
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Allowing Push Changes: true
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot Displaying as Switch
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot BLERefreshStatus
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot updateCharacteristic On: false
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot is not listening webhook.
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot updateCharacteristic BatteryLevel: 100
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot updateCharacteristic StatusLowBattery: 0
[27/05/2024, 09:24:58] [SwitchBot] [DEBUG] Bot: SwitchBot BLE Address: d3:35:xx:xx:xx:xx
[27/05/2024, 09:25:02] [SwitchBot] Bot: SwitchBot Set ProgrammableSwitchOutputState: true
[27/05/2024, 09:25:02] [SwitchBot] [DEBUG] Bot: SwitchBot BLEpushChanges
[27/05/2024, 09:25:02] [SwitchBot] [DEBUG] Bot: SwitchBot BLEpushChanges On: true OnCached: false
[27/05/2024, 09:25:02] [SwitchBot] [DEBUG] Bot: SwitchBot BLE Address: d3:35:xx:xx:xx:xx
[27/05/2024, 09:25:02] [SwitchBot] [DEBUG] Bot: SwitchBot Press Mode: switch
[27/05/2024, 09:25:07] [SwitchBot] Bot: SwitchBot On: true
[27/05/2024, 09:25:07] [SwitchBot] TypeError: Cannot read properties of undefined (reading 'turnOn')
[27/05/2024, 09:25:07] [SwitchBot] Bot: SwitchBot Retrying
[27/05/2024, 09:25:08] [SwitchBot] [DEBUG] Bot: SwitchBot BLEparseStatus
TypeError: Cannot read properties of undefined (reading 'mode')
    at Bot.BLEparseStatus (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/bot.ts:510:21)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/bot.ts:629:18
[27/05/2024, 09:25:08] [SwitchBot] Child bridge process ended
[27/05/2024, 09:25:08] [SwitchBot] Process Ended. Code: 1, Signal: null
[27/05/2024, 09:25:15] [SwitchBot] Restarting Process...

Config for homebridge-switchbot

{
    "name": "SwitchBot",
    "credentials": {
        "token": "xxxx",
        "secret": "xxxx",
        "notice": "Keep your Token & Secret a secret!"
    },
    "options": {
        "devices": [
            {
                "deviceId": "D3:35:xx:xx:xx:xx",
                "configDeviceName": "SwitchBot",
                "configDeviceType": "Bot",
                "connectionType": "BLE",
                "scanDuration": 10,
                "bot": {
                    "mode": "switch",
                    "deviceType": "switch",
                    "allowPush": true,
                    "doublePress": 1
                },
                "maxRetry": 7,
                "logging": "debug"
            }
        ]
    },
    "_bridge": {
        "username": "0E:xx:xx:xx:xx:xx",
        "port": 550xx
    },
    "platform": "SwitchBot"
}

Screenshots

No response

Device and Model

SwitchBot V6.6

Node.js Version

v20.13.1

NPM Version

v8.19.4

Homebridge Version

v1.8.2

Homebridge Switchbot Plugin Version

v3.5.0

Homebridge Config UI X Plugin Version

No response

Operating System

Raspbian

donavanbecker commented 1 month ago

Did this work for you on previous versions?

badxhabit commented 1 month ago

Getting the same issue. I disabled the Switchbot plugin and everything is working now.

Boscosticks commented 1 month ago

+1 Same issue here.

I rolled back 3.4.0, and everything is working as intended.

donavanbecker commented 1 month ago

And is this only on Bots for everyone?

Boscosticks commented 1 month ago

And is this only on Bots for everyone?

Yep. I have the same error message as OP.

morning3tar commented 1 month ago

+1 Same issue here.

I rolled back 3.4.0, and everything is working as intended.

I rolled back to the 3.4.0 version but the issue persists and not working.

donavanbecker commented 1 month ago

I have found part of the issue, just need to figure out a fix and resolve it. I will do it as quick as I can as life allows.

CalamandreiLorenzo commented 1 month ago

Hi, idk if can be of any help, I think the error is also present for hubs, or at least I have a similar error for the humidity retrieving of hub2, the error message seems the same, so it could be related.

TypeError: Cannot read properties of undefined (reading 'CurrentRelativeHumidity') 
at Hub.updateHomeKitCharacteristics (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/hub.ts: 345:37)
at new Hub (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/hub.ts:141:10)
at SwitchBotPlatform.createHub2 (file:///homebridge/node_modules/@switchbot/homebridge-switchbot/src/platform.ts: 1094:9)
at processTicksAndRejections (node: internal/process/task_queues: 95:5)
teh-hippo commented 1 month ago

Similar issue as above. Fixed by reverting the version.

[05/06/2024, 12:17:10 pm] [SwitchBot] Restoring existing accessory from cache: Hub 2 DeviceID: ABC123
TypeError: Cannot read properties of undefined (reading 'battery')
    at Meter.BLEparseStatus (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:155:52)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:267:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
github-actions[bot] commented 2 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

teh-hippo commented 2 weeks ago

I don't believe this is stale; I'm still on 3.4. In case it helps, I'm running on a Raspberry Pi.

[21/06/2024, 8:49:41 am] [SwitchBot] Restoring existing accessory from cache: Hub 2 DeviceID: MY_DEVICE_ID
TypeError: Cannot read properties of undefined (reading 'battery')
    at Meter.BLEparseStatus (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:155:52)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:267:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
[21/06/2024, 8:49:47 am] [SwitchBot] Child bridge process ended
donavanbecker commented 2 weeks ago

I don't believe this is stale; I'm still on 3.4. In case it helps, I'm running on a Raspberry Pi.

[21/06/2024, 8:49:41 am] [SwitchBot] Restoring existing accessory from cache: Hub 2 DeviceID: MY_DEVICE_ID
TypeError: Cannot read properties of undefined (reading 'battery')
    at Meter.BLEparseStatus (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:155:52)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:267:18
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
[21/06/2024, 8:49:47 am] [SwitchBot] Child bridge process ended

can you try the latest beta?

teh-hippo commented 2 weeks ago

Issue is still occurring.

[21/06/2024, 4:48:10 pm] [SwitchBot] MeterPlus: Server Meter ad: {
  "id": "ab1c234567d8",
  "address": "ab:1c:23:45:67:d8",
  "rssi": -32,
  "serviceData": {
    "model": "i",
    "modelName": "WoSensorTH",
    "modelfriendlyName": "Meter",
    "temperature": {
      "c": 18.6,
      "f": 65.5
    },
    "fahrenheit": false,
    "humidity": 51,
    "battery": 100
  }
}
[21/06/2024, 4:48:12 pm] [SwitchBot] MeterPlus: Server Meter ad: {
  "id": "ab1c234567d8",
  "address": "ab:1c:23:45:67:d8",
  "rssi": -27,
  "serviceData": {
    "model": "i",
    "modelName": "WoSensorTH",
    "modelfriendlyName": "Meter",
    "temperature": {
      "c": 18.6,
      "f": 65.5
    },
    "fahrenheit": false,
    "humidity": 51,
    "battery": 100
  }
}
[21/06/2024, 4:48:14 pm] [SwitchBot] MeterPlus: Server Meter ad: {
  "id": "ab1c234567d8",
  "address": "ab:1c:23:45:67:d8",
  "rssi": -28,
  "serviceData": {
    "model": "i",
    "modelName": "WoSensorTH",
    "modelfriendlyName": "Meter",
    "temperature": {
      "c": 18.6,
      "f": 65.5
    },
    "fahrenheit": false,
    "humidity": 51,
    "battery": 100
  }
}
TypeError: Cannot read properties of undefined (reading 'c')
    at Meter.BLEparseStatus (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:164:47)
    at runNextTicks (node:internal/process/task_queues:60:5)
    at listOnTimeout (node:internal/timers:540:9)
    at processTimers (node:internal/timers:514:7)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/meter.ts:263:11
[21/06/2024, 4:48:15 pm] [SwitchBot] Child bridge process ended
donavanbecker commented 1 week ago

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

teh-hippo commented 1 week ago

Negative; same problem.

On Fri, 28 Jun 2024 at 12:46 PM, Donavan Becker @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/OpenWonderLabs/homebridge-switchbot/issues/977#issuecomment-2196007699 or unsubscribe https://github.com/notifications/unsubscribe-auth/AADXWRJNITBZD3BLPX7N2HTZJTE7TBFKMF2HI4TJMJ2XIZLTSSBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLAVFOZQWY5LFVIZTEMJRHAYTAMBUGWSG4YLNMWUWQYLTL5WGCYTFNSWHG5LCNJSWG5C7OR4XAZNMJFZXG5LFINXW23LFNZ2KM5DPOBUWG44TQKSHI6LQMWVHEZLQN5ZWS5DPOJ42K5TBNR2WLKJTHEYDONZUHE3THAVEOR4XAZNFNFZXG5LFUV3GC3DVMWVDEMZRHEYTQMZRGU4IFJDUPFYGLJLMMFRGK3FFOZQWY5LFVIZTEMJRHAYTAMBUGWTXI4TJM5TWK4VGMNZGKYLUMU . You are receiving this email because you commented on the thread.

Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub .

morning3tar commented 3 days ago

Still have some issues.

[01/07/2024, 10:22:15] [SwitchBot] Process Ended. Code: 1, Signal: null
[01/07/2024, 10:22:22] [SwitchBot] Restarting Process...
[01/07/2024, 10:22:22] [SwitchBot] Launched child bridge with PID 3737
[01/07/2024, 10:22:23] Registering platform '@switchbot/homebridge-switchbot.SwitchBot'
[01/07/2024, 10:22:23] [SwitchBot] Loaded @switchbot/homebridge-switchbot v3.5.1 child bridge successfully
[01/07/2024, 10:22:23] Loaded 1 cached accessories from cachedAccessories.0xx4xxxxD43x.
[01/07/2024, 10:22:23] Homebridge v1.8.3 (HAP v0.12.2) (SwitchBot) is running on port 32125.
[01/07/2024, 10:22:24] [SwitchBot] Total SwitchBot Devices Found: 1
[01/07/2024, 10:22:24] [SwitchBot] Restoring existing accessory from cache: SwitchBot deviceId: Dxx533xxxxxx
[01/07/2024, 10:22:29] [SwitchBot] Bot: SwitchBot failed to get serviceData, serviceData: [object Object]
TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Timeout'
    |     property '_idlePrev' -> object with constructor 'TimersList'
    --- property '_idleNext' closes the circle
    at JSON.stringify (<anonymous>)
    at Bot.BLERefreshConnection (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/bot.ts:1392:90)
    at file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/src/device/bot.ts:680:22
[01/07/2024, 10:22:29] [SwitchBot] Child bridge process ended
[01/07/2024, 10:22:29] [SwitchBot] Process Ended. Code: 1, Signal: null
[01/07/2024, 10:22:36] [SwitchBot] Restarting Process...