homebridge-switchbot icon indicating copy to clipboard operation
homebridge-switchbot copied to clipboard

Bug: Bot not able to send BLE commands

Open DKhen opened this issue 1 year ago • 23 comments

Describe the Bug

ive just installed Version 4.0.0, set up the bot from scratch but still receiving the Same error as in the old Issue.

Bot: Swotchbot failed BLEpushChanges with BLE Connection, Error Message: "Cannot read properties of undefined (reading 'press') "

To Reproduce

  • install Version 4.0.0
  • Setup bot with BLE
  • tap Switchbot bot with Firmware v6.6

Expected Behavior

properties can be read and makes a press

Relevant Log Output


[10/12/2024, 11:00:38 AM] [SwitchBot] ID EBUG] Bot: Swotchbot (power, battery, de
viceMode) = BLE: (undefined, undefined, u
ndefined), current: (undefined, 100, press)

[10/12/2024, 11:00:38 AM] [SwitchBot] [D EBUG] Bot: Swotchbot Press Mode, On: fal se
[10/12/2024, 11:00:38 AM] [SwitchBot] [D EBUG] Bot: Swotchbot BatteryLevel: undef ined
[10/12/2024, 11:00:38 AM] [SwitchBot] [D EBUG] Bot: Swotchbot StatusLowBattery: 0 [10/12/2024, 11:00:38 AM] [SwitchBot] ID EBUG] Bot: Swotchbot updateHomeKitCharac teristics
[10/12/2024, 11:00:38 AM] [SwitchBot] ID EBUG] Bot: Swotchbot BatteryLevel: undef ined
[10/12/2024, 11:00:38 AM] [SwitchBot] [D EBUG] Bot: Swotchbot updateCharacteristi c StatusLowBattery: 0
[10/12/2024, 11:00:38 AM] [SwitchBot] ID EBUG] Bot: Swotchbot updateCharacteristi c On: false
[10/12/2024, 11:00:58 AM] [SwitchBot] ID
EBUG] Bot: Swotchbot value: true
[10/12/2024, 11:00:58 AM] [SwitchBot] [D EBUG] Bot: Swotchbot BLEpushChanges

[10/12/2024, 11:00:58 AM] [SwitchBot] [D
EBUG] Bot: Swotchbot value: true
[10/12/2024, 11:00:58 AM] [SwitchBot] [D EBUG] Bot: Swotchbot BLEpushChanges
[10/12/2024, 11:00:58 AM] [SwitchBot] [D EBUG] Bot: Swotchbot BLEpushChanges On:
true OnCached: false
[10/12/2024, 11:00:58 AM] [SwitchBot] [D EBUG] Bot: Swotchbot bleMac: c7:32:34:35
: 0b: 5c
[10/12/2024, 11:00:58 AM] [SwitchBot] ID
EBUG] Bot: Swotchbot Bot Mode: press [10/12/2024, 11:01:03 AM] [SwitchBot] St opped Scanning for SwitchBot BLE devices
[10/12/2024, 11:01:03 AM] [SwitchBot] BO
t: Swotchbot On: true
[10/12/2024, 11:01:03 AM] [SwitchBot] Bot: Swotchbot failed BLEpushChanges with
BLE Connection, Error Message: "Cannot read properties of undefined (reading 'press') "

Config for homebridge-switchbot


{
"name": "Switchbot",
"credentials": {
        "token": "x",
        "secret": "x",
        "notice": "Keep your Token & Secret a secret!"
    },
    "options": {
        "devices": [
            {
                "configDeviceName": "Swotchbot",
                "deviceId": "c7:32:34:35:0B:5C",
                "configDeviceType": "Bot",
                "connectionType": "BLE",
                "mode": "press",
                "doublePress": 1,
                "logging": "debug"
            }
        ]
    },
    "platform": "SwitchBot"
}

Screenshots

No response

Device and Model

Switchbot Bot with Firmware v6.6

Node.js Version

v20.10.0

NPM Version

10.2.3

Homebridge Version

v1.8.4

Homebridge Switchbot Plugin Version

v4.0.0

Homebridge Config UI X Plugin Version

v4.58.0

Operating System

Raspian / Portainer / homebridge Image

DKhen avatar Oct 12 '24 09:10 DKhen

Providing no config?

Also you have this installed on portainer. My guess is that that could be causing the issues.

