Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

Xiaomi-cloud-key-extractor been updated. It will now extract your Bluetooth encryption keys from the Xiaomi cloud as well, which is needed for some sensors in BLE monitor :partying_face:. Thanks to the help of @rezmus it is now much easier than before to get the required keys. Works on Windows as well as Linux.

3 Likes

Hello, I guess I have same problem as above, I’ve added to my configuration.yml following:

ble_monitor:
  devices:
    - mac: 'A4:C1:38:14:0A:72'
      name: 'XIAOMI Mijia Bluetooth Thermometer 2 in Office'

on page http://homeassistant.local:8123/config/integrations integration is visible: Passive BLE monitor - Bluetooth Low Energy Monitor but no devices/entities are added. When I removed configuration from yaml and try to configure it via UI I was able to see my device on configuration dialog pulldown list but same: no devices/entities added. I’m running Home Assistant OS on Raspberry pi 4. No other bluetooth devices/integratons added. Please advise how to proceed?

Which sensor do you have? Some sensors need an encryption key, you can find this by checking your sensor description on the main page of the ble monitor

I’ve got LYWSD03MMC flashed with telink flasher to ATC firmware. Now it works without specifying encryption key in yaml - is it possible that it remembers some settings from UI and merges them?
Finally I’ve got device/entities added - is it normal to have to wait several hours to get this working?
Unfortunatelly readings are inconsistent:


This device is like 1,5 meter away from raspberry in the same room, do you have any recomendations how to improve readings stability? Other firmware or changing some params?

new window/door and motion sensors from qingping.

The faq gives some hints on improving reliability. Most of the times, it’s an SSD drive that is interfering with the Bluetooth signal. If you have good reception, it should work within one minute. In the above screenshot, I see 6 messages in one minute, which is normal.

If you have data from these sensor, I can add them to ble monitor.

what data do you need?

The FAQ gives a good description on how to collect the data (ble advertisements) from the sensor. With this data, I can add the sensor to ble monitor.

i don’t use HA or any bluetooth stick, but i can give you events from BLE gateway log

cgllc.magnet.hodor
“pd_id”: 982 = b’\xD6\x03’: (“CGH1”, False),

events same as mijia window/door sensor 2

“evt”:[{“eid”:4121,“edata”:“01”}] - closed
“evt”:[{“eid”:4121,“edata”:“00”}] - open
“evt”:[{“eid”:4121,“edata”:“02”}] - open for 1m

cgllc.motion.cgpr1
“pd_id”: 2691 = b’\x83\x0A’: (“CGPR1”, False),

events similar to mijia motion sensor 2, but it supports lux not just dark/bright

“evt”:[{“eid”:15,“edata”:“490300”}] - motion + lux
“evt”:[{“eid”:4119,“edata”:“3c000000”}] - no motion since sent on 1m, 2m, 5m, 10m, 20m, 30m with time
“evt”:[{“eid”:4103,“edata”:“490300”}] - lux sent every ~10m (does not depend on lux change)

they both send events like battery level or rssi. both encrypted. motion can trigger every ~15s, but it needs 10-15s of constant time without motion to trigger next motion event. i have some problem with it. all automations even local have ~3s lag compared to motion sensor 2 from lumi. hope it’s firmware thing and will be fixed.

Didn’t know that you don’t use HA. Even more appreciated that you share this info.

I think that it would be good if a user of HA that has one of these sensors is willing to test it. I can add it, but without someone actually testing it doesn’t seem right. So, if someone wants this sensor to be implemented, just create an issue on github, and I will add it.

Edit: Actually, I changed my mind, it looks pretty much the same as the existing sensors (except the lux value). @rezmus, do you know if these sensors need an encryption key?

yes, both need key. for motion sensor you can set firmware option of detection interval (5-60s, but maybe it can be less). i still have problem with delayed event on motion (2-4s delay in mijia local automation).

edit: i found something strange considering my delay issue with qingping motion sensor. when looking at sislab_ncp_bt logs on mgl03 hub i found out that it triggers 4119 event (with 0 value to clear no motion since) quite fast after i do motion. maybe not so fast as mijia ble motion 2, but under 1s. however real motion event always goes with 2s delay after 4119 is cleared (look at gwts).


[D] : TX: {"id":123,"method":"_async.ble_event","params":{"dev":{"did":"blt.4.X","mac":"58:2D:34:XX:YY:ZZ","pdid":2691},"evt":[{"eid":4119,"edata":"00000000"}],"frmCnt":108,"gwts":1613894629}}
[D] : RX: {"result":"ok","id":123}
[D] : TX: {"id":123,"method":"_async.ble_event","params":{"dev":{"did":"blt.4.X","mac":"58:2D:34:XX:YY:ZZ","pdid":2691},"evt":[{"eid":15,"edata":"690000"}],"frmCnt":109,"gwts":1613894631}}
[D] : RX: {"result":"ok","id":123}

Hi, this happened to me also at the beginnig. I flashed all sensors with ATC firmware, removed completely the integration / component (i had config in config.yaml - removed and use only integrations) and reinstalled everything. Now works fine

Supervisor suddenly decided to remove my Bluetooth USB device!!!

