Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth tracker does not work with newer python - Can't run HA Core on python 3.11.2 because of dependency to pybluez==0.22 #89119

Open
ferinelo opened this issue Mar 3, 2023 · 75 comments

Comments

@ferinelo
Copy link

ferinelo commented Mar 3, 2023

The problem

I created new venv with python 3.11.2, installed HA Core 2023.3.1 there and run hass --script check_config
I have a bluetooth tracker enabled in my configuration.

HA tries to install pybluez==0.22 and fails with error:

gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc -DTHREAD_STACK_SIZE=0x100000 -fPIC -I./port3 -I/srv/homeassistant_3.11.2/include -I/usr/local/include/python3.11 -c bluez/btmodule.c -o build/temp.linux-armv7l-cpython-311/bluez/btmodule.o
      bluez/btmodule.c: In function ‘PyInit__bluetooth’:
      bluez/btmodule.c:2837:22: error: lvalue required as left operand of assignment
       2837 |  Py_TYPE(&sock_type) = &PyType_Type;
            |                      ^
      bluez/btmodule.c:2838:29: error: lvalue required as left operand of assignment
       2838 |  Py_TYPE(&sdp_session_type) = &PyType_Type;
            |                             ^
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

With python 3.10.9 I had no issue at all (currently running venv).
I managed to install pybluez from source/github, however this did not solve the issue. Seems like device_tracker integration requires pybluez==0.22 and forces HA to install this version, which is not compatible with python 3.11.
I failed to migrate to venv python 3.11 because of this issue.

What version of Home Assistant Core has the issue?

2023.3.1

What was the last working version of Home Assistant Core?

2023.3.1

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Bluetooth Tracker

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bluetooth_tracker/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -ljemalloc -DTHREAD_STACK_SIZE=0x100000 -fPIC -I./port3 -I/srv/homeassistant_3.11.2/include -I/usr/local/include/python3.11 -c bluez/btmodule.c -o build/temp.linux-armv7l-cpython-311/bluez/btmodule.o
      bluez/btmodule.c: In function ‘PyInit__bluetooth’:
      bluez/btmodule.c:2837:22: error: lvalue required as left operand of assignment
       2837 |  Py_TYPE(&sock_type) = &PyType_Type;
            |                      ^
      bluez/btmodule.c:2838:29: error: lvalue required as left operand of assignment
       2838 |  Py_TYPE(&sdp_session_type) = &PyType_Type;
            |                             ^
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Mar 3, 2023

@alvariyo
Copy link