donavanbecker avatar Oct 12 '24 10:10 donavanbecker

Sorry, it didnt show up, here it is:

{
"name": "Switchbot",
"credentials": {
        "token": "x",
        "secret": "x",
        "notice": "Keep your Token & Secret a secret!"
    },
    "options": {
        "devices": [
            {
                "configDeviceName": "Swotchbot",
                "deviceId": "c7:32:34:35:0B:5C",
                "configDeviceType": "Bot",
                "connectionType": "BLE",
                "mode": "press",
                "doublePress": 1,
                "logging": "debug"
            }
        ]
    },
    "platform": "SwitchBot"
}

The error also occurs if I use the Plugin outside of docker.

DKhen avatar Oct 12 '24 10:10 DKhen

Does everything work fine with OpenAPI?

donavanbecker avatar Oct 12 '24 10:10 donavanbecker

Update your deviceId to C73234350B5C

donavanbecker avatar Oct 12 '24 10:10 donavanbecker

Isnt OpenAPI exclusive to use with the Switchbot Bridge? I just got the bot.

Changed deviceId but no difference.

DKhen avatar Oct 12 '24 11:10 DKhen

New error Message: image

DKhen avatar Oct 12 '24 11:10 DKhen

Isnt OpenAPI exclusive to use with the Switchbot Bridge? I just got the bot.

Changed deviceId but no difference.

Yes you need a Hub to use bot with OpenAPI

donavanbecker avatar Oct 12 '24 12:10 donavanbecker

New error Message: image

This happens when the plugin cannot receive serviceData (BLE Data) from the device.

If you cannot push a command, I am not surprised that you weren't able to receive as well.

donavanbecker avatar Oct 12 '24 12:10 donavanbecker

The error also occurs if I use the Plugin outside of docker.

Have you installed all prerequisites of node-switchbot and noble.

donavanbecker avatar Oct 12 '24 12:10 donavanbecker

Yes I have, im trying also some scripts with noble with discovering bluetooth devices, and that seems to be working. Is there a discord where we could discuss this?

DKhen avatar Oct 12 '24 16:10 DKhen

directly from homebridge console:

const noble = require('@stoprocent/noble');

const targetAddress = 'c7:32:34:35:0b:5c';

noble.on('stateChange', (state) => {
    if (state === 'poweredOn') {
        console.log('Bluetooth is powered on. Starting scan...');
        noble.startScanning([], false);
    } else {
        console.log('Bluetooth is not powered on. Stopping scan...');
        noble.stopScanning();
    }
});

