Passive BLE Monitor integration

I wish to ask for some assistance in trying to figure what happened to my ble integrations. It was working up to a few days ago when I had to power down the server due to a storm then i had to reboot serveral times due to a nvidia issue which was unrelated. I didn’t take much notice when it booted back up as my Ha runs in docker on ubtunu (using official image). As i logged in to check today the BLE sensors were not picked up.

Now as i see it i was on 2021.8 and i saw a support post about having to run some commands if the python was above 3.8. This was all working before. Being dumb i thought i might update to 2021.10.6 to see if a new image would help but it made things a little worse.

So now I deleted ble_monitor from my config.yaml and re added it to my integrations. I notice now the ble integration is added but nothing is configured. The configuration picks up the mac address of the BT adapter. Scan does nothing in the config. The errors are

HCIdump thread: Runtime error while sending scan request on hci0: Event loop stopped before Future completed.
8:25:45 PM – (ERROR) Passive BLE monitor (custom integration) - message first occurred at 7:54:43 PM and shows up 11 times
HCIdump thread: Runtime error while stop scan request on hci0: Event loop stopped before Future completed.
8:24:45 PM – (ERROR) Passive BLE monitor (custom integration) - message first occurred at 7:56:43 PM and shows up 9 times

Googling this it seems the BT adapter isnt being detected by the system.
A log file shows it is being detected by the container at least .

[133492.409160] usb 2-1.5: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[133492.409162] usb 2-1.5: Product: BCM20702A0
[133492.409164] usb 2-1.5: Manufacturer: Broadcom Corp
[133492.409165] usb 2-1.5: SerialNumber:

Now though when i use the BT commands it shows no devices.

hcitool lescan
Could not open device: No such device

This is most liekly the issue. I how ever can not run the following commands via the shell in the container to see if anything works.

sudo hciconfig hci0 down
sudo hciconfig hci0 up
if this doesn't work or it hangs in DOWN status, try:

sudo service bluetooth restart
sudo service dbus restart
What is the result of this command?

sudo getcap `readlink -f \`which python3\``
and

hcitool dev

hciconfig hci0 up gives - Can’t init device hci0: No error information (132)

getcap doesnt exist on the container to run.
hcitool shows nothing

So Anything else i can try here or am I doomed for now?

What is the result of the following commands?

bluetoothctl list
bluetoothctl status MA:CA:DD:RE:SS:XX
rfkill list

Also try the latest beta, it now has a feature that tries to start you Bluetooth in case of than Error.

EDIT: UPDATE!!!

Seems it might have been the USB port playing up I plugged it into another port. restarted the bluetooth on the host and rebooted the container and it come back up. Thanks ernst!


I think maybe the dongle might be dead somehow only a couple months old. I plugged it into windows and it shows up then goes “driver not available” it used to work straight up. So maybe its dead but here is the list of the commands you asked.

bluetoothctl list
dbus[1773]: arguments to dbus_connection_get_object_path_data() were incorrect, assertion "connection != NULL" failed in file dbus-connection.c line 5905.
This is normally a bug in some application using the D-Bus library.

  D-Bus not compiled with backtrace support so unable to print a backtrace
4: hci0: bluetooth
        Soft blocked: yes
        Hard blocked: no
dbus[1781]: arguments to dbus_connection_get_object_path_data() were incorrect, assertion "connection != NULL" failed in file dbus-connection.c line 5905.
This is normally a bug in some application using the D-Bus library.

  D-Bus not compiled with backtrace support so unable to print a backtrace
1 Like

Thanks for making this great component!

I installed this integration with xiaomi LYWSD03MMC. However the temperature value is showing celsius even though I select Fahrenheit from the UI. Is there a way to convert it to Fahrenheit?

That is a Home Assistant Setting. Setting → General. Change this to Imperial.

image

The BLE monitor setting is a setting telling HA in which unit the sensor sends temperature data to Home Asssistant.
The Home Assistant setting is a setting which unit it should display in the UI. If you set this to F, and a sensor has received data in °C, it will convert the temperature to F.

1 Like

Thanks. My HA already set Imperial.
I was under the wrong impression that the device sends data in Fahrenheit since I change it in the MiHome app. It seems that the device is always sending data in celsius, so I need to set it celsius in this integration, then HA will do the conversion.

Yes, stock firmware always sends data in °C, only ATC firmware can send in F, as far as I know.

:tada: New release 5.6.2 :tada:

This time we have a mix of new features, like support for the new Xiaomi Digital Temperature and Humidity Monitor sensor (XMWSDJ04MMC) with EInk screen.

We also improved the behavior of the sensors right after a restart. During the first period (minute) it will now use a rolling mean/median, which still allows the sensor to be available as soon as possible, but eliminates “bumpy” measurements in the first minute after a HA restart.

Last but not least, we have added automatic reset of the Bluetooth adapter, in case of the famous HCIdump thread: Runtime error while stop scan request on hci0: Event loop stopped before Future completed error. Unfortunately, it still doesn’t solve the actual issue, as we think this error is related to the hardware/firmware or the Operating System, but at least it will reset the Bluetooth adapter such that it will continue to work. If you want to discuss this issue further, please share your info in this issue on github

4 Likes

:tada: New release 5.7.5 :tada:

And again a new release with a new sensor, this time we added support for the Xiaogui TZC4 scale, which is basically a Xiaomi Mi Scale clone, but is using its own BLE advertisement format. We also fixed an issue with negative temperatures for some Govee sensors and fixed an issue in the report_uknown function, which was not displaying all advertisements.

2 Likes

I found an issue with the configuration of BLE monitor since 2021.11. When you open the configuration options menu of BLE monitor, the BT interface and the option report_unknown are empty, like this.

image

Selecting a MAC address and selecting submit results in

image

If you exit the menu with the X, it continues to work with the old config.

Am I the only one observing this, or is this a general issue other users also have? I have opened an issue here, so please share your experience. 2021.10.7 works fine in my case, but 2021.11.0 not (the UI also looks different). I’m looking into it, but do not have a clue yet what is wrong. No further errors in the log.

Hi Ernst.
I also get the same error :frowning:

For the time being, you can continue by selecting no BT interface at all. It will then automatically use the first one. I have tried to find out what is wrong, but I still do not have a clue why it isn’t working anymore in 2021.11. It looks like something goes wrong with the validation of the input, but I don’t understand what is wrong. I’ll keep digging, but any help is highly appreciated.

Is there an easy way to have the passive listening functionality also running on a second (non-HA) device like a pizero to resolve BLE range issues? The second device would just listen and then send updates via WiFi to this integration, or indirectly via MQTT. Has someone done it? Thanks!

Yes, ESPhome is capable of passively listening to BLE advertisements and forwarding it to HA over WiFi/mqttt.

Xiaomi Mijia BLE Sensors — ESPHome For xiaomi devices or ESPHome — ESPHome for other devices

I also get the same error

Please try with 5.8.0-beta. It should fix the issue.

what’s the best way to increase bluetooth range, like Zigbee can I add a router.

is it possible to use 2x LYWSD03MMC at the same time with 1x esp-32?

i use esphome to link it all together, but it seems i can only use one bluetooth temp sensor with them at a time.

asking so i can use less esp-32’s around the house

The FAQ of BLE monitor has the following tips for increasing range.

There are several ways to increase coverage:

  • use an external BT-dongle (preferably with a full-size antenna).
  • use multiple spaced BT-dongles. You can experiment with various extension cords (for example, inexpensive USB-RJ45 extenders in combination with a regular ethernet cable).
  • use additional devices with their own BT-interface, and connect them to Home Assistant. For example, it could be another raspberrypi with Home Assistant and our component, connected to the main host using the remote_homeassistant component, which links multiple Home Assistant instances together.

Another option is a ESPhome, as described a few post above this one

Should be possible, look at the CGG1 example on this ESPhome page

@Ernst there was an issue at one point, that 2 BT dongles didn’t work - it was a problem with HA OS. Has that been resolved?