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

Switchbot not working in 2022.7 Docker Container #74621

Closed
jannis3005 opened this issue Jul 7, 2022 · 17 comments
Closed

Switchbot not working in 2022.7 Docker Container #74621

jannis3005 opened this issue Jul 7, 2022 · 17 comments

Comments

@jannis3005
Copy link

The problem

With the Update to 2022.7 the Switchbot Integration stopped working for me. First, it gave an error related to dbus_next saying it couldn't find a file or directory. I figured, with the recent python/bluetooth changes i'd have to do something like adding '- /var/run/dbus/:/var/run/dbus/' to the volumes section inside my docker-compose file.

That made the error go away - However, now it just loads for a short moment and then just says connection failed - and there is literally nothing in the log hinting at what the Problem could be.

Bluetooth itself is working fine on the device and it is definitely powered on. Since I could not find any error related to the switchbot integration, I have no idea where to search for one and how to solve this.

What version of Home Assistant Core has the issue?

2022.7

What was the last working version of Home Assistant Core?

2022.5

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Switchbot

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

@probot-home-assistant
Copy link

Hey there @Danielhiversen, @RenierM26, mind taking a look at this issue as it has been labeled with an integration (switchbot) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)


switchbot documentation
switchbot source
(message by IssueLinks)

@Chreece
Copy link

Chreece commented Jul 7, 2022

Try adding the :z label at the mounted volume:
- /var/run/dbus/:/var/run/dbus/:z

That worked for me

@jannis3005
Copy link
Author

@Chreece sadly that din't change anything

@emailforos
Copy link

Same problem here in a Home Assistant Container installation in a Rsapberry Pi.

Log information from HA-Container:

Logger: homeassistant.components.switchbot.coordinator
Source: components/switchbot/coordinator.py:43
Integration: SwitchBot (documentation, issues)
First occurred: 7 de julio de 2022, 22:18:17 (635 occurrences)
Last logged: 12:23:40