21-02-24 04:53:44 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/103

I noticed quite quickly but really???

A quick look through the syslog and it seems this happens fairly regularly! ON the last occasion though, it did not add it back in. Looking at the incrementing numbers this seems to be happening a lot.

The final ‘ADD’ is me manually removing and reinserting the dongle.

/var/log/syslog:Feb 24 04:53:44 hassio hassio-supervisor[7409]: #033[32m21-02-24 04:53:44 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/103#033[0m
/var/log/syslog:Feb 24 06:53:57 hassio hassio-supervisor[7409]: #033[32m21-02-24 06:53:57 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/104#033[0m
/var/log/syslog.1:Feb 23 06:21:51 hassio hassio-supervisor[7409]: #033[32m21-02-23 06:21:51 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/096#033[0m
/var/log/syslog.1:Feb 23 06:21:54 hassio hassio-supervisor[7409]: #033[32m21-02-23 06:21:54 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/097#033[0m
/var/log/syslog.1:Feb 23 09:13:26 hassio hassio-supervisor[7409]: #033[32m21-02-23 09:13:26 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/097#033[0m
/var/log/syslog.1:Feb 23 09:13:30 hassio hassio-supervisor[7409]: #033[32m21-02-23 09:13:30 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/099#033[0m
/var/log/syslog.1:Feb 23 10:36:10 hassio hassio-supervisor[7409]: #033[32m21-02-23 10:36:10 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/099#033[0m
/var/log/syslog.1:Feb 23 10:36:13 hassio hassio-supervisor[7409]: #033[32m21-02-23 10:36:13 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/100#033[0m
/var/log/syslog.1:Feb 23 18:17:46 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:17:46 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/100#033[0m
/var/log/syslog.1:Feb 23 18:17:48 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:17:48 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/101#033[0m
/var/log/syslog.1:Feb 23 18:33:22 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:33:22 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/101#033[0m
/var/log/syslog.1:Feb 23 18:33:25 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:33:25 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/102#033[0m
/var/log/syslog.1:Feb 23 18:43:51 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:43:51 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.REMOVE usb hardware /dev/bus/usb/001/102#033[0m
/var/log/syslog.1:Feb 23 18:43:54 hassio hassio-supervisor[7409]: #033[32m21-02-23 18:43:54 INFO (MainThread) [supervisor.hardware.monitor] Detecting HardwareAction.ADD usb hardware /dev/bus/usb/001/103#033[0m

I have seen several users on github with similar problems (at least that bluetooth isn’t working anymore all of a sudden). For me, it is working fine again after a full restart of the entire system (not only HA). Not sure if it is solving your issue, but it is worth to try. It seems to have started with one of the supervisor updates recently.

1 Like

Hi!
I’m trying to configure Passive BLE monitor Integration with a Xiaomi LYWSD03MMC.
I’m running Home Assistant in a VM with Virtual Box.

Successfully completed the following installation steps:

  • Install the custom integration
  • Add your sensors to the MiHome app
  • Configure the integration (tried in the User Interface and YAML)

I allways get the following error message:

Logger: custom_components.ble_monitor
Source: custom_components/ble_monitor/__init__.py:592
Integration: Passive BLE monitor (documentation)
First occurred: February 24, 2021, 7:42:14 PM (2456 occurrences)
Last logged: 9:25:35 AM

HCIdump thread: OS error (hci0): [Errno 19] error while attempting to bind on interface 0: No such device
HCIdump thread: OS error (hci1): [Errno 19] error while attempting to bind on interface 1: No such device
HCIdump thread: OS error (hci2): [Errno 19] error while attempting to bind on interface 2: No such device

i suspect this can be related with the Bluetooth configuration itself in Virtual Box? It seems to correctly show the Bluetooth in the USB settings.

Thanks!

This error means that hcitools can’t access your Bluetooth on the host machine. This topic (last message) explains it a bit further (https://www.reddit.com/r/homeassistant/comments/i88hbm/how_to_install_missing_hclitools_in_home/). In short, it seems that it is not possible to access hci in a VM with internal Bluetooth on the host system, you will need an external usb dongle.

1 Like

Thanks. That’s what I suspected, but as the Bluetooth appears in the VirtualBox USB and it even disconnects in the host, I thought it could be something else. I guess it won’t work in VM this way.

The following sensors have been added in passive BLE monitor.

  • Xiaomi Mi Motion Sensor 2 (RTCGQ02LM)
  • Qingping Door/window contact sensor (GCH1)
  • Qingping Motion and ambient light sensor (GCPR1)

I’ve all sensors working! One thing for sure was that despite Telink Flasher for Mi Thermostat shows disconnected state, my sensor was still connected in osx Bluetooth settings.
For other sensors I’m not entirely sure what worked, but I flashed ATC firmware, replaced battery, reset HA multiple times. I think that most confusing thing was that sensors does not appear instantly in HA despite adding them to configuration.yml. Also I wasn’t able to enable debug logs despite following steps nothing happens, but HA does not allow to show logs from certain integration anyways so maybe other integrations were too verbose and I just missed entries.
Many Thanks for great integration @Ernst!