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

[Bug]: Doesn't work with Docker macvlan - Bluetooth interface is not available #1301

Open
LeVraiRoiDHyrule opened this issue Jan 17, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@LeVraiRoiDHyrule
Copy link

What happened?

Hi,
I would like to use this with HA on Docker using macvlan networking mode instead of host mode. This mode allows to attribute a mac address for the container (HA) on the LAN. This allows for features that would normally require host mode, like DLNA, without the problems of host mode (impossibility to join a Docker virtual network).

I was using BLE Monitor before with host mode, and I would like to use it with macvlan.
I have set my HA this way:

  homeassistant:
    image: homeassistant/homeassistant:latest
    platform: "linux/arm64"
    container_name: homeassistant
    restart: unless-stopped
    privileged: true
    networks:
      - services
      - macvlan
    cap_add:
      - NET_ADMIN
      - NET_RAW
      - SYS_ADMIN
    environment:
      - PUID=0
      - PGID=0
      - TZ=${TZ}
    volumes:
      - ${CONFIG_FOLDER}/homeassistant:/config
      - /run/dbus:/run/dbus:ro
    ports:
      - 8123:8123

PUID=0 PGID=0 means I am running as root.
I checked that Bluetooth works on the main system.

The bluetooth adapter is seen by HA's bluetooth integration:
image

HA's Xiaomi BLE integration automatically found my BLE device (MiScale Body Composition 2) and was able to retrieve the weight:
image

But this is non-stabilized weight and I would like impedance in addition to this value.

But BLE monitor fails to find the adapter:
image

I know this is an uncommon setup but I would like to ask for some help and knowledge to dig a bit more into this.

What, in your opinion, could cause this issue with macvlan ? What can cause the adapter to be seen by HA and not by BLE Monitor ? Why can HA's Xiaomi BLE integration receive the weight but not BLE Monitor ?

In the log section, you will find the output if I don't use automatic configuration but rather the following YAML:

ble_monitor:
  bt_interface:
    - '00:1A:7D:DA:71:15'
  discovery: False
  devices:
    - mac: '0C:95:41:D7:4A:F8'

With this configuration, I have the following error:
2024-01-17 22:18:20.753 ERROR (MainThread) [custom_components.ble_monitor] Bluetooth interface with MAC address 00:1A:7D:DA:71:15 is not available

What could cause the interface to not be available with this config ?

Thanks in advance for any answer and have a great day.

Sensor type

MiScale Body Composition 2

Relevant log output

2024-01-17 22:17:05.405 DEBUG (MainThread) [custom_components.ble_monitor] async_unload_entry: <homeassistant.config_entries.ConfigEntry object at 0x7f75239e40>
2024-01-17 22:17:05.414 DEBUG (MainThread) [custom_components.ble_monitor] HCIdump thread: joining
2024-01-17 22:17:05.418 DEBUG (Thread-2) [custom_components.ble_monitor] HCIdump thread: main event_loop stopped, finishing.
2024-01-17 22:17:05.420 DEBUG (Thread-2) [custom_components.ble_monitor] HCIdump thread: Run finished
2024-01-17 22:17:05.421 DEBUG (MainThread) [custom_components.ble_monitor] HCIdump thread: joined
2024-01-17 22:17:05.421 DEBUG (MainThread) [custom_components.ble_monitor] BLE monitor stopped
2024-01-17 22:17:05.422 DEBUG (MainThread) [custom_components.ble_monitor] Initializing BLE Monitor entry (config entry): <homeassistant.config_entries.ConfigEntry object at 0x7f75239e40>
2024-01-17 22:17:05.422 DEBUG (MainThread) [custom_components.ble_monitor] async_setup_entry: domain {'bt_interface': ['00:1A:7D:DA:71:15'], 'discovery': False, 'devices': [{'mac': '0C:95:41:D7:4A:F8', 'report_unknown': False, 'restore_state': 'default', 'consider_home': 180, 'reset_timer': 35, 'track_device': False, 'use_median': 'default', 'tracker_scan_interval': 20}], 'report_unknown': 'Off', 'restore_state': False, 'batt_entities': True, 'period': 60, 'bt_auto_restart': False, 'hci_interface': [], 'active_scan': False, 'use_median': False, 'log_spikes': False, 'is_flow': False, 'ids_from_name': True}
2024-01-17 22:17:05.423 INFO (MainThread) [custom_components.ble_monitor] Available Bluetooth interfaces for BLE monitor: ["Don't use Bluetooth adapter"]
2024-01-17 22:17:05.423 ERROR (MainThread) [custom_components.ble_monitor] Bluetooth interface with MAC address 00:1A:7D:DA:71:15 is not available
2024-01-17 22:17:05.423 WARNING (MainThread) [custom_components.ble_monitor] No configured Bluetooth interface was found, using default interface instead
2024-01-17 22:17:05.424 DEBUG (MainThread) [custom_components.ble_monitor] HCI interface is ['disable']
2024-01-17 22:17:05.424 DEBUG (MainThread) [custom_components.ble_monitor] async_setup_entry: {'bt_interface': ['disable'], 'discovery': False, 'devices': [{'mac': '0C:95:41:D7:4A:F8', 'report_unknown': False, 'restore_state': 'default', 'consider_home': 180, 'reset_timer': 35, 'track_device': False, 'use_median': 'default', 'tracker_scan_interval': 20}], 'report_unknown': 'Off', 'restore_state': False, 'batt_entities': True, 'period': 60, 'bt_auto_restart': False, 'hci_interface': ['disable'], 'active_scan': False, 'use_median': False, 'log_spikes': False, 'is_flow': False, 'ids_from_name': True}
2024-01-17 22:17:05.427 DEBUG (MainThread) [custom_components.ble_monitor] Spawning HCIdump thread
2024-01-17 22:17:05.427 DEBUG (MainThread) [custom_components.ble_monitor] HCIdump thread: Init
2024-01-17 22:17:05.427 DEBUG (MainThread) [custom_components.ble_monitor] 0 encryptors mac:key pairs loaded
2024-01-17 22:17:05.430 DEBUG (MainThread) [custom_components.ble_monitor] sensor whitelist: [0C:95:41:D7:4A:F8]
2024-01-17 22:17:05.430 DEBUG (MainThread) [custom_components.ble_monitor] 1 sensor whitelist item(s) loaded
2024-01-17 22:17:05.430 DEBUG (MainThread) [custom_components.ble_monitor] 0 device tracker(s) being monitored
2024-01-17 22:17:05.431 DEBUG (Thread-4) [custom_components.ble_monitor] HCIdump thread: Run
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] Starting device tracker entry startup
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] BLE device tracker updater initialization
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] BLE device tracker updater initialized
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] Device Tracker entry setup finished
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] Starting binary sensor entry startup
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] BLE binary sensors updater initialization
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] BLE binary sensors updater initialized
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] Binary sensor entry setup finished
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.sensor] Starting measuring sensor entry startup
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.sensor] BLE sensors updater initialization
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.sensor] BLE sensors updater initialized
2024-01-17 22:17:05.440 DEBUG (MainThread) [custom_components.ble_monitor.sensor] Measuring sensor entry setup finished
2024-01-17 22:17:05.441 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] Device tracker updater loop started!
2024-01-17 22:17:05.441 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] Binary entities updater loop started!
2024-01-17 22:17:05.441 DEBUG (MainThread) [custom_components.ble_monitor.sensor] Entities updater loop started!
2024-01-17 22:17:05.442 DEBUG (MainThread) [custom_components.ble_monitor.binary_sensor] Entities updater loop stopped
2024-01-17 22:17:05.442 DEBUG (MainThread) [custom_components.ble_monitor.sensor] Entities updater loop stopped
2024-01-17 22:17:05.442 DEBUG (MainThread) [custom_components.ble_monitor.device_tracker] Entities updater loop stopped
2024-01-17 22:17:05.443 DEBUG (Thread-4) [custom_components.ble_monitor] HCIdump thread: start main event_loop
@LeVraiRoiDHyrule LeVraiRoiDHyrule added the bug Something isn't working label Jan 17, 2024
@LeVraiRoiDHyrule
Copy link
Author

I just tested using Docker network mode host, and it works. So there is something with using macvlan driver that doesn't work with BLE monitor. But I would be very interested to find out what it is, as macvlan should work very similar to network host mode, it allows to have bridge network in addition to having an IP / Mac address on the physical network.

@Ernst79
Copy link
Collaborator

Ernst79 commented Jan 19, 2024

I can’t help you with this, I never used docker. In the faq are some tips for issues with docker installations but I’m not sure if it applies to your issue.

BLE monitor is using Bluetooth at a lower level, bij making HCI dumps, compared to the official Bluetooth integration. IHA needs proper access to perform this operation.

@Young1223
Copy link

I’m dealing with the same problem as you.

@Sorien
Copy link

Sorien commented Feb 26, 2024

I have no problems and HA in docker can use two different adapters one is internal card intel ax210 second is dongle Edup EP-B3536GS, my docker-compose looks like this:

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
      - /run/dbus:/run/dbus:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

I can't remember what exactly I had to setup or why it's working, it was long ago, but I think privileged flag could be the answer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants