klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
69 stars 15 forks source link

Trying to get ha-plejd to work on home assistant docker on Synology nas #43

Closed anha7196 closed 3 years ago

anha7196 commented 3 years ago

Hi, and many thanks for all Your hard work!

I´m trying to get ha-plejd to work on the official home assistant docker image on Synology nas, but I'm running in to some problems.

I'm running the docker container with high privelege and ha runs as root.

First i got the file not found error reported here in other issues, after adding " -v /var/run/dbus:/var/run/dbus", i get another error which makes me think i got a little bit further:

2021-03-24 15:53:28 ERROR (MainThread) [homeassistant.components.light] Error while setting up plejd platform for light Traceback (most recent call last): File "/usr/local/lib/python3.8/site-packages/dbus_next/proxy_object.py", line 214, in get_interface intr_interface = next(i for i in self.introspection.interfaces if i.name == name) StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 200, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/plejd/light.py", line 478, in async_setup_platform await connect(plejdinfo) File "/config/custom_components/plejd/light.py", line 175, in connect om = bus.get_proxy_object(BLUEZ_SERVICE_NAME, '/', om_introspection).get_interface(DBUS_OM_IFACE) File "/usr/local/lib/python3.8/site-packages/dbus_next/aio/proxy_object.py", line 159, in get_interface return super().get_interface(name) File "/usr/local/lib/python3.8/site-packages/dbus_next/proxy_object.py", line 216, in get_interface raise InterfaceNotFoundError(f'interface not found on this object: {name}') dbus_next.errors.InterfaceNotFoundError: interface not found on this object: org.freedesktop.DBus.ObjectManager

hcitool seems to scan fine:

bash-5.0# hcitool dev Devices: hci0 00:1A:7D:DA:71:0C

bash-5.0# hcitool lescan
LE Scan ...
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
E8:63:57:EA:F6:33 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh
D0:16:3D:92:40:48 P mesh

bluetoothctl however has no controller: [bluetooth]# list [bluetooth]#

Any idea if it is possible to get ha-plejd working on this setup?

klali commented 3 years ago

bluetoothctl is a good tool here, it also uses dbus to speak bluetooth.

Do you have bluetoothd running outside the container? The point of mapping through the dbus socket is that you can then from inside the container reach bluetoothd outside, a different option is to try to map through the adapter and run bluetoothd inside the container.

anha7196 commented 3 years ago

Yes, bluetoothd is running outside the container, and a bluetooth scan works from the synology gui. However no bluetoothctl is available there. I guess running bluetoothd from inside the container would demand changes to the container that would be wiped every upgrade, so i would prefer the other route. Any tips on how to continue from here?

klali commented 3 years ago

Yeah, I think it's a saner setup to have bluetoothd running outside the container. I'm not very familiar with containers and even less so with synology.

Do you know what version of bluetoothd is running? Do you have a system dbus-daemon running outside of the container? Is /var/run/dbus/system_bus_socket the socket it uses?

anha7196 commented 3 years ago

bluetoothd --version 4.101

ps -ef | grep dbus root 4877 1 0 Mar11 ? 00:01:58 /sbin/dbus-daemon --session --fork --print-address root 4884 1 0 Mar11 ? 00:01:33 /sbin/dbus-daemon --system --nopidfile

/var/run/dbus/system_bus_socket is there at least, don´t know how to check if that is the one being used though.

Thanks for helping!

klali commented 3 years ago

That's a seriously old version of bluetoothd, the dbus API was introduced in version 5, I'm not sure about what versions exactly are needed, but 5.48 works and I think someone had issues with 5.37.

edit: 4.101 seems to have been released in 2012..

anha7196 commented 3 years ago

Hm, I'll look into upgrading it. The Synology OS is updated to the latest release, so i assume Synology just have an old version in their OS for some reason.

anha7196 commented 3 years ago

Still trying to get this to work, but with no success so far. Upgrading blutetoothd on the Synoplogy seems not to be possible. There is no packages and no further patches. Seems strange to me that they use such an old version.

I've been exploring the option to run bluetoothd in the container instead, but run into new errors: If i understand it correctly i need to stop bluetoothd on the host and run it in the container instead, i get errors starting bluetoothd, and new errors in the home assistant log:

starting bluetoothd in container: bash-5.0# /usr/lib/bluetooth/bluetoothd -n bluetoothd[245]: Bluetooth daemon 5.54 bluetoothd[245]: Starting SDP server bluetoothd[245]: kernel lacks bnep-protocol support bluetoothd[245]: System does not support network plugin bluetoothd[245]: Failed to open RFKILL control device bluetoothd[245]: Bluetooth management interface 1.7 initialized bluetoothd[245]: Failed to read advertising features: Unknown Command (0x01)

Result in HA-logs: 2021-03-30 09:36:36 ERROR (MainThread) [homeassistant.components.light] Error while setting up plejd platform for light Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 200, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/plejd/light.py", line 478, in async_setup_platform await connect(plejdinfo) File "/config/custom_components/plejd/light.py", line 213, in connect await adapter.call_set_discovery_filter(scan_filter) File "/usr/local/lib/python3.8/site-packages/dbus_next/aio/proxy_object.py", line 92, in method_fn BaseProxyInterface._check_method_return(msg, intr_method.out_signature) File "/usr/local/lib/python3.8/site-packages/dbus_next/proxy_object.py", line 61, in _check_method_return raise DBusError._from_message(msg) dbus_next.errors.DBusError: Resource Not Ready

Any ideas how to proceed?

klali commented 3 years ago

You would have to map the bluetooth devices through to the container in that case I imagine.

I find mentions of running the container with --privileged but you'll have to research and debug that more.

anha7196 commented 3 years ago

Hi! Just wanted to let you know that i after a lot of research and testing gave up on getting this to run on my Synology. There is several examples of people getting BT to work on synology and docker, but the instructions from them, like --priviliged and device mappings won´t work in my case. I ended up running Thomas Lovéns plejd2mqtt on my always on Kodi RPI, with the same BT-stick instead. His software did not work on the Synology either, even running directly on the NAS OS, so my theory is that it was something with the Synology implementation of BT. Anyway, thanks for your help!