Gladys Assistant 4.2 is available with Zigbee2mqtt compatibility! 🚀

we shoule talk in english T.T

@bulolo we have an international category for english talk :slight_smile:

Hello everyone,

I just tested the ZZH (CC2652R) key after flashing it with the coordinator firmware. I followed the tutorial to enable the Zigbee2Mqtt integration and before I could scan any equipment, I realized that the Bluetooth module was no longer working
 After rebooting Gladys, the Bluetooth device scan menu tells me that the module is disabled.
I saw in another topic that @Tlse-vins also has the ZZH key. Have you noticed the same kind of malfunctions with Bluetooth?

Hello,
I also have the ZZH key but on my side Bluetooth works perfectly, I have already had problems with Bluetooth but in my case a reboot of the host and not just the container was enough to solve the problem


I haven’t had any issues with Bluetooth either. Even before the key, device detection worked fine.

Oh no! So I reinstalled my instance because it was impossible to reactivate the Bluetooth that I use a lot, especially with the arrival of version 4.3! I still kept the log to dig through when I have some time.

@Mastho what was your problem with Bluetooth?

After connecting and installing Zigbee2Mqtt, I noticed that users were marked as absent on the Dashboard for exactly the same duration. To check, I tried a Bluetooth device scan that started spinning without ever displaying anything. I tried stopping and then restarting the Bluetooth service without success. I finally did a reboot of the Raspberry and when I returned to the Bluetooth scan page, a yellow banner indicated that the Bluetooth module was disabled.

Ouch, ok there might be an incompatibility between Bluetooth and zigbee2mqtt


Unfortunately, Bluetooth uses an NPM dependency that is terribly buggy (there isn’t anything better on the market unfortunately). We’ll investigate then

@VonOx @AlexTrovato any idea what could be blocking here?

No conflict for me, the zigbee2mqtt firmware for the zzh! does not use the Bluetooth of the chip, so no link.

Ok, that’s reassuring :slight_smile:

@Mastho we would like the logs then

Okay, I’ll transfer that as soon as possible :slight_smile:

I’m reposting here the error you sent me by email @Mastho :slight_smile:

2021-04-25T15:20:35+0200 <error> index.js:16 (process.<anonymous>) Error: Could not start scanning, state is unknown (not poweredOn)
    at Noble.scan (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:107:21)
    at Noble.startScanning (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:136:10)
    at /src/server/services/bluetooth/lib/commands/bluetooth.scan.js:67:24
    at Promise._execute (/src/server/services/bluetooth/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:103:10)
    at BluetoothManager.scan (/src/server/services/bluetooth/lib/commands/bluetooth.scan.js:35:12)
    at BluetoothManager.scanPresence (/src/server/services/bluetooth/lib/commands/bluetooth.scanPresence.js:26:36)
2021-04-25T15:21:35+0200 <error> index.js:15 (process.<anonymous>) unhandledRejection catched: Promise {
  <rejected> Error: Could not start scanning, state is unknown (not poweredOn)
      at Noble.scan (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:107:21)
      at Noble.startScanning (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:136:10)
      at /src/server/services/bluetooth/lib/commands/bluetooth.scan.js:67:24
      at Promise._execute (/src/server/services/bluetooth/node_modules/bluebird/js/release/debuggability.js:384:9)
      at Promise._resolveFromExecutor (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:518:18)
      at new Promise (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:103:10)
      at BluetoothManager.scan (/src/server/services/bluetooth/lib/commands/bluetooth.scan.js:35:12)
      at BluetoothManager.scanPresence (/src/server/services/bluetooth/lib/commands/bluetooth.scanPresence.js:26:36)
}

I looked a bit on the internet, and I found this:

I think there is a small lifecycle issue with the bluetooth service.

@AlexTrovato what do you think about it?

I think there’s a hole in the racket.
@Mastho in the Gladys settings, you should find the list of services, can you try reactivating Bluetooth, while capturing the logs?
We can switch to private messages for « sensitive Â» exchanges if you prefer.

Hi @AlexTrovato,
I had to do a reinstall because I couldn’t find a way to get Bluetooth working again, so I won’t be able to do the test. However, in the log that I kept and transferred to @pierre-gilles, there is a moment where I restart the Bluetooth service. I’ll try to find that for you :slight_smile:

2021-04-25T15:15:32+0200 <error> index.js:16 (process.<anonymous>) Error: Could not start scanning, state is unknown (not poweredOn)
    at Noble.scan (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:107:21)
    at Noble.startScanning (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:136:10)
    at /src/server/services/bluetooth/lib/commands/bluetooth.scan.js:67:24
    at Promise._execute (/src/server/services/bluetooth/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:103:10)
    at BluetoothManager.scan (/src/server/services/bluetooth/lib/commands/bluetooth.scan.js:35:12)
    at BluetoothManager.scanPresence (/src/server/services/bluetooth/lib/commands/bluetooth.scanPresence.js:26:36)
2021-04-25T15:15:32+0200 <info> index.js:26 (Object.stop) Stopping Bluetooth service
2021-04-25T15:15:32+0200 <info> bluetooth.stop.js:13 (BluetoothManager.stop) Bluetooth configuration: stopping presence scanner
2021-04-25T15:15:35+0200 <info> index.js:15 (Object.start) Starting Bluetooth service
2021-04-25T15:15:35+0200 <info> bluetooth.initPresenceScanner.js:18 (BluetoothManager.initPresenceScanner) Bluetooth configuration: starting presence scanner
2021-04-25T15:15:35+0200 <error> index.js:15 (process.<anonymous>) unhandledRejection catched: Promise {
  <rejected> Error: Could not start scanning, state is unknown (not poweredOn)
    at Noble.scan (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:107:21)
    at Noble.startScanning (/src/server/services/bluetooth/node_modules/@abandonware/noble/lib/noble.js:136:10)
    at /src/server/services/bluetooth/lib/commands/bluetooth.scan.js:67:24
    at Promise._execute (/src/server/services/bluetooth/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/src/server/services/bluetooth/node_modules/bluebird/js/release/promise.js:103:10)
    at BluetoothManager.scan (/src/server/services/bluetooth/lib/commands/bluetooth.scan.js:35:12)
    at BluetoothManager.scanPresence (/src/server/services/bluetooth/lib/commands/bluetooth.scanPresence.js:26:36)
}

Ok super, it seems like it’s « simple Â». The presence scanner is launched while Bluetooth is not initialized.

However, @Mastho, do you confirm that Bluetooth never returned to a functional state?

Yes, I couldn’t restore it. In addition to restarting the Bluetooth service, I tried stopping the Zigbee2Mqtt service since that’s when I lost Bluetooth, but without success. And I ended up with a reboot of the Raspberry.

@AlexTrovato I looked at the code of the old bluetooth service in Gladys 3, and indeed we only launched a scan when the state was « poweredOn Â» (cf https://github.com/GladysAssistant/gladys-bluetooth/blob/master/lib/scan.js)

In the case of the bluetooth service on Gladys 4, it seems we launch the scan without checking the state!

cf => Gladys/server/services/bluetooth/lib/commands/bluetooth.scan.js at master · GladysAssistant/Gladys · GitHub

Yet we do record in a variable « ready Â» when the bluetooth is ready. We just need to use the variable :slight_smile:

Would it work if we added « this.ready Â» before starting the scan:

if (!this.scanning && this.ready) {
   this.bluetooth.startScanning([], true);
}

Would that do the trick?

This is the only place where the « startScanning Â» function is called, and it would prevent the error we’re seeing