Hi, I am facing the same issue (pip 23.0.1 from /srv/homeassistant/venv_3.11.2/lib/python3.11/site-packages/pip (python 3.11))
I have tried to install directly in the venv but same error:
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting pybluez
Using cached PyBluez-0.23.tar.gz (97 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error

× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
error in PyBluez setup command: use_2to3 is invalid.
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Also is blocking the upgrade :(

@bdraco
Copy link
Member

bdraco commented Mar 26, 2023

Support for 3.11 added in https://github.com/pybluez/pybluez/commits/master but pybluez hasn't done a release that supports 3.11 yet so this isn't fixable until a new released is available.

@bdraco
Copy link
Member

bdraco commented Jun 9, 2023

#94189 (comment)

Nobody has picked up the project at this point ( last release in Dec 2019 https://github.com/pybluez/pybluez/releases/tag/0.23 ) https://github.com/pybluez/pybluez#contributors-wanted

@EthanBezz
Copy link

EthanBezz commented Jun 9, 2023

I’ve created a temporary fix for this issue! It can be found here

NOTE: It’s only intended for docker users, as that’s what I use, but maybe it could be adapted to help others.

@d03n3rfr1tz3
Copy link
Contributor

d03n3rfr1tz3 commented Jun 15, 2023

I’ve created a temporary fix for this issue! It can be found here

NOTE: It’s only intended for docker users, as that’s what I use, but maybe it could be adapted to help others.

well, after fiddling around for a few hours (my first failed attempt was to fake pybluez 0.30 to be 0.22 in the docker container) and just opening a PR in hope it might help someone, I just realized you already had basically the same solution laid out a week ago. 🤦
I'm cringing right now.

@thehoff
Copy link

thehoff commented Jul 15, 2023

https://github.com/andrewjfreyer/monitor is another way to get this done which I am playing with atm

@bdraco bdraco changed the title Can't run HA Core on python 3.11.2 because of dependency to pybluez==0.22 Bluetooth tracker does not work with newer python - Can't run HA Core on python 3.11.2 because of dependency to pybluez==0.22 Jul 22, 2023
@bentolor
Copy link

Support for [Python] 3.11 added in https://github.com/pybluez/pybluez/commits/master but pybluez hasn't done a release that supports 3.11 yet so this isn't fixable until a new released is available.

The current pybluez release 0.23 is dated Dec 28, 2019.
This gives me doubts that waiting for a new upstream release will be fruitful.

@PimDoos
Copy link
Contributor

PimDoos commented Aug 1, 2023

Since Home Assistant has a dedicated bluetooth integration, which is used by other integrations requiring Bluetooth, wouldn't it make sense to use that instead of pybluez?

@andriilahuta
Copy link

It's also possible to use bluetooth integration with D-Bus API instead. Here's a proof of concept if anyone wants to try.
custom_bluetooth_tracker.zip

Caveats:

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

@Duke-Box
Copy link

Duke-Box commented Aug 3, 2023

@andriilahuta

how do I try this? Do I just put the folder structure under "custom_components" and restart HA?

I'm running HAOS native on generic PC so I cannot change Bluez run time.
However all my device trackers are already discovered in known_devices.

@Duke-Box
Copy link

Duke-Box commented Aug 3, 2023

@bentolor

Yes I agree.
However it stopped working when HA went to python 3.10.x last year but started working again up until HA 2023.6.0. So someone/something made pybluez work with python 3.10.x without any fanfare or release notes!

@andriilahuta
Copy link

@Duke-Box Yes, just treat it as any other custom component.

Unfortunately, I don't think it would work without 'experimental' flag until this api moves out of experimental stage.
I've tried implementing this without experimental features, but it wasn't very reliable for me.

@Duke-Box
Copy link

Duke-Box commented Aug 3, 2023

Thanks for the quick reply.

I will try it on my test system which is a pi4 running HAOS also.
I think both generic X64 and Pi4 both run Bluez and looking at the documentation for bluetooth integration they mention experimental mode. [https://www.home-assistant.io/integrations/bluetooth/#additional-requirements-by-install-method]

I'll update when i get the time to try it out.

@bdraco
Copy link
Member

bdraco commented Aug 3, 2023

HAOS has the experimental flag turned on by default so it should work for most people.

Ideally the dbus implementation would get moved into a lib and a PR could be opened to replace the pybluez implementation with a dbus based one which should make things work for the foreseeable future.

@Joeviocoe
Copy link

It's also possible to use bluetooth integration with D-Bus API instead. Here's a proof of concept if anyone wants to try. custom_bluetooth_tracker.zip

Caveats:

* Discovery is not implemented, so trackable devices should already be present in known_devices.yaml

* Bluez experimental features should be enabled (--experimental flag)

I tried this custom component. It doesn't seem to do anything. I tried with and without this in my configuration.yaml:

device_tracker:
  - platform: custom_bluetooth_tracker

Running sudo systemctl status bluetooth:

● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2023-08-08 16:35:59 MDT; 41min ago
     Docs: man:bluetoothd(8)
 Main PID: 16957 (bluetoothd)
   Status: "Running"
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/bluetooth.service
           └─16957 /usr/lib/bluetooth/bluetoothd --experimental

I didn't know if I should expect an Integration tile to show up.
I have Airthings BLE working just fine. I can run bluetoothctl on the host, and it shows a scan of all found devices, so it appears like nothing is exclusively locking the BT adapter.

Should I be expecting already known devices to update my existing device_tracker entities?
Right now, they don't update and all show an attribute of "source_type: null"

No error messages (other than warning about a custom component being loaded).
Home Assistant 2023.8.1
Supervisor 2023.08.1
Docker version 20.10.7, build f0df350

@andriilahuta
Copy link

It should behave exactly like the original bluetooth tracker (except for discovery), so it has no UI.
For it to work, the bluetooth integration itself should be configured via UI.

Config looks okay, component-specific debug logs would be helpful.
FWIW it works fine on my setup (2023.08 / RPi / Microk8s).

@Rubquila
Copy link

Rubquila commented Aug 9, 2023

I upgrade to version 2023.8.1 on RaspberryPi

Home Assistant 2023.8.1
Supervisor 2023.08.1
Operating System 10.4
Frontend 20230802.0 - latest

I have gotten the following error:

Logger: homeassistant.util.package
Source: util/package.py:107
First occurred: 12:59:07 (6 occurrences)
Last logged: 13:24:22
Unable to install package PyBluez==0.22: error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [19 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.linux-armv7l-cpython-311 creating build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/__init__.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/widcomm.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/osx.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/msbt.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/btcommon.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/bluez.py -> build/lib.linux-armv7l-cpython-311/bluetooth copying bluetooth/ble.py -> build/lib.linux-armv7l-cpython-311/bluetooth running build_ext building 'bluetooth._bluetooth' extension creating build/temp.linux-armv7l-cpython-311 creating build/temp.linux-armv7l-cpython-311/bluez gcc -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fno-semantic-interposition -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free -DTHREAD_STACK_SIZE=0x100000 -fPIC -I./port3 -I/usr/local/include/python3.11 -c bluez/btmodule.c -o build/temp.linux-armv7l-cpython-311/bluez/btmodule.o error: command 'gcc' failed: No such file or directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for PyBluez ERROR: Could not build wheels for PyBluez, which is required to install pyproject.toml-based projects [notice] A new release of pip is available: 23.1.2 -> 23.2.1 [notice] To update, run: pip install --upgrade pip

With this I have updated the version of pip through commands in the terminal and now I have this error:

Platform error device_tracker.bluetooth_tracker - Requirements for bluetooth_tracker not found: ['PyBluez==0.22'].

So I try to install pyBluez via console with "pip install pybluez", but i get the following error:

Error in PyBluez setup command: use_2to3 is invalid

So it still doesn't work.

@Joeviocoe
Copy link

Trying to get debug logs:

      homeassistant.components.device_tracker: debug
      homeassistant.components.bluetooth_tracker: debug
      homeassistant.components.custom_bluetooth_tracker: debug
      homeassistant.setup: debug
      homeassistant.components.bluetooth: debug
      bleak.backends.bluezdbus: debug

homeassistant.components.device_tracker shows other trackers like network devices and a single mention of setting up the custom_bluetooth_tracker
homeassistant.components.bluetooth_tracker shows nothing
homeassistant.components.custom_bluetooth_tracker shows nothing

2023-08-09 09:58:52.465 INFO (MainThread) [homeassistant.setup] Setting up device_tracker
2023-08-09 09:58:52.603 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.custom_bluetooth_tracker
2023-08-09 09:58:52.651 INFO (MainThread) [homeassistant.setup] Setup of domain device_tracker took 0.2 seconds

homeassistant.components.bluetooth:

Debug logs for Bluetooth Component

2023-08-09 08.101 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration custom_bluetooth_tracker which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2023-08-09 0
0.016 DEBUG (MainThread) [homeassistant.setup] Dependency bluetooth will wait for dependencies ['usb']
2023-08-09 00.161 INFO (MainThread) [homeassistant.setup] Setting up bluetooth
2023-08-09 0
0.238 INFO (MainThread) [homeassistant.setup] Setup of domain bluetooth took 0.1 seconds
2023-08-09 00.247 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] Initializing bluetooth scanner with {'detection_callback': <bound method HaScanner._async_detection_callback of <homeassistant.components.bluetooth.scanner.HaScanner object at 0x7fd8683a3920>>, 'scanning_mode': 'active', 'adapter': 'hci0'}
2023-08-09 0
0.248 DEBUG (MainThread) [homeassistant.components.bluetooth.scanner] hci0 (5D): Starting bluetooth discovery attempt: (1/3)
2023-08-09 00.570 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] Registering scanner hci0 (5
D)
2023-08-09 0
1.400 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5D) [connectable]: 08 AdvertisementData(manufacturer_data={* b'\x01\t \x02\xe0\xda\xd4T\x87\xb2\x14T\xff/\x86\tg\xf4\xb4\xf7p;\xd48M\xd4\xbf'}, rssi=-84) match: set()
2023-08-09 01.978 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5D) [connectable]: 6A AdvertisementData(local_name='Airthings Wave+', manufacturer_data={82* b'(G\xa6\xaeI\x00'}, service_uuids=['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'b42e1c08-ade7-11e4-89d3-123b93f75cba', 'f000ffc0-0451-4000-b000-000000000000'], rssi=-75) match: set()
2023-08-09 0
8.452 DEBUG (MainThread) [homeassistant.setup] Dependency airthings_ble will wait for dependencies ['bluetooth_adapters']
2023-08-09 08.612 DEBUG (MainThread) [homeassistant.setup] Dependency bluetooth_adapters will wait for after dependencies ['esphome']
2023-08-09 0
2.603 INFO (MainThread) [homeassistant.components.device_tracker] Setting up device_tracker.custom_bluetooth_tracker
2023-08-09 07.636 INFO (MainThread) [homeassistant.setup] Setting up bluetooth_adapters
2023-08-09 0
7.636 INFO (MainThread) [homeassistant.setup] Setup of domain bluetooth_adapters took 0.0 seconds
2023-08-09 08.362 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6A - Airthings Wave+ -> /org/bluez/hci* Connecting (last rssi: -75)
2023-08-09 0
1.152 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6
A - Airthings Wave+ -> /org/bluez/hci* Connected (last rssi: -75)
2023-08-09 00.571 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.0239976670127362
2023-08-09 0
0.572 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.27197356801480055
2023-08-09 10.573 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.11198911600513384
2023-08-09 1
0.574 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.09599067096132785
2023-08-09 10.574 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.11598872800823301
2023-08-09 1
0.575 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.003999611013568938
2023-08-09 10.575 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.03199689101893455
2023-08-09 1
0.576 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.12398795003537089
2023-08-09 14.534 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 29 AdvertisementData(manufacturer_data={* b'\x01\t "\xbe\x89+@\xcd=v\x99\xdb\x07\x0b\xd3\x0b\xf2\xd7\x16j\xe2qf\xc9)c'}, rssi=-94) match: set()
2023-08-09 1
0.576 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5D): Scanner watchdog time_since_last_detection: 0.07999222504440695
2023-08-09 13.124 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 6A AdvertisementData(local_name='Airthings Wave+', manufacturer_data={82* b'(G\xa6\xaeK\x00'}, service_uuids=['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'b42e1c08-ade7-11e4-89d3-123b93f75cba', 'f000ffc0-0451-4000-b000-000000000000'], rssi=-76) match: set()
2023-08-09 1
0.577 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.003999612003099173
2023-08-09 11.776 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 6A AdvertisementData(local_name='Airthings Wave+', manufacturer_data={82* b'(G\xa6\xaeI\x00'}, service_uuids=['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'b42e1c08-ade7-11e4-89d3-123b93f75cba', 'f000ffc0-0451-4000-b000-000000000000'], rssi=-76) match: set()
2023-08-09 1
4.393 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6A - Airthings Wave+ -> /org/bluez/hci* Connecting (last rssi: -75)
2023-08-09 15.605 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6
A - Airthings Wave+ -> /org/bluez/hci* Connected (last rssi: -75)
2023-08-09 1
0.577 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5D): Scanner watchdog time_since_last_detection: 0.09999028302263469
2023-08-09 14.304 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 69 AdvertisementData(manufacturer_data={7* b'\x02\x15\x1c\xa9.#\xf0\x87M\xf7\xb9\xa2\xfdKqjK\xf6\x00\xe5\x00\x00\x03'}, rssi=-91) match: {'ibeacon'}
2023-08-09 1
6.724 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: D2 AdvertisementData(service_data={'0000feed-0000-1000-8000-00805f9b34fb': b'\x02\x00\n\xac\x9a\x12\xf8*<'}, service_uuids=['0000feed-0000-1000-8000-00805f9b34fb'], rssi=-76) match: set()
2023-08-09 10.577 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5D): Scanner watchdog time_since_last_detection: 0.1519852289929986
2023-08-09 1
0.579 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.03999611298786476
2023-08-09 10.580 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.03999611298786476
2023-08-09 1
5.042 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 38 AdvertisementData(manufacturer_data={* b'\x01\t \x02+\t\x83.\xaf\x95\x1b:TB\x7f\x0b\xc6#\xf9\xe1\xb0@F\xb7\x8a\xd76'}, rssi=-83) match: set()
2023-08-09 1
4.945 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5D) [connectable]: 46 AdvertisementData(manufacturer_data={7* b'\x10\x068\x1a$\x830\xff'}, tx_power=7, rssi=-90) match: set()
2023-08-09 1
0.580 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5D): Scanner watchdog time_since_last_detection: 0.0
2023-08-09 10.581 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.03599650098476559
2023-08-09 1
0.582 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.08399183698929846
2023-08-09 10.582 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.07599261403083801
2023-08-09 1
0.583 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.09199106000596657
2023-08-09 12.159 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 6A AdvertisementData(local_name='Airthings Wave+', manufacturer_data={82* b'(G\xa6\xaeK\x00'}, service_uuids=['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'b42e1c08-ade7-11e4-89d3-123b93f75cba', 'f000ffc0-0451-4000-b000-000000000000'], rssi=-76) match: set()
2023-08-09 1
0.583 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5D): Scanner watchdog time_since_last_detection: 0.043995724990963936
2023-08-09 13.363 DEBUG (MainThread) [homeassistant.components.bluetooth.manager] hci0 (5
D) [connectable]: 6A AdvertisementData(local_name='Airthings Wave+', manufacturer_data={82* b'(G\xa6\xaeI\x00'}, service_uuids=['00001800-0000-1000-8000-00805f9b34fb', '00001801-0000-1000-8000-00805f9b34fb', '0000180a-0000-1000-8000-00805f9b34fb', 'b42e1c08-ade7-11e4-89d3-123b93f75cba', 'f000ffc0-0451-4000-b000-000000000000'], rssi=-86) match: set()
2023-08-09 1
9.393 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6
A - Airthings Wave+ -> /org/bluez/hci* Connecting (last rssi: -75)
2023-08-09 10.584 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.9719055430032313
2023-08-09 1
0.684 DEBUG (MainThread) [homeassistant.components.bluetooth.wrappers] 6
A - Airthings Wave+ -> /org/bluez/hci* Connected (last rssi: -75)
2023-08-09 10.584 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.21997862099669874
2023-08-09 1
0.585 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.1719832859816961
2023-08-09 10.586 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.13598678295966238
2023-08-09 1
0.587 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.0
2023-08-09 10.587 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
D): Scanner watchdog time_since_last_detection: 0.1079895049915649
2023-08-09 1
0.587 DEBUG (MainThread) [homeassistant.components.bluetooth.base_scanner] hci0 (5
****D): Scanner watchdog time_since_last_detection: 0.0239976670127362

bleak.backends.bluezdbus: bluez.log

@andriilahuta
Copy link

@Joeviocoe could you try this version:
custom_bluetooth_tracker.zip

It contains some additional debug statements and should produce at least some debug output.
Ideally, the original bluetooth tracker should be disabled in the meantime.

@Duke-Box
Copy link

Duke-Box commented Sep 2, 2023

It isn't pyBluez, or "Bluez". That's the point of the thread.

This component uses the D-Bus API in experimental mode. You must be confused.

And because you have a native install of HA on Pi3, i.e running HAOS, then all this is done for you. As per my question in the thread and the response from Nick (bdraco), 5 posts down from my previous link.
So you didn't need to hack any files via SSH.
After you had put the custom files into your custom_components dir you just needed to edit your yaml files
You had the correct stuff in you configuration.yaml and once you corrected your known_device.yaml, it worked.

EDIT: but I agree the bluetooth tracker documentatiion isn't great and when I have suggested updates to it I have runn into a brick wall with some of the devs.

@devildant
Copy link

devildant commented Sep 2, 2023

It isn't pyBluez, or "Bluez". That's the point of the thread.

This component uses the D-Bus API in experimental mode. You must be confused.

yes, I discovered home assistant, home assistant, a lot of information at the same time, my bad haha

And because you have a native install of HA on Pi3, i.e running HAOS, then all this is done for you. As per my question in the thread and the response from Nick (bdraco), 5 posts down from my previous link. So you didn't need to hack any files via SSH. After you had put the custom files into your custom_components dir you just needed to edit your yaml files You had the correct stuff in you configuration.yaml and once you corrected your known_device.yaml, it worked.

I'm not used to everything working like that haha ​​so it lost me haha.

anyway thanks for the info and help :)

@Rubquila
Copy link

I have tried this CustomComponent and it works for me too.
Although it must be emphasized that it works with the system update with Python 3. That is, in HAOS 2023.5.4 it did not work for me due to the Python version.

@mistermog
Copy link

Im confused here... I am still back on 2023.5.4 with unsupervised install and not sure if this is the method to get it to work for phone tracking? It isn't LE and again unsupervised. Are people in this case still waiting?

@LordNex
Copy link

LordNex commented Nov 5, 2023


url="http://localhost:8123/api/services/homeassistant/restart"
pip list|grep PyBluez
RC=$?
if [ "$RC" -ne "0" ]
then
 apk add gcc musl-dev bluez-dev
 pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez
 [ "$?" -ne "0" ] && (exit 1)
 curl -X POST -H "Authorization: Bearer $token" -H "content-type: application/json" $url
fi

url="http://localhost:8123/api/services/homeassistant/restart"
pip list|grep PyBluez
RC=$?
if [ "$RC" -ne "0" ]
then
 apk add gcc musl-dev bluez-dev
 pip install git+https://github.com/pybluez/pybluez.git#egg=pybluez
 [ "$?" -ne "0" ] && (exit 1)
 curl -X POST -H "Authorization: Bearer $token" -H "content-type: application/json" $url
fi

Returns

image

Not sure where how or why I'd need to install the wheels which I really no zip about.

@mistermog
Copy link

You should install 'python3-dev' with 'apt install xxxx'

is that all i would have to do then bluetooth tracking would work with newer versions of home assistant unsupervised?

@barneyman
Copy link

barneyman commented Feb 5, 2024

looks like xz-dev has moved the underlying component from pybluez to bleak - it's just waiting on on a workflow approval - i'm currently stuck at 2023.5.4 ....

@micium
Copy link

micium commented Feb 8, 2024

any news in 2024.2 version? in this release ships running on Python 3.12!

@freedomanonyme
Copy link

It's also possible to use bluetooth integration with D-Bus API instead. Here's a proof of concept if anyone wants to try. custom_bluetooth_tracker.zip

Caveats:

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

Thanks! it works!!!

@goliath888
Copy link

Anyone knows if using an ESP32 as Bluetooth proxy would let me use the bluetooth tracker component?

@HansDampfwurst
Copy link

It's also possible to use bluetooth integration with D-Bus API instead. Here's a proof of concept if anyone wants to try. custom_bluetooth_tracker.zip
Caveats:

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

Thanks! it works!!!

@freedomanonyme :
How have you done this? I have downloaded the zip file and exctract the content. Upload the folder "custom_bluetooth_tracker" with contend to /config/custom_components on my Raspberry Pi 4. Reboot the system. In known_devices.yaml there is still the BT entry for my phone. But the phone is not detected on entitys.

Where is the error? Or how to controll that this costum componet works?

@freedomanonyme
Copy link

Hi! I don't work with a rasberry Pi. I'm on a generic X86-64 with a USB bluetooth dongle bought on Temu. At first I added the bluetooth dongle in the integrations. After that, I added the folder in my custom components as you said. Did you setup the component in your configuration.yaml? :

panel_custom:
  - name: custom_bluetooth_tracker
    url_path: custom_bluetooth_tracker


device_tracker:
  - platform: custom_bluetooth_tracker
    interval_seconds: 10
#    seen_interval_seconds: 60
    consider_home: 60

I track 2 Iphones added manually in the know devices. However, it doesn't work with a Garmin Fenix 6 watch.

It's also possible to use bluetooth integration with D-Bus API instead. Here's a proof of concept if anyone wants to try. custom_bluetooth_tracker.zip
Caveats:

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

Thanks! it works!!!

@freedomanonyme : How have you done this? I have downloaded the zip file and exctract the content. Upload the folder "custom_bluetooth_tracker" with contend to /config/custom_components on my Raspberry Pi 4. Reboot the system. In known_devices.yaml there is still the BT entry for my phone. But the phone is not detected on entitys.

Where is the error? Or how to controll that this costum componet works?

@Duke-Box
Copy link

HI,

I too use a generic x86-64 amd/intel old laptop with a usb bluetooth dongle. I originally used a generic bluetooth dongle supporting v5.1 which proved unreliable so I replaced it with one that was compatible with bluetooth v4.0 ( which I believe is recommended for use with HA).

I don't use the custom panel integration so your first YAML snippet is irrelevant.
I do have your second YAML snippet in my config.yaml file.

Did your old system work with iPhones? can you see their device_tracker.x entities using Developer tools > states?
I use Android phones and they work.
I have never been able to track smartwatches probably because some use BLE which this isn't about, and others only advertise themselves if they are not paired to their App. So I doubt you would have success there.

@emanuele-bordon
Copy link

Hi all...
I'm on Home Assistant OS...
Without activating --experimental, I saw my iPhone "Home" for a few minutes, then I see this error in the logs "hci0 (00:15:83:FB:C1:9F): Error stopping scanner: [org.bluez.Error.Failed] No discovery started"...

Would someone be able to help me to activate the --experimental feature?

Thanks guys

@Duke-Box
Copy link

Duke-Box commented Mar 5, 2024 via email

@emanuele-bordon
Copy link

It's already activated on ha core. I think your problem is you want to track an iPhone.

On Tue, 5 Mar 2024, 23:00 emanuele-bordon, @.> wrote: Hi all... I'm on Home Assistant OS... Without activating --experimental, I saw my iPhone "Home" for a few minutes, then I see this error in the logs "hci0 (00:15:83:FB:C1:9F): Error stopping scanner: [org.bluez.Error.Failed] No discovery started"... Would someone be able to help me to activate the --experimental feature? Thanks guys — Reply to this email directly, view it on GitHub <#89119 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJIPW7BIYS46D65EGFLXGI3YWZE7PAVCNFSM6AAAAAAVO44ESGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZZG44DANRSHE . You are receiving this because you were mentioned.Message ID: @.>

but @freedomanonyme track iPhone....

@andriilahuta
Copy link

@emanuele-bordon might be an adapter issue: #78341.

@emanuele-bordon
Copy link

Oh... I had purchased a "TRENDnet TBW-107UB (CSR8510A10)" among the "KNOWN WORKING HIGH-PERFORMANCE ADAPTERS" for maximum compatibility... :)

