core
core copied to clipboard
bluetooth_tracker doesn't work in 2022.7.x (not compatible with python 3.10)
The problem
No devices are located by bluetooth_tracker. In registry I found that stacktrace:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 197, in update_bluetooth
await perform_bluetooth_update()
File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 175, in perform_bluetooth_update
rssi = await hass.async_add_executor_job(client.request_rssi)
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.10/site-packages/bt_proximity/bt_rssi.py", line 55, in request_rssi
self.prep_cmd_pkt()
File "/usr/local/lib/python3.10/site-packages/bt_proximity/bt_rssi.py", line 24, in prep_cmd_pkt
b'6sB17s', bt.str2ba(self.addr), bt.ACL_LINK, b'\0' * 17)
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Possibily, it is related to Python3.10
What version of Home Assistant Core has the issue?
2022.7.3
What was the last working version of Home Assistant Core?
2022.6.x
What type of installation are you running?
Home Assistant Supervised
Integration causing the issue
bluetooth_tracker, device_tracker
Link to integration documentation on our website
https://www.home-assistant.io/integrations/bluetooth_tracker/
Diagnostics information
Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 197, in update_bluetooth await perform_bluetooth_update() File "/usr/src/homeassistant/homeassistant/components/bluetooth_tracker/device_tracker.py", line 175, in perform_bluetooth_update rssi = await hass.async_add_executor_job(client.request_rssi) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.10/site-packages/bt_proximity/bt_rssi.py", line 55, in request_rssi self.prep_cmd_pkt() File "/usr/local/lib/python3.10/site-packages/bt_proximity/bt_rssi.py", line 24, in prep_cmd_pkt b'6sB17s', bt.str2ba(self.addr), bt.ACL_LINK, b'\0' * 17) SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Example YAML snippet
device_tracker:
- platform: bluetooth_tracker
request_rssi: true
Anything in the logs that might be useful for us?
No response
Additional information
No response
bluetooth_tracker documentation bluetooth_tracker source (message by IssueLinks)
That is expected and was announced:

