core: 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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 55 (10 by maintainers)

Most upvoted comments

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)

@stefanuytterhoeven see above? 🤷 Things don’t solve itself 😉

The issue I have with using the app is I use presence tracking for many family members by their mac and I do not want to ask everyone to install, maintain and run the HA app. The bluetooth tracker was the cornerstone of my automations, so after many hours invested in HA, I am looking for an alternative which does support bluetooth mac tracking. Such a shame!

Kindest regards Peter Talbot


From: Roy @.> Sent: Tuesday, February 14, 2023 2:48:27 PM To: home-assistant/core @.> Cc: bigbigblue @.>; Comment @.> Subject: Re: [home-assistant/core] bluetooth_tracker doesn’t work in 2022.7.x (not compatible with python 3.10) (Issue #75049)

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/

@royboschhttps://github.com/roybosch can you expand on what you mean by this? Is the iOS app supposed to turn an iPhone into a trackable BLE device? From what I can tell, the bluetooth_le_tracker finds iOS devices whether or not they have the Companion app installed, but the MAC is randomized for privacy so it’s not useful.

That’s right. In my android app, under settings > companion app > manage sensors > BLE transmitter you can transmit a BLE signal that won’t change. I’d be surprised if the iOS app doesn’t have this feature.

— Reply to this email directly, view it on GitHubhttps://github.com/home-assistant/core/issues/75049#issuecomment-1429865151, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEXQZPMOI7UVYWMF7ISEBU3WXOLLXANCNFSM53KLJVHA. You are receiving this because you commented.Message ID: @.***>

Adding a comment to keep this thread alive. I will try the dbus api proof of concept above when I get a chance.

It is also possible to use D-Bus API directly. Here’s a proof of concept with a few caveats:

  • Discovery is not implemented, so trackable devices should already be present in known_devices.yaml
  • Bluez experimental features should be enabled (--experimental flag)
  • Bluetooth integration should be configured

custom_bluetooth_tracker.zip

Thanks for the clarification on the ble integration. I’ve learnt something today - when you enable the BLE sensor in the HA companion app for android it doesn’t allow you to specify a MAC but allows you to specify a UUID. But that is no good for the ble_tracker as it track MACs. Therefore the phone does not show up in known devices using HA app.

In my known devices yaml I can see my phone appear and then re-appear with a different MAC 'cos it is randomising it. This is done deliberately so you can’t track a phone. What would be good (and I know this is off topic) is for the ble_tracker to capture both MAC and UUID, then we would have a fighting chance.

@kevdliu - Since you have made a Custom Component that tracks the UUID already, which would solve my immediate problem, could you share this? It would save me re-inventing the wheel, so to speak. 😃

Thanks

I uploaded my custom component to a github repo: https://github.com/kevdliu/bt_tracker. I added some examples and notes to the readme as well. Let me know if you run into any problems using it.

ble does work. as a matter of fact it finds huge amounts of devices… just not my phones 😉

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.