@freedomanonyme can you tell me which dongle you use and if you did something special for iPhone?

@freedomanonyme
Copy link

Oh... I had purchased a "TRENDnet TBW-107UB (CSR8510A10)" among the "KNOWN WORKING HIGH-PERFORMANCE ADAPTERS" for maximum compatibility... :)

@freedomanonyme can you tell me which dongle you use and if you did something special for iPhone?

Hi! Sorry for the late response. It worked for 48 h… not reliable.

@Bergasha
Copy link

Mines the same now, a hardware reboot brings it back for a few days. No errors when it drops out so it might be a hard one.

@Blabla4137
Copy link

Hello, there is no news about this problem ? We can't use bluetooth anymore in the future ?
I follow this problem for a long time now and i'm surprised to don't find a solution now :(

@uzirox76
Copy link

Hello, there is no news about this problem ? We can't use bluetooth anymore in the future ? I follow this problem for a long time now and i'm surprised to don't find a solution now :(

I agree. So it must be removed from documentation if it isn't working.
I'm using the custom BT integration but it's not discovering any new device so it's partially useful.

@Blabla4137
Copy link

Hello, there is no news about this problem ? We can't use bluetooth anymore in the future ? I follow this problem for a long time now and i'm surprised to don't find a solution now :(

I agree. So it must be removed from documentation if it isn't working. I'm using the custom BT integration but it's not discovering any new device so it's partially useful.

How to use the custom BT integration ? There is a procedure ?
I think that could help me a lot...

@bartek75
Copy link

bartek75 commented Apr 14, 2024

Hello, there is no news about this problem ? We can't use bluetooth anymore in the future ? I follow this problem for a long time now and i'm surprised to don't find a solution now :(

I agree. So it must be removed from documentation if it isn't working. I'm using the custom BT integration but it's not discovering any new device so it's partially useful.

How to use the custom BT integration ? There is a procedure ? I think that could help me a lot...

It is described in this very thread: look for custom_bluetooth_tracker.zip.

@Blabla4137
Copy link

Blabla4137 commented Apr 15, 2024

Hello,
I don't understand how to use the custom tracker...

I add the folder "custom_bluetooth_tracker" in my "custom_components" folder

i have this in my configuration.yaml

device_tracker:
  - platform: bluetooth_le_tracker
    new_device_defaults:
    track_new_devices: false
  - platform: bluetooth_tracker
  - platform: custom_bluetooth_tracker

My devices are already in the "known_devices.yaml" file

I restarted HA but... It don't seem to work ?

I use a Respberry PI 4 so i think that experimental is on ?

@uzirox76
Copy link

uzirox76 commented May 2, 2024

With the latest update (2024.5.0) custom_bt integration is not working anymore. It seems that BT is hated... now I don't have a reliable presence detection anymore.

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/config/custom_components/custom_bluetooth_tracker/device_tracker.py", line 203, in update_bluetooth await perform_bluetooth_update() File "/config/custom_components/custom_bluetooth_tracker/device_tracker.py", line 165, in perform_bluetooth_update adapters = await bluetooth._get_manager(hass).async_get_bluetooth_adapters() ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: module 'homeassistant.components.bluetooth' has no attribute '_get_manager'. Did you mean: 'set_manager'?

@andriilahuta
Copy link

Here's an updated version:
https://github.com/andriilahuta/hass-dbus-bluetooth-tracker/tree/2024.5.0
Note that I renamed the component slightly.

@uzirox76
Copy link

uzirox76 commented May 2, 2024

Here's an updated version: https://github.com/andriilahuta/hass-dbus-bluetooth-tracker/tree/2024.5.0 Note that I renamed the component slightly.

You're a hero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests