Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

@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

Hi, I’ve just realized the breaking change as my round bluetooth temp and humidity sensor (LYWSDCGQ) had stopped reporting values. I have now changed the config according to instructions to ble_monitor:. However, after restarting Home Assistant (Home Assistant OS with Raspberry Pi 4) it still does not seem to find the new entities. I tried adding the sensor to Xiaomi’s Home app and got the reporting working fine there, so the sensor definitely works. I’m only using the bluetooth of the Pi for this one sensor / use case. Any ideas what to try next?

Hi @Magalex, I have a few of these sensors but are setup in ESPHome, I want to try your component. However, I use my HA machine’s builtin BT module for Govee Temp sensors. My machine runs Ubuntu server.

Will there be any conflict if I run both components on the same machine? I wonder if it will work. Thanks for the advise!

Did you check whether the sensor appeared under a new name (e.g. sensor.ble_temperature_MAC).

Yep, that should work just fine. ble_monitor just listens to ble messages with its ble_adapter, so no interference with esphome. Esphome uses the ble adapter of an esp device.

I’m having the same problem here for LYWSDCGQ and also a MiFlora HHCCJCY01.

I have looked for entities starting ‘ble’ however nothing is appearing.

I have installed the integration via HACS and my config YAML looks something like:

ble_monitor:
    rounding: True
    decimals: 1
    period: 60
    log_spikes: False
    use_median: False
    active_scan: False
    hci_interface: 0
    batt_entities: True
    report_unknown: False
    devices:
      - mac: 'XX:XX:XX:XX:XX:XX'
        name: MiFlora
      - mac: 'XX:XX:XX:XX:XX:XX'
        name: Xuainu

I did and checked through all my sensors and doesn’t seem to be showing. Enabled debug logs but can’t see any errors or anything noteworthy there either.

Two things you can try
try it with ble_monitor without further options first

If that doesn’t work, enable debug logging to see if it receives messages.

logger:
  default: warn
  logs:
    custom_components.ble_monitor: debug

Restart and post your log here (or create an issue on github). We first have to check if it receives messages or not.

To confirm when you say without further options do you mean:

ble_monitor:
    devices:
      - mac: 'XX:XX:XX:XX:XX:XX'
        name: MiFlora
      - mac: 'XX:XX:XX:XX:XX:XX'
        name: Xiaomi