BLE device tracker stops after an hour or so "unexpected error when scanning"

Yeah, i was using the standard HA BLE integration.

I’ve copied the ble_track folder into custom_components, what else do i need to do to use it? Cos i’m not sure its loaded, nothing in log about loading custom components???

Thanks

So I’m not getting actual errors anymore, but the device tracker is still briefly flicking to ‘not_home’ for a few seconds while the BLE scan is in progress…

Screenshot 2021-03-21 at 16.59.09

2021-03-21 16:54:16 DEBUG (SyncWorker_3) [homeassistant.components.bluetooth_le_tracker.device_tracker] Discovering Bluetooth LE devices
2021-03-21 16:54:16 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Starting BLE scan
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 4F:A8:7E:4E:18:BD (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 3B:9D:38:A2:35:A3 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 70:2A:D5:63:56:53 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of 70:2A:D5:63:56:53 as [TV] Samsung 7 Series (55)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 79:D9:8D:63:F6:D9 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 07:E2:FA:20:E4:20 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 88:C6:26:AB:95:B7 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 94:53:30:B2:3C:14 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered D4:A6:51:8F:07:2A (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 78:BD:BC:89:AC:E8 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 7A:05:3A:D0:6C:B8 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 65:6D:E9:11:EB:18 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 71:3D:BE:45:D0:FB (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 59:30:7E:6F:7E:36 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of D4:A6:51:8F:07:2A as TY
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 59:49:A1:61:34:09 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered D8:9E:2C:29:8F:C9 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of D8:9E:2C:29:8F:C9 as Tile
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered EB:43:38:53:C7:D1 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 68:12:CF:FA:6D:3E (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 08:EF:3B:FD:E8:3F (LG SJ6(BC:D0))
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 80:EA:CA:89:15:7C (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of 80:EA:CA:89:15:7C as Flower care
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered CB:EA:8F:28:B0:0C (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 29:8A:CF:5E:F7:BC (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 60:18:0A:AF:DC:74 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 7D:BD:BD:86:7A:13 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered F0:1C:FD:38:52:9E (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of F0:1C:FD:38:52:9E as Tile
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 50:5C:C8:21:4C:01 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 28:56:5A:30:4A:C0 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered 44:90:B6:E7:E2:46 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered CD:F4:1A:40:CB:05 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered E4:F7:07:4F:AA:80 (None)
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Discovered name of 78:BD:BC:89:AC:E8 as [TV] UE55JU6510
2021-03-21 16:54:28 INFO (SyncWorker_3) [pygatt.backends.gatttool.gatttool] Found 29 BLE devices
2021-03-21 16:54:28 DEBUG (SyncWorker_3) [homeassistant.components.bluetooth_le_tracker.device_tracker] Bluetooth LE devices discovered = {'4F:A8:7E:4E:18:BD': None, '3B:9D:38:A2:35:A3': None, '70:2A:D5:63:56:53': '[TV] Samsung 7 Series (55)', '79:D9:8D:63:F6:D9': None, '07:E2:FA:20:E4:20': None, '88:C6:26:AB:95:B7': None, '94:53:30:B2:3C:14': None, 'D4:A6:51:8F:07:2A': 'TY', '78:BD:BC:89:AC:E8': '[TV] UE55JU6510', '7A:05:3A:D0:6C:B8': None, '65:6D:E9:11:EB:18': None, '71:3D:BE:45:D0:FB': None, '59:30:7E:6F:7E:36': None, '59:49:A1:61:34:09': None, 'D8:9E:2C:29:8F:C9': 'Tile', 'EB:43:38:53:C7:D1': None, '68:12:CF:FA:6D:3E': None, '08:EF:3B:FD:E8:3F': 'LG SJ6(BC:D0)', '80:EA:CA:89:15:7C': 'Flower care', 'CB:EA:8F:28:B0:0C': None, '29:8A:CF:5E:F7:BC': None, '60:18:0A:AF:DC:74': None, '7D:BD:BD:86:7A:13': None, 'F0:1C:FD:38:52:9E': 'Tile', '50:5C:C8:21:4C:01': None, '28:56:5A:30:4A:C0': None, '44:90:B6:E7:E2:46': None, 'CD:F4:1A:40:CB:05': None, 'E4:F7:07:4F:AA:80': None}

Hi davefrooney, yes I am using the standard HA BLE using …

device_tracker:
  - platform: bluetooth_le_tracker
    track_new_devices: False

Is there any alternative that I should try from your perspective?

Cheers

This is the config I am using. I am also using an esp32 to track bluetooth devices which I found to be very reliable. This is setup with esphom

  - platform: ble_track
    track_new_devices: false
    interval_seconds: 15
    device_id: hci0
    hide_unnamed: true
    new_device_defaults:
      track_new_devices: false

I made a small change to the official integration that stops the scan from crashing. It is in my github

Hi davefrooney, actually I am trying to reduce additional risk of failures in my setup. And your proposal would mean an additional device and an additional SW component (which must be maintained on the long run). To avoid additional risks I actually bet on Pi4 (bringing bluetooth by default) and the standard integration bluetooth_le_tracker. Anyone idea how to get the standard integration fully working without errors? Cheers

I am using the esp32 as an additional tracker. The above integration runs directly on the pi

Ah, great. I’ve got your custom component working now. Realised I hadn’t changed the platform to ‘ble_track’.

So far so good, reliably tracked for half an hour or so. :crossed_fingers:

Thank you.

i do have the same error, but i am using a USB bluetooth dongle on my Raspberry 4.

Can i use the modified config ? should i do something else before like disabling the build-in bluetooth on my pi4 first ?

I have the error a lot and often when i restart the Home Assistant , i have to unplug the dongle and plug it back to make everything works for a while.

I’m not too sure about that but you can specify a device as an option. You should try getting the device path and enter it like this

  - platform: ble_track
    track_new_devices: true
    device_id: /path/to/usb
    scan_duration: 20
    interval_seconds: 12

thanks for that, i’m trying to find witch usb i am using, or witch HCI i am using. I’m on a pi4 + a bluetooth and i find it pretty hard to find the information! bluetoothctl command show me 2 mac but i do need to find out witch usb (and hci) i am using.

Hello @davefrooney, I am trying to get Bluetooth LE tracking working on my Home Assistant. I tried using the “baked in version” using:

device_tracker: 
    - platfrom: bluetooth_le_tracker

I was getting various errors and came across this thread, so want to give you custom component a try. I am fairly new and have only installed official integrations and integrations through HACS. I looked on your page and did not see any readme file or anything.

From reading through the posts, I understand that I have to copy some of the files into the custom component folder. But can you walk me through the steps exactly, i.e. which files need to be put into the custom component folder. I appreciate any help you are able to offer.

Thank you.

For BLE tracking the problem is in the tools it depends on, those binaries used to manage the BT environment that with recent (and even not so recent) HW is becoming even more buggy: hciconfig, bluetoothctl and so on. The BT scan at a certain point will not exit from the current cycle and will remain stuck preventing new scans and writing errors in the log.
If you are using HA installed with the Home Assistant OS (Hassio) I don’t have a solution, but if you are using Home Assistant Supervised I wrote a quite simple watchdog that I can say resolve the problem.