noble.on('discover', (peripheral) => {
    const discoveredAddress = peripheral.address.toLowerCase(); // Normalize to lowercase
    if (discoveredAddress === targetAddress) {
        const advertisement = peripheral.advertisement;
        const manufacturerData = advertisement.manufacturerData;

        let deviceName = 'Unknown';
        if (manufacturerData) {
            // Extract device-specific name from manufacturerData if localName is undefined
            deviceName = `SwitchBot_${manufacturerData.toString('hex').slice(0, 12)}`;
        }

       console.log(peripheral);
       console.log('Discovered target peripheral:');
       console.log(`  Name: ${deviceName}`);
       console.log(`  Address: ${peripheral.address}`);
       console.log(`  RSSI: ${peripheral.rssi}`);
       console.log(`  UUID: ${peripheral.uuid}`);
       console.log('  Advertisement:', advertisement);
}
});
Bluetooth is powered on. Starting scan...
<ref *1> Peripheral {
  _noble: Noble {
    initialized: true,
    address: 'e4:5f:01:a8:64:9f',
    _state: 'poweredOn',
    _bindings: NobleBindings {
      _state: 'poweredOn',
      _addresses: [Object],
      _addresseTypes: [Object],
      _connectable: [Object],
      _isExtended: false,
      scannable: [Object],
      _pendingConnectionUuid: null,
      _connectionQueue: [],
      _handles: {},
      _gatts: {},
      _aclStreams: {},
      _signalings: {},
      _hci: [Hci],
      _gap: [Gap],
      _events: [Object: null prototype],
      _eventsCount: 25,
      onSigIntBinded: [Function: bound ],
      _scanServiceUuids: []
    },
    _peripherals: {
      d4adfc01a646: [Peripheral],
      '7138c37152be': [Peripheral],
      '3e402754330d': [Peripheral],
      '54deca1759a9': [Peripheral],
      '4623a39224d8': [Peripheral],
      '6abada3773c8': [Peripheral],
      '57c75c6cb276': [Peripheral],
      c73234350b5c: [Circular *1]
    },
    _services: {
      d4adfc01a646: {},
      '7138c37152be': {},
      '3e402754330d': {},
      '54deca1759a9': {},
      '4623a39224d8': {},
      '6abada3773c8': {},
      '57c75c6cb276': {},
      c73234350b5c: {}
    },
    _characteristics: {
      d4adfc01a646: {},
      '7138c37152be': {},
      '3e402754330d': {},
      '54deca1759a9': {},
      '4623a39224d8': {},
      '6abada3773c8': {},
      '57c75c6cb276': {},
      c73234350b5c: {}
    },
    _descriptors: {
      d4adfc01a646: {},
      '7138c37152be': {},
      '3e402754330d': {},
      '54deca1759a9': {},
      '4623a39224d8': {},
      '6abada3773c8': {},
      '57c75c6cb276': {},
      c73234350b5c: {}
    },
    _discoveredPeripheralUUids: {
      d4adfc01a646: true,
      '7138c37152be': true,
      '3e402754330d': true,
      '54deca1759a9': true,
      '4623a39224d8': true,
      '6abada3773c8': true,
      '57c75c6cb276': true,
      c73234350b5c: true
    },
    _events: [Object: null prototype] {
      warning: [Function (anonymous)],
      newListener: [Function (anonymous)],
      stateChange: [Function (anonymous)],
      discover: [Function (anonymous)]
    },
    _eventsCount: 4,
    _allowDuplicates: false
  },
  id: 'c73234350b5c',
  uuid: 'c73234350b5c',
  address: 'c7:32:34:35:0b:5c',
  addressType: 'random',
  connectable: true,
  scannable: false,
  advertisement: {
    localName: undefined,
    txPowerLevel: undefined,
    manufacturerData: <Buffer 69 09 c7 32 34 35 0b 5c 10 2c>,
    serviceData: [ [Object] ],
    serviceUuids: [],
    solicitationServiceUuids: [],
    serviceSolicitationUuids: []
  },
  rssi: -32,
  services: null,
  mtu: null,
  state: 'disconnected'
}
Discovered target peripheral:
  Name: SwitchBot_6909c7323435
  Address: c7:32:34:35:0b:5c
  RSSI: -32
  UUID: c73234350b5c
  Advertisement: {
  localName: undefined,
  txPowerLevel: undefined,
  manufacturerData: <Buffer 69 09 c7 32 34 35 0b 5c 10 2c>,
  serviceData: [ { uuid: 'fd3d', data: <Buffer 48 40 e4 00> } ],
  serviceUuids: [],
  solicitationServiceUuids: [],
  serviceSolicitationUuids: []
}

DKhen avatar Oct 12 '24 18:10 DKhen

But if I try this using node-switchbot:

import { SwitchBotBLE } from 'node-switchbot';
import noble from '@stoprocent/noble';
const switchBotBLE = new SwitchBotBLE({ noble });

switchBotBLE.discover().then(() => {
  console.log('The discovery process was finished.');
});

switchBotBLE.discover({
  duration: 5000,
  quick: true
}).then((device_list) => {
 console.log(device_list);
}).catch((error) => {
  console.error(error);
});

i get

The discovery process was finished.
[]
[]

DKhen avatar Oct 12 '24 22:10 DKhen

My BLE control is also completely broken with 4.0

[10/14/2024, 2:23:26 PM] [@switchbot/homebridge-switchbot] This plugin generated a warning from the characteristic 'Target Position': characteristic value expected valid finite number and received "NaN" (number). See https://homebridge.io/w/JtMGR for more info.
[10/14/2024, 2:23:27 PM] [SwitchBot] Curtain3: LeftCurtain TypeError: Cannot read properties of undefined (reading 'runToPos')
[10/14/2024, 2:23:27 PM] [SwitchBot] Curtain3: LeftCurtain Retrying
[10/14/2024, 2:23:28 PM] [SwitchBot] Curtain3: LeftCurtain TypeError: Cannot read properties of undefined (reading 'runToPos')
[10/14/2024, 2:23:28 PM] [SwitchBot] Curtain3: LeftCurtain Retrying
[10/14/2024, 2:23:29 PM] [SwitchBot] Curtain3: LeftCurtain TypeError: Cannot read properties of undefined (reading 'runToPos')
[10/14/2024, 2:23:29 PM] [SwitchBot] Curtain3: LeftCurtain Retrying
[10/14/2024, 2:23:30 PM] [SwitchBot] Curtain3: LeftCurtain TypeError: Cannot read properties of undefined (reading 'runToPos')
[10/14/2024, 2:23:30 PM] [SwitchBot] Curtain3: LeftCurtain Retrying
[10/14/2024, 2:23:31 PM] [SwitchBot] Curtain3: LeftCurtain failed BLEpushChanges with BLE Connection, Error Message: "Cannot read properties of undefined (reading 'runToPos')"

This seems to be a carryover of this: #1007 (comment)

Please delete from this issue and open a new issue as this is for Curtains

donavanbecker avatar Oct 14 '24 18:10 donavanbecker

@donavanbecker using noble, i managed to send the trigger command to the bot, eventually this might help you with finding the error? i have tbh struggle to see through this project 😅

const noble = require('@abandonware/noble');
const targetAddress = 'c7:32:34:35:0b:5c';

noble.on('stateChange', (state) => {
    if (state === 'poweredOn') {
        console.log('Bluetooth is powered on. Starting scan...');
        noble.startScanning([], false);
    } else {
        console.log('Bluetooth is not powered on. Stopping scan...');
        noble.stopScanning();
    }
});

noble.on('discover', (peripheral) => {
    const discoveredAddress = peripheral.address.toLowerCase();
    if (discoveredAddress === targetAddress) {
        console.log('Discovered target peripheral:', peripheral.advertisement);

        console.log('Attempting to connect...');
        peripheral.connect((error) => {
            if (error) {
                console.error('Failed to connect:', error);
                return;
            }
            console.log('Connected to the device.');

            // Add a small delay before interacting
            setTimeout(() => {
                sendCommandToSwitchBot(peripheral);
            }, 1000); // Delay for 1 second
        });

        // Handle disconnect
        peripheral.once('disconnect', (error) => {
            if (error) {
                console.error('Disconnected due to error:', error);
            } else {
                console.log('Peripheral disconnected');
            }
        });
    }
});

function sendCommandToSwitchBot(peripheral) {
    peripheral.discoverAllServicesAndCharacteristics((error, services, characteristics) => {
        if (error) {
            console.error('Error discovering services/characteristics:', error);
            return;
        }

        console.log('Successfully discovered services and characteristics.');

        // Interact with the custom characteristics
        characteristics.forEach((characteristic) => {
            if (characteristic.uuid === 'cba20003224d11e69fb80002a5d5c51b' ||
                characteristic.uuid === 'cba20002224d11e69fb80002a5d5c51b') {

                console.log('Interacting with SwitchBot Bot characteristic.');

                // Attempt to read the characteristic first
                characteristic.read((error, data) => {
                    if (error) {
                        console.error('Error reading characteristic:', error);
                    } else {
                        console.log('Characteristic read data:', data);

                        // Now attempt to send the press command
                        const command = Buffer.from([0x57, 0x01, 0x00]); // Example press command
                        characteristic.write(command, false, (error) => {
                            if (error) {
                                console.error('Error writing to characteristic:', error);
                            } else {
                                console.log('Command sent to SwitchBot Bot!');
                            }
                        });
                    }
                });
            }
        });
    });
}

DKhen avatar Oct 17 '24 18:10 DKhen

Thanks @DKhen! When I have time I will take a look. But if you want to open a PR to make it better, by all means.

donavanbecker avatar Oct 17 '24 19:10 donavanbecker

oh that was no critism for your project, its just my own stupidness lol :D i will give it a try, but im sure in mean time you already fixed it haha

DKhen avatar Oct 17 '24 19:10 DKhen

I wasn't taking it as critism. I self taught myself how to code.... so it probably could be better ha.

donavanbecker avatar Oct 17 '24 20:10 donavanbecker

Ah okay nice, in fact i develop with php, but I find it hardly to get into typescript especially with such huge projects

DKhen avatar Oct 17 '24 20:10 DKhen

@DKhen are you on the homebridge discord server?