Unexpected error fetching switchbot data: [Errno 2] No such file or directory
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 43, in _async_update_data
    switchbot_data = await self.switchbot_data.discover(
  File "/usr/local/lib/python3.10/site-packages/switchbot/__init__.py", line 162, in discover
    await devices.start()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 88, in start
    self._bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 122, in __init__
    super().__init__(bus_address, bus_type, ProxyObject)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 85, in __init__
    self._setup_socket()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 575, in _setup_socket
    raise err
  File "/usr/local/lib/python3.10/site-packages/dbus_next/message_bus.py", line 548, in _setup_socket
    self._sock.connect(filename)
FileNotFoundError: [Errno 2] No such file or directory

I suppose that this integration is affected by the Python bluetooth changes but there is no reference in Breaking Changes of the blog about this integration being affected.

@jannis3005
Copy link
Author

You also need to map your dbus into your container like shown above and then it should in theory work

@maxgashkov
Copy link

@jannis3005 I had the 'connection failed' error before (unrelated to this issue) and adding the following options to container definition resolved it for me: --privileged -v /dev/bus/usb:/dev/bus/usb. By extending it with the dbus mount you suggested, I was able to make it work again.

@emailforos
Copy link

You also need to map your dbus into your container like shown above and then it should in theory work

This solved it also for me. Thank you.

I think this should be in the integration documentation.

Thank you very much.

@ljaquier
Copy link

First, I had the @emailforos's issue. Then, I added the -v /var/run/dbus:/var/run/dbus and I have now another issue. Below, the stack trace.

2022-07-11 20:37:08 ERROR (MainThread) [homeassistant.components.switchbot.coordinator] Unexpected error fetching switchbot data: [org.freedesktop.DBus.Error.UnknownMethod] Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 43, in _async_update_data
    switchbot_data = await self.switchbot_data.discover(
  File "/usr/local/lib/python3.10/site-packages/switchbot/__init__.py", line 162, in discover
    await devices.start()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 133, in start
    assert_reply(reply)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownMethod] Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

@emailforos
Copy link

@ljaquier, I don't have this error in my logs.

Only for checking: Did you add the :z at the end of the volume mapping?

@ljaquier
Copy link

I've tried both with and without the :z and I get exactly the same error. I'm running Home assistant on a Synology DS218+ with DSM 6.2.4-25556 Update 6.

docker run -d --name=home-assistant --privileged --network=host --restart=unless-stopped -v "/volume2/@root_docker/home-assistant":/config -v /etc/localtime:/etc/localtime:ro -v /dev/bus/usb:/dev/bus/usb:z -v /var/run/dbus:/var/run/dbus:z homeassistant/home-assistant:stable

@unfurled
Copy link

Same issue for me. Only that I'm running HA in a VM on Proxmox 7.2-4. It was working fine before the migration to bleak.

@emailforos
Copy link

emailforos commented Jul 20, 2022

I updated HA to 2022.7.5 and Switchbot stop working again (after being able to work with @Chreece suggestion).

The message that appears in HA log is:

Logger: homeassistant.components.switchbot.coordinator
Source: components/switchbot/coordinator.py:43
Integration: SwitchBot (documentation, issues)
First occurred: 10:19:14 (2 occurrences)
Last logged: 10:19:42

Unexpected error fetching switchbot data: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 205, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 43, in _async_update_data
    switchbot_data = await self.switchbot_data.discover(
  File "/usr/local/lib/python3.10/site-packages/switchbot/__init__.py", line 162, in discover
    await devices.start()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/scanner.py", line 155, in start
    assert_reply(reply)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/utils.py", line 23, in assert_reply
    raise BleakDBusError(reply.error_name, reply.body)
bleak.exc.BleakDBusError: [org.freedesktop.DBus.Error.UnknownObject] Method "SetDiscoveryFilter" with signature "a{sv}" on interface "org.bluez.Adapter1" doesn't exist

I did not touch anything except to perform the update. Any idea?

@nitobuendia
Copy link

@emailforos Do you have more than one Bluetooth device (e.g. native from the system and an adapter)?

I had the same issue, it seem the solution uses interface=0 and that was not working for me. I changed that for interface=1 and that worked fine. Basically, try this.

I am not sure why this is happening, but once I realized that was the issue, I simply removed one of the interfaces (i.e. unplugged the USB Bluetooth dongle), restarted the server, and it worked ever since. However, you could also change the code of the integration like this. I did try disabling, filtering and/or swapping the interfaces at the operating system level but that was not very fruitful for me.

A more long-term fix should be handled natively to explore all available interfaces, I feel.

@emailforos
Copy link

@emailforos Do you have more than one Bluetooth device (e.g. native from the system and an adapter)?

I had the same issue, it seem the solution uses interface=0 and that was not working for me. I changed that for interface=1 and that worked fine. Basically, try this.

I am not sure why this is happening, but once I realized that was the issue, I simply removed one of the interfaces (i.e. unplugged the USB Bluetooth dongle), restarted the server, and it worked ever since. However, you could also change the code of the integration like this. I did try disabling, filtering and/or swapping the interfaces at the operating system level but that was not very fruitful for me.

A more long-term fix should be handled natively to explore all available interfaces, I feel.

Thank you for your reply.

Unfortunately, I'm not a programmer and change the inside code of my HA scares me a lot. I will need a step by step manual and the answer to other issue is not for the switchbot so the steps to follow I'm not sure to be able to follow them.

On the other hand, I have only one bluetooth device (no hub, directly from my raspberry pi) and nothing changed in my system before the 2022.7 breaking change in home assistant.

I think that the origin of the error in this integration is clear. Unfortunately both programmers of this integration may be busy and they don't have enough time to review it. It's comprensible, they have their own jobs and HA is their hobby.

@emailforos
Copy link

If someone is interested.

Until the official integration is solved, I'm using it with this mqtt solution: https://github.com/fphammerle/switchbot-mqtt

@bdraco
Copy link
Member

bdraco commented Jul 24, 2022

Thank you for reaching out. The above are all problems with dbus configuration not specifically related to the integration. We use GitHub for tracking issues, not for providing support.

If you want help with a setup, you should try our Community Forum: Configuration.

If you have additional questions, feel free to join our Discord chat server.

Thanks! 👍

@bdraco bdraco closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2022
@bdraco
Copy link
Member

bdraco commented Jul 24, 2022

D-Bus and BlueZ are required on Linux

For Bluetooth to function on Linux systems, the D-Bus socket must be accessible to Home Assistant. The Bluetooth adapter must be accessible to D-Bus and running BlueZ >= 5.43.

  • Home Assistant Operating System: no additional steps are required. Version 8.4 or later is recommended for performance reasons.
  • Home Assistant Container: The host system must run BlueZ, and the D-Bus socket must be accessible to Home Assistant inside the container.
  • Home Assistant Supervised: The host system must run BlueZ, and the D-Bus socket must be accessible to Home Assistant inside the container.
  • Home Assistant Core: The system must run BlueZ, and the D-Bus socket must be accessible to Home Assistant.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants