Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

Can you run the following command and report back the response

hcitool dev

Did you add the sensor to the MiHome app?

Indeed I was able to add them to the MiHome app v5.8.42, it was easely discovered and configured, but I wasn’t able to add it to the old MiHome v5.0.0 , it did not discover it (probably because by then this devices did not exist).

That’s why I used the Qingping+ app since it discovers it and records information in the qingping.log file that I believe is the correct one (maybe I’m wrong)

Getting hcitool: command not found

Running bluetoothctl leaves me with Waiting to connect to bluetoothhd... hanging.

Looks like Bluetooth / hcitools is not installed. Are you using Ubuntu or raspberry-os? Have a look here for a solution to try.

I’m using Hassio on a raspberry pi 4

Edit: it appears I might have disabled bt during my Razberry v2 module set up. I might need to explore a different z-wave controller or research other options.

Yes, that will be it. The onboard Bluetooth device of the Raspberry Pi will be disabled by adding dtoverlay=disable-bt

@Ernst were you talking about what version of the MiHome app?

@Flink As far as I know, devices from Qingping (some or all) support two protocols - Mijia BLE and its own Qingping. It is possible that without pairing the sensor in the MiHome application, it will not send MiBeacon messages at all.

I think Ernst did not mean a specific version. If you have difficulty getting the encryption key, then try looking for a modified version from Vevs (there is a link in our FAQ (point 3), I’ve heard a lot of positive reviews about this mod).

@Flink No, I didn’t mean the version. As @Magalex explains, I expect that you have to add in the MiHome app to make sure it uses the Mijia BLE protocol. I don’t know which protocol the Qingping app uses, but it might be different.

@Magalex @Ernst thanks for your replies! I’m hopefully one step closer, but there yet :slight_smile:

After using the mi home version from Vevs, I in fact got the bindkey from the text file, but it still does not seem to work :expressionless:
The bindkey is different from the one I was previously using (that I got from the Qingping+ app).
Not sure if it matters, but I was unable to pair/add the device on the mi home app, if gives me an error on the pairing sequence sayig: Standard verification failure (-51).

Bellow are the logs from HA
As far as I can (think) to understand, ha received 3 packages but was unable to decipher them

2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] update_ble called
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Discovering Bluetooth LE devices
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Time to analyze...
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Getting data from HCIdump thread
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] HCIdump thread: joining
2020-11-17 13:25:04 DEBUG (Thread-37) [custom_components.ble_monitor.sensor] HCIdump thread: main event_loop stopped, finishing
2020-11-17 13:25:04 DEBUG (Thread-37) [custom_components.ble_monitor.sensor] HCIdump thread: Run finished
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] HCIdump thread: joined
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Spawning HCIdump thread(s).
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] HCIdump thread: Init
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] HCIdump thread: Init finished
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Starting HCIdump thread for hci0
2020-11-17 13:25:04 DEBUG (Thread-38) [custom_components.ble_monitor.sensor] HCIdump thread: Run
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] HCIdump threads count = 1
2020-11-17 13:25:04 DEBUG (Thread-38) [custom_components.ble_monitor.sensor] HCIdump thread: Connection
2020-11-17 13:25:04 DEBUG (Thread-38) [custom_components.ble_monitor.sensor] HCIdump thread: Connected
2020-11-17 13:25:04 DEBUG (Thread-38) [custom_components.ble_monitor.sensor] HCIdump thread: start main event_loop
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed: MAC check failed
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] token: a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] nonce: d90d53342d58760589000000
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] encrypted_payload: 6b67367c1f000000a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] cipherpayload: 6b67367c1f
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed for 582D3453****, decrypted payload is None
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed: MAC check failed
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] token: a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] nonce: d90d53342d58760589000000
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] encrypted_payload: 6b67367c1f000000a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] cipherpayload: 6b67367c1f
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed for 582D3453****, decrypted payload is None
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed: MAC check failed
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] token: a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] nonce: d90d53342d58760589000000
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] encrypted_payload: 6b67367c1f000000a0cb0c83
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] cipherpayload: 6b67367c1f
2020-11-17 13:25:04 ERROR (SyncWorker_12) [custom_components.ble_monitor.sensor] Decryption failed for 582D3453****, decrypted payload is None
2020-11-17 13:25:04 DEBUG (SyncWorker_12) [custom_components.ble_monitor.sensor] Finished. Parsed: 567 hci events, 1 xiaomi devices.

my current configuration is

ble_monitor:
  active_scan: True
  batt_entities: True
  discovery: False
  report_unknown: False
  devices:
    - mac: '58:2D:34:53:**:**'
      name: 'Bed_Clock'
      encryption_key: '6fbfff4b18a67cae45fdf7b5********'
      temperature_unit: C

Any ideas?

Yes, messages from the device come, but the encryption key does not fit…
The device must be bound with the app since it is during the binding process the encryption key is generated and saved. I don’t understand how at least something worked for you… The error “Standard verification failure (-51)” may not refer to the exchange with the device, but to the exchange with Xiaomi web services via the https protocol. Is the internet good on your android? Is you android date / time correct? Firewalls / proxies / VPNs? No other ideas yet…

In the MiHome application, the selected region also matters. See which one you have there, and try to play with it - many problems were solved by setting it to Mainland China.

AHA! I see the light :smiley:
How you may ask? By starting from scratch on another CGD1 device (got 4 in total) I realised the process works and I was doing something on the initial device.

The bindkey from the first device, seemed to get changed upon the device pairing/adding on the MiHome.
I mentioned before that I managed to get the key but the device was not properly added to the MiHome app, well, I deleted the text files generated by the Vevs mod and run the process all over again, and after adding/pairing, the bindkey changed and now I can see the device on HA.

Nevertheless, I have the batt_entities: True option on the configuration but not all the sensor.ble_battery_XXX entities generated shows value (some say Unknown), and the atribute battery_level isn’t present on the sensor.ble_temperature_*** entity

Battery level is not broadcasted as often as the other measurements. Give it some time.

Exactly!
I need to add the be_patient:True parameter on my own config file.

The CGD1 battery levels started to show up, only from the LYWSD02 devices is missing. I’m give it time

Can the ble_monitor sensor be used as device tracker? I want to use it to detect the presence of nearby bluetooth devices.
Thanks for this great custom component!

This is planned for the future, but for now we are too busy with current issues …

1 Like

Ok. Thank you!

successfully follow the procedure until step 6. I was able to capture “POST https://api.io.mi.com/app/device/bltbind”, but I did not find “bind_key” as described in step 7.
Any tips? Thanks