See: https://www.home-assistant.io/blog/2022/07/06/release-20227/#breaking-changes
i also got the same issue :-(....
i got the same issue :-(
Why isn't this solved?
@stefanuytterhoeven see above? 🤷 Things don't solve itself 😉
???
I am not understand you response, it only contains question marks. Could you clarify those?
I have seen there is a pybluez2 library which was last updated August 2021 and requires python >=3.6. Could this be used instead of pybluez? Would it solve any, some or all of the issues? I am now currently stuck on HA 2022.7.1 as a lot of my automations reply on the bluetooth device tracker. As I cannot upgrade past 2022.7.1, I cannot upgrade to the latest TRACCAR add-on, which I also use extensively. I have to say I am getting a bit frustrated with all the breaking changes. I would like to help to fix this if I can. I have some programming experience (mainly assembler and C), but not with Python or HA, so would probably need some hand-holding. Cheers
I have seen there is a pybluez2 library which was last updated August 2021 and requires python >=3.6. Could this be used instead of pybluez? Would it solve any, some or all of the issues?
The solution is documented in the breaking change, which is listed above as well. Move towards bleak.
I have seen there is a pybluez2 library which was last updated August 2021 and requires python >=3.6. Could this be used instead of pybluez? Would it solve any, some or all of the issues?
The solution is documented in the breaking change, which is listed above as well. Move towards bleak.
As far as I know bleak only supports BLE. It does not detect classic Bluetooth devices like smartphones, which I assume is what most of us are trying to track with this integration. It's not really a suitable replacement.
The new Bluetooth integration in HA 2022.8.x seems to have re-introduced the bluetooth tracker functionality and it detects my smartphones perfectly.
That's true? I can update my ha without problems with classic bluetooth tracker?
It is true! HOWEVER - I find it less reliable than the old bluetooth tracker - I find that it toggles between home and not home for my bluetooth trackers more often than is acceptable (using the RPI4 built in bluetooth). I then tried using one of the recommended USB bluetooth dongles and had a lot of problems with it. So yes, basic function works, but look out for some quirks. I am hoping the bluetooth integration will go from strength to strength as I rely HEAVILY on reliable bluetooth tracking for my automations.
not so sure about that. I have it installed, and it finds exactly nothing at all...
100% certain my miniPC BT is functional, because when adding the blue tracker to yaml it finds many many devices (even the cards driving by)
however that doesnt find most of the phones in the household.
sofar, the new BT integration is no replacement at all for the former https://rc.home-assistant.io/integrations/bluetooth_tracker/
device_tracker:
- platform: bluetooth_tracker
Even with the updated bluetooth libraries in 2022.9.1 there isn't any improvement. Downloading the diagnostics from the bluetooth integration, I can see it picking up a myriad of BLE devices, but the mobile phones are not detected, or are only detected for a few seconds every couple of minutes. I did notice that running 'hcitool lescan' shows lots of devices, however 'hcitool scan' returns nothing, which is probably why Home Assistant doesn't see anything either. I am struggling to understand why this would be the case.
I did notice that running 'hcitool lescan' shows lots of devices, however 'hcitool scan' returns nothing, which is probably why Home Assistant doesn't see anything either. I am struggling to understand why this would be the case.
This is because Classic Bluetooth isn't supported anymore by HA as the title of this issue points out.
Further, as @Mariusthvdb and @kevdliu state, the new bluetooth in HA from 2022.7.x is based on Bleak which will probably never support classic bluetooth and therefore is no solution. I suggest that what you are seeing are the BLE MACs of your phones that are randomised every few minutes therefore you see them for a few seconds then they change.
I ended up creating a custom component based off of the BLE Tracker and modified it to recognize BLE beacons by their service UUID instead of mac. On my Android phone I installed nRF Connect and have it advertise as a beacon with a preset service UUID that the custom component recognizes. Seems to be working well so far.
Duke-box, If HA won't ever support the proper tracking of mobile phones, then in one step HA has been rendered useless for 90% of the function of my automations. Hopefully someone will come along with a Bluetooth tracking integration for phones at some point. I don't understand why support for smartphone tracking via bluetooth would be dropped, I would imagine 99%+ of all HA users have bluetooth enabled smartphones and it makes perfect sense (to me anyway) to use it for presence tracking. The alternatives (wifi and gps) have issues which the old bluetooth tracker doesn't have. Wifi uses a lot of battery power and GPS has privacy issues. Hey ho, perhaps I need to learn how to write an integration myself (I was a programmer many many moons ago)
Duke-box, If HA won't ever support the proper tracking of mobile phones, then in one step HA has been rendered useless for 90% of the function of my automations. Hopefully someone will come along with a Bluetooth tracking integration for phones at some point. I don't understand why support for smartphone tracking via bluetooth would be dropped, I would imagine 99%+ of all HA users have bluetooth enabled smartphones and it makes perfect sense (to me anyway) to use it for presence tracking. The alternatives (wifi and gps) have issues which the old bluetooth tracker doesn't have. Wifi uses a lot of battery power and GPS has privacy issues. Hey ho, perhaps I need to learn how to write an integration myself (I was a programmer many many moons ago)
Have you considered using the BLE transmitter that's part of the Home Assistant mobile app? I think this has the same functionality as you're using now. You'll only have to change the entity-id in your automations. https://www.home-assistant.io/integrations/bluetooth_le_tracker/
Roybosch, Thanks for the suggestion, but I don't really think it is practical in my situation. With the bluetooth tracker, I tracked the presence (or not) of 5 mobile phones (and this number will only increase). It isn't really practical to ask all of the phone owners to install, setup and maintain the HA mobile app. With the old tracker, I only needed to know their bluetooth mac and they had to do nothing other than leave their bluetooth on. The tracking was then used to control my heating, among other things. With the cost of energy spiralling, I want to maintain the tight control over when my property is being heated, which I no longer have through HA.
I understand. I'm having the same issue right now: https://github.com/home-assistant/core/issues/76979
Although the BLE tracker might be suitable for me, as I'm tracking only the devices of my family who also use the mobile app. It still is strange that such an important integration doesn't have a good alternative within HA itself.
It still is strange that such an important integration doesn't have a good alternative within HA itself.
Exactly my point, however this : https://github.com/robmarkoski/bt-mqtt-tracker might offer a glimmer of hope (at least for those of us who can install stuff on their HA installation).
It still is strange that such an important integration doesn't have a good alternative within HA itself.
Exactly my point, however this : https://github.com/robmarkoski/bt-mqtt-tracker might offer a glimmer of hope (at least for those of us who can install stuff on their HA installation).
Room Assistant does the same thing
https://www.room-assistant.io/guide/#how-it-works
And it uses the built in MQTT server of HA so it works pretty much out of the box. However it is quite slow at responding but it uses classic bluetooth as well as BLE.
I use it already to detect phone arriving in the kitchen and was considering building another instance with a greater range threshold just to replicate the bluetooth_tracker functionality.
Edit: And there is a Add On for HA so should be not too much pain to try it.
Or, if you have a spare Pi, just install Ha in the last version that supported the native bluetooth tracker and use mqtt to publish those. It was my system before I switched to a single box. Have a main production system, a secondary with Mqtt add-on and bluetooth, and a ternary for Zwave add-on. Spread your risks ;-)
about these ble trackers in the app: I tried all of that, but not a single phone was detected, only hundreds of passing carkists... o, and 2 Hue Bt lights.
about these ble trakers in the app: I tried all of that, but not a single phone was detected, only hundreds of passing carkists... o, and 2 Hue Bt lights.
You're right. I see that I already activated the BLE tracker in my config in the past. Not a single BLE_ prefix is present in the known_devices.yaml file.
I installed a few room-assistant nodes a few months ago but they don't work great yet. I find calibrating the things to show the correct room very difficult. At this moment, when I'm in the living room, it shows "office" often. That's a room upstairs...
Or, if you have a spare Pi, just install Ha in the last version that supported the native bluetooth tracker and use mqtt to publish those. It was my system before I switched to a single box. Have a main production system, a secondary with Mqtt add-on and bluetooth, and a ternary for Zwave add-on. Spread your risks ;-)
Just prior to support for the mac based detection of bluetooth devices being deprecated, that is exactly the setup I had (4 x pi's running HA) JUST to detect the presence of my smartphones. Given the soaring cost of energy, I decided to go back to just 1 pi running HA, as generally it got the presence detection right on its own. Ho hum, so much for trying to make a contribution to saving the planet. Maybe I will have to go back to running another pi, just for presence tracking.
Wow, so you guys are saying that the NEW ble_tracker doesn't work with 2022.9.x either! I thought this was released back in 2022.8.0.
I can see from the linked issue in @Mariusthvdb comment above that it is being worked on though. Yet another reason not to upgrade. Also glad I didn't buy the quite expensive BLE tracker tags with fixed MACs that should have worked with this integration!
That's about half right. In the past, I've been using ESP32's with ESPhome to track my Xiaomi BLE climate sensors. Now I'm using the Bluetooth integration combined with the Xiaomi BLE integration, which works great.
The BLE_tracker integration which you still have to configure via yaml doesn't seem to work. So tracking phones is still an issue.
BLE works great in the new integration, what doesn't work is the detection of Bluettoth Classic (ie NOT BLE) via their mac addresses.