Passive BLE Monitor integration (Xiaomi Mijia BLE MiBeacon monitor)

I have also just had a look in my log and have found the following:
Logger: custom_components.ble_monitor.sensor
Source: custom_components/ble_monitor/sensor.py:587
Integration: Passive BLE monitor integration (documentation)
First occurred: 15:30:15 (35 occurrences)
Last logged: 16:04:22

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

No, I meant ble_monitor: only.

But looking at your error, first try this (in ssh)

hcitool dev

and show the result. The message says that it doesnā€™t find the Bluetooth adapter on hci0

I ran the above and got the following result:
zsh: command not found: hcitool

For info I am running a Raspberry Pi 3.

Did you follow step 1 in the installation instructions?

Which version of HassOS do you have? There is a known issue in HassOs 4.14

I propose that you create an issue on github, that is a better place to help you.

I wasnā€™t aware I had to do the additional install instructions as the system was a standard install. In any case I canā€™t grant permissions as ā€˜set-up: command not foundā€™
I expect I have set up Terminal wrong somehow.

Iā€™m currently running version HassOS 4.17
Supervisor Version 2020.11.0

Sorry I donā€™t have much programming experience. You may be better waiting for someone that can help fault find better than me.

Is the process to capture the bind_key broken or did Xiaomi change something?
Stream can capture ā€œPOST https://api.io.mi.com/app/device/bltbind", like other reported I cannot find the ā€œbind_keyā€ in it. Text, Charles proxy or VS Code show the same informations see picture below
I have tried using different phones, removing and reinstalling Mi home. During this process the LYWSD03MMC was always removed before re-pairing it again.

Screen Shot 2020-11-22 at 12.51.08 PM

Mi Home version 5.5.2 set for china mainland
LYWSD03MMC fw 106 and fw 109
Stream - https Sniffing reports CA installed and trusted

Any idea ?

Hi,

Iā€™ve only added ble_monitor: on my config file without any options now and restarted. Iā€™ve also tried to connect via SSH but hcitool command does not exist. Itā€™s the Home Assistant OS standard installation, which has limited permissions etc. to underlying OS. I did run the other command bluetoottcl etc. and it found some devices, so I think bluetooth should be working fine on the rbpi4.

Hereā€™s some recent logs:
2020-11-22 22:40:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joining

2020-11-22 22:40:35 DEBUG (Thread-583) [custom_components.ble_monitor.sensor] HCIdump thread: main event_loop stopped, finishing

2020-11-22 22:40:35 DEBUG (Thread-583) [custom_components.ble_monitor.sensor] HCIdump thread: Run finished

2020-11-22 22:40:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joined

2020-11-22 22:40:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] Spawning HCIdump thread

2020-11-22 22:40:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: Init

2020-11-22 22:40:35 DEBUG (Thread-584) [custom_components.ble_monitor.sensor] HCIdump thread: Run

2020-11-22 22:40:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] 2825 HCI Events parsed, 0 valuable MiBeacon BLE ADV messages. Found 0 known device(s) total. Priority queue = 0

2020-11-22 22:40:35 DEBUG (Thread-584) [custom_components.ble_monitor.sensor] HCIdump thread: connected to hci0

2020-11-22 22:40:35 DEBUG (Thread-584) [custom_components.ble_monitor.sensor] HCIdump thread: start main event_loop

2020-11-22 22:41:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joining

2020-11-22 22:41:35 DEBUG (Thread-584) [custom_components.ble_monitor.sensor] HCIdump thread: main event_loop stopped, finishing

2020-11-22 22:41:35 DEBUG (Thread-584) [custom_components.ble_monitor.sensor] HCIdump thread: Run finished

2020-11-22 22:41:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: joined

2020-11-22 22:41:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] Spawning HCIdump thread

2020-11-22 22:41:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: Init

2020-11-22 22:41:35 DEBUG (Thread-585) [custom_components.ble_monitor.sensor] HCIdump thread: Run

2020-11-22 22:41:35 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] 2686 HCI Events parsed, 0 valuable MiBeacon BLE ADV messages. Found 0 known device(s) total. Priority queue = 0

2020-11-22 22:41:35 DEBUG (Thread-585) [custom_components.ble_monitor.sensor] HCIdump thread: connected to hci0

2020-11-22 22:41:35 DEBUG (Thread-585) [custom_components.ble_monitor.sensor] HCIdump thread: start main event_loop

@Ernst a bit wrongā€¦ The Govee integration uses the same data retrieval method (and based on our old code) as our component. Unfortunately, a conflict is inevitable, but you can still try, since both components use the same operating mode of the bluetooth module, so the negative effect of this conflict may be invisible or acceptable. Just try it!

@EduNeiva and @soruam
Unfortunately, guys, Xiaomi at the end of July, as I managed to find out, turned on additional encryption of the api requests. The key can still be obtained, but to do this, you need to intercept the request containing the ssecurity field (it appears in MiHome traffic when you login into your Mihome account), and using the ssecurity key, you can then decrypt the bltbind request content (I did this using a separate python script). In general, the procedure has become much more complicated, and the simplest method at the moment is to use a custom firmware (for LYWSD03MMC) or use special MiHome mod from vevs (there is a link in our FAQ).

1 Like

@fuziduck have you tried hci_interface: 1?

@Tuomas judging by your log, the component works fine (receives events from the bluetooth interface), but for some reason does not see any useful ones among them.
Please show us your config for the component and try the discovery: True option. Also, make sure that the mac-addresses of your sensors are configured correctly.

Hi everyone,
does the whole thing work with the integrated bluetooth of raspberry 4?

@Magalex
Thank you for the prompt response. I was able to get the key installing Chrome (I am not a google fan) on my computer and with that accessing TelinkFlasher. NO other browser worked for me.
Thank you again

1 Like

Hi Magalex. That didnā€™t work Iā€™m afraid.
I have a feeling there is a wider issue with the internal Raspberry Pi 3 bluetooth adapter and the Home Assistant update as I have a ā€˜Switchbotā€™ that is no longer responding either.

I just installed HassOS 4.17 on my raspberry 3b+, and I am not experiencing any problems with the component. Usually, this error indicates that bluetooth is turned off. Someone else had it so that hci0 was missing, but hci1 worked, which is also very strangeā€¦

Yes, there are reviews that work. However, there are also some strange issues. For example, someoneā€™s wifi falls off, or other strange errors. Unfortunately, I have no accurate information on how many users are doing well on rpi4ā€¦

Same here. I used telinkflasher to flash a custom firmware that does not need the bind key.

Thanks. Got it working by defining the mac address and having the discovery: true as well. Might have also been a range issue as I did recently move the sensor to another location a bit further away from the pi4. Iā€™ll experiment a bit further, but my first suspect is the range, second that maybe I needed to define the mac address and perhaps third the discovery option, but I guess the default is true for that anyway.

Edit: can confirm it was a range issue. All good now.

1 Like

Hi guys,
can you tell me how the settings are in HA?
Did you get that with em Rpi 4 without an additional Bluetooth adapter?

Do I have to create this conguration in addition?
device_tracker:

  • platform: bluetooth_le_tracker

Or just
ble_monitor: ?

Thank you.

Hi,
i add ble_monitor component in my Home Assistant (raspberry pi4).
Insert in config yaml but i get this error in logs:

2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] BLE monitor initialization
2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] 0 encryptors mac:key pairs loaded.
2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] whitelist: []
2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] 0 whitelist item(s) loaded.
2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] BLE monitor initialized
2020-11-24 11:21:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] Dataparser loop started!
2020-11-24 11:21:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] Spawning HCIdump thread
2020-11-24 11:21:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] HCIdump thread: Init
2020-11-24 11:21:36 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: Run
2020-11-24 11:21:36 DEBUG (Thread-6) [custom_components.ble_monitor.sensor] HCIdump thread: connected to hci0
2020-11-24 11:21:36 DEBUG (SyncWorker_3) [custom_components.ble_monitor.sensor] Platform setup finished
2020-11-24 11:22:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] HCIdump thread: joining
2020-11-24 11:22:36 ERROR (Thread-6) [root] Uncaught thread exception
Traceback (most recent call last):
File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/home/homeassistant/.homeassistant/custom_components/ble_monitor/sensor.py", line 595, in run
self._event_loop.run_until_complete(btctrl[hci].send_scan_request(self._active))
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 614, in run_until_complete
raise RuntimeError('Event loop stopped before Future completed.')
RuntimeError: Event loop stopped before Future completed.
2020-11-24 11:22:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] HCIdump thread: joined
2020-11-24 11:22:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] Spawning HCIdump thread
2020-11-24 11:22:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] HCIdump thread: Init
2020-11-24 11:22:36 DEBUG (Thread-35) [custom_components.ble_monitor.sensor] HCIdump thread: Run
2020-11-24 11:22:36 DEBUG (Thread-5) [custom_components.ble_monitor.sensor] 0 HCI Events parsed, 0 valuable MiBeacon BLE ADV messages. Found 0 known device(s) total. Priority queue = 0
2020-11-24 11:22:36 DEBUG (Thread-35) [custom_components.ble_monitor.sensor] HCIdump thread: connected to hci0

Can you help?