donavanbecker avatar Oct 19 '24 04:10 donavanbecker

Not yet, you got a link somewhere?

DKhen avatar Oct 19 '24 09:10 DKhen

You can find it right here:

Homebridge UI: Community

donavanbecker avatar Oct 19 '24 10:10 donavanbecker

Might be experiencing the same/a similar issue here:

  • Plugin v4.1.5
  • Bot firmware v6.6
  • Homebridge v1.8.5
  • OS: Ubuntu 22.04 (linux kernel 6.8.0-49-generic)
  • Node v22.12.0

Issue appearance in logs:

[12/15/2024, 10:06:41 PM] [SwitchBot] [DEBUG] Bot: Kitchen Bot Mode: switch
[12/15/2024, 10:06:41 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available!
[12/15/2024, 10:06:42 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available!
[12/15/2024, 10:06:42 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3!
[12/15/2024, 10:06:46 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices.
[12/15/2024, 10:06:46 PM] [SwitchBot] No devices found during discovery.
[12/15/2024, 10:06:46 PM] [SwitchBot] Bot: Kitchen failed BLEpushChanges with BLE Connection, Error Message: "No devices found during discovery."
...
Config
```json { "name": "SwitchBot", "credentials": { "token": "", "secret": "", "notice": "Keep your Token & Secret a secret!" }, "options": { "devices": [ { "configDeviceName": "Kitchen", "deviceId": "D93431303F45", "hide_device": false, "configDeviceType": "Bot", "connectionType": "BLE", "type": "switch", "mode": "switch", "allowPush": true, "doublePress": 1, "maxRetry": 3, "firmware": "6.6", "external": false } ], "BLE": true, "discoverBLE": true, "logging": "debug" }, "_bridge": { "username": "0E:37:A8:82:E2:AB", "port": 37394 }, "platform": "SwitchBot" } ```
Large logs snipped
``` [12/15/2024, 9:39:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:39:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:39:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:39:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:39:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false [12/15/2024, 9:39:43 PM] [SwitchBot] [DEBUG] Bot: Kitchen value: false [12/15/2024, 9:39:43 PM] [SwitchBot] [DEBUG] Bot: Kitchen value: false [12/15/2024, 9:39:43 PM] [SwitchBot] [DEBUG] Bot: Kitchen value: false [12/15/2024, 9:39:44 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEpushChanges [12/15/2024, 9:39:44 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEpushChanges On: false OnCached: false [12/15/2024, 9:39:44 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:39:44 PM] [SwitchBot] [DEBUG] Bot: Kitchen Bot Mode: switch [12/15/2024, 9:39:44 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] Bot: Kitchen value: true [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEpushChanges [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEpushChanges On: true OnCached: false [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] Bot: Kitchen Bot Mode: switch [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:39:48 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:39:49 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:39:49 PM] [SwitchBot] No devices found during discovery. [12/15/2024, 9:39:49 PM] [SwitchBot] Bot: Kitchen failed BLEpushChanges with BLE Connection, Error Message: "No devices found during discovery." [12/15/2024, 9:39:53 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:39:53 PM] [SwitchBot] No devices found during discovery. [12/15/2024, 9:39:53 PM] [SwitchBot] Bot: Kitchen failed BLEpushChanges with BLE Connection, Error Message: "No devices found during discovery." [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLERefreshStatus [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] Bot: Kitchen 'node-switchbot' found: [object Object] [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] Bot: Kitchen Scanning for WoHand devices... [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] Started Scanning for SwitchBot BLE devices. [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:39:59 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:40:00 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:40:02 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLERefreshStatus [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] Bot: Kitchen 'node-switchbot' found: [object Object] [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] Bot: Kitchen Scanning for WoHand devices... [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] Started Scanning for SwitchBot BLE devices. [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:40:03 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEparseStatus [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen (power, battery, deviceMode) = BLE:(undefined, undefined, undefined), current:(false, 100, switch) [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:40:04 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEparseStatus [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen (power, battery, deviceMode) = BLE:(undefined, undefined, undefined), current:(false, 100, switch) [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:40:08 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLERefreshStatus [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen 'node-switchbot' found: [object Object] [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen Scanning for WoHand devices... [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] Started Scanning for SwitchBot BLE devices. [12/15/2024, 9:44:32 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:44:33 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:44:33 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:44:34 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:44:34 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:44:35 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:44:36 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEparseStatus [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen (power, battery, deviceMode) = BLE:(undefined, undefined, undefined), current:(false, 100, switch) [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:44:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLERefreshStatus [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen 'node-switchbot' found: [object Object] [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen Scanning for WoHand devices... [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] Started Scanning for SwitchBot BLE devices. [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:49:32 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:33 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:49:33 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:49:33 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:34 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:35 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:49:35 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:36 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:36 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEparseStatus [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen (power, battery, deviceMode) = BLE:(undefined, undefined, undefined), current:(false, 100, switch) [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:49:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLERefreshStatus [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen 'node-switchbot' found: [object Object] [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen bleMac: d9:34:31:30:3f:45 [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] Bot: Kitchen Scanning for WoHand devices... [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] Started Scanning for SwitchBot BLE devices. [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:54:32 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:54:33 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:54:33 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:54:33 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:54:34 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:54:34 PM] [SwitchBot] [DEBUG] [parseAdvertising.] return null, model "" not available! [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] [parseServiceData] Buffer length 4 !== 3! [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Stopped Scanning for SwitchBot BLE devices. [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen BLEparseStatus [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen (power, battery, deviceMode) = BLE:(undefined, undefined, undefined), current:(false, 100, switch) [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen Press Mode, On: false [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateHomeKitCharacteristics [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic BatteryLevel: 100 [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic StatusLowBattery: 0 [12/15/2024, 9:54:37 PM] [SwitchBot] [DEBUG] Bot: Kitchen updateCharacteristic On: false ```

Trying manually to find the device with @stoprocent/noble via the script @DKhen wrote above works similarly in my case. It seems to be able to find my switchbot:

homebridge@craptop:/var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot $ node raw-noble.cjs 
Bluetooth is powered on. Starting scan...
<ref *1> Peripheral {
  _noble: Noble {
    initialized: true,
    address: '08:be:ac:30:d8:ef',
    _state: 'poweredOn',
    _bindings: NobleBindings {
      _state: 'poweredOn',
      _addresses: [Object],
      _addresseTypes: [Object],
      _connectable: [Object],
      _isExtended: false,
      scannable: [Object],
      _pendingConnectionUuid: null,
      _connectionQueue: [],
      _handles: {},
      _gatts: {},
      _aclStreams: {},
      _signalings: {},
      _hci: [Hci],
      _gap: [Gap],
      _events: [Object: null prototype],
      _eventsCount: 25,
      onSigIntBinded: [Function: bound ],
      _scanServiceUuids: []
    },
    _peripherals: {
      '4870f6982a5f': [Peripheral],
      '7a9e15389312': [Peripheral],
      '6074f4d4bdfd': [Peripheral],
      '5b672368a3c6': [Peripheral],
      '66ca56170d62': [Peripheral],
      e23a2682c6ed: [Peripheral],
      '48e15c75dc3c': [Peripheral],
      '7e552f825fdc': [Peripheral],
      '6074f4447a8b': [Peripheral],
      '1d8e1dc83104': [Peripheral],
      d0c9071e03a5: [Peripheral],
      '7ec85a2e7d80': [Peripheral],
      d0c9071e1d53: [Peripheral],
      '6bd2d82d40da': [Peripheral],
      d0c9071dcca1: [Peripheral],
      '72f2498adfd8': [Peripheral],
      d0c9071d2e59: [Peripheral],
      '4194c766eb19': [Peripheral],
      d93431303f45: [Circular *1]
    },
    _services: {
      '4870f6982a5f': {},
      '7a9e15389312': {},
      '6074f4d4bdfd': {},
      '5b672368a3c6': {},
      '66ca56170d62': {},
      e23a2682c6ed: {},
      '48e15c75dc3c': {},
      '7e552f825fdc': {},
      '6074f4447a8b': {},
      '1d8e1dc83104': {},
      d0c9071e03a5: {},
      '7ec85a2e7d80': {},
      d0c9071e1d53: {},
      '6bd2d82d40da': {},
      d0c9071dcca1: {},
      '72f2498adfd8': {},
      d0c9071d2e59: {},
      '4194c766eb19': {},
      d93431303f45: {}
    },
    _characteristics: {
      '4870f6982a5f': {},
      '7a9e15389312': {},
      '6074f4d4bdfd': {},
      '5b672368a3c6': {},
      '66ca56170d62': {},
      e23a2682c6ed: {},
      '48e15c75dc3c': {},
      '7e552f825fdc': {},
      '6074f4447a8b': {},
      '1d8e1dc83104': {},
      d0c9071e03a5: {},
      '7ec85a2e7d80': {},
      d0c9071e1d53: {},
      '6bd2d82d40da': {},
      d0c9071dcca1: {},
      '72f2498adfd8': {},
      d0c9071d2e59: {},
      '4194c766eb19': {},
      d93431303f45: {}
    },
    _descriptors: {
      '4870f6982a5f': {},
      '7a9e15389312': {},
      '6074f4d4bdfd': {},
      '5b672368a3c6': {},
      '66ca56170d62': {},
      e23a2682c6ed: {},
      '48e15c75dc3c': {},
      '7e552f825fdc': {},
      '6074f4447a8b': {},
      '1d8e1dc83104': {},
      d0c9071e03a5: {},
      '7ec85a2e7d80': {},
      d0c9071e1d53: {},
      '6bd2d82d40da': {},
      d0c9071dcca1: {},
      '72f2498adfd8': {},
      d0c9071d2e59: {},
      '4194c766eb19': {},
      d93431303f45: {}
    },
    _discoveredPeripheralUUids: {
      '4870f6982a5f': true,
      '7a9e15389312': true,
      '6074f4d4bdfd': true,
      '5b672368a3c6': true,
      '66ca56170d62': true,
      e23a2682c6ed: true,
      '48e15c75dc3c': true,
      '7e552f825fdc': true,
      '6074f4447a8b': true,
      '1d8e1dc83104': true,
      d0c9071e03a5: true,
      '7ec85a2e7d80': true,
      d0c9071e1d53: true,
      '6bd2d82d40da': true,
      d0c9071dcca1: true,
      '72f2498adfd8': true,
      d0c9071d2e59: true,
      '4194c766eb19': true,
      d93431303f45: true
    },
    _events: [Object: null prototype] {
      warning: [Function (anonymous)],
      newListener: [Function (anonymous)],
      stateChange: [Function (anonymous)],
      discover: [Function (anonymous)]
    },
    _eventsCount: 4,
    _allowDuplicates: false
  },
  id: 'd93431303f45',
  uuid: 'd93431303f45',
  address: 'd9:34:31:30:3f:45',
  addressType: 'random',
  connectable: true,
  scannable: false,
  advertisement: {
    localName: undefined,
    txPowerLevel: undefined,
    manufacturerData: <Buffer 69 09 d9 34 31 30 3f 45 36 8c>,
    serviceData: [ [Object] ],
    serviceUuids: [],
    solicitationServiceUuids: [],
    serviceSolicitationUuids: []
  },
  rssi: -70,
  services: null,
  mtu: null,
  state: 'disconnected'
}
Discovered target peripheral:
  Name: SwitchBot_6909d9343130
  Address: d9:34:31:30:3f:45
  RSSI: -70
  UUID: d93431303f45
  Advertisement: {
  localName: undefined,
  txPowerLevel: undefined,
  manufacturerData: <Buffer 69 09 d9 34 31 30 3f 45 36 8c>,
  serviceData: [ { uuid: 'fd3d', data: <Buffer 48 80 e4 00> } ],
  serviceUuids: [],
  solicitationServiceUuids: [],
  serviceSolicitationUuids: []
}

But, via the node-switchbot lib itself, it seems to timeout:

homebridge@craptop:/var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot $ node w-switchbot.mjs 
Error: No devices found during discovery.
    at Timeout.<anonymous> (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/dist/switchbot-ble.js:184:32)
file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/dist/switchbot-ble.js:184
                        reject(new Error('No devices found during discovery.'));
                               ^

Error: No devices found during discovery.
    at Timeout.<anonymous> (file:///var/lib/homebridge/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/dist/switchbot-ble.js:184:32)

Node.js v22.12.0

If this seems like a separate issue LMK, happy to make a separate issue :)

nfgrep avatar Dec 16 '24 03:12 nfgrep

I think it was fixed for me updating to some latest version (v4.3.1-beta.3), but I'm now facing #1155 / #1166

Kylmakalle avatar Feb 09 '25 09:02 Kylmakalle