d03n3rfr1tz3 / hass-divoom

Divoom Integration for Home Assistant
MIT License
111 stars 9 forks source link

Unknown error in custom_components/divoom/devices/divoom.py:138 - (Bluetooth Proxy with ESPHome) #28

Closed Eisbergsalat closed 8 months ago

Eisbergsalat commented 8 months ago

Hi 😄

During my setup I encountered a little issue. Most likely due to my incompetence 😅 Hopefully someone can help?

First of all: I have to use Bluetooth proxy with ESPHome. Due to being supervised in a VM, BLE-Adapter wont work. I can connect HA with the Pixoo, but I cant get the notify command through (Bluetooth on the only phone ever connected is disabled)

Setup: Neither the setup via the integration site nor in configuration.yaml change anything. But either way, the setup itself is without error and seems to work. image

Only the notify service doesnt work: Modern: image Classic: image

LogFile of Home Assistant Core shows the following Error:

" Logger: homeassistant.components.websocket_api.http.connection Quelle: custom_components/divoom/devices/divoom.py:138 Integration: Home Assistant WebSocket API (Dokumentation, Probleme) Erstmals aufgetreten: 21:52:01 (8 Vorkommnisse) Zuletzt protokolliert: 22:20:28

[139856287054528] Error handling message: Unknown error (unknown_error) User from 172.29.0.1 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36) [139856071238592] Error handling message: Unknown error (unknown_error) User from 172.29.0.1 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 795, in handle_execute_script script_result = await script_obj.async_run( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1600, in async_run return await asyncio.shield(run.async_run()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 435, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 487, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 512, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 485, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 723, in _async_call_service_step response_data = await self._async_run_long_action( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 685, in _async_run_long_action return long_task.result() ^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2319, in async_call response_data = await coro ^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/core.py", line 2356, in _execute_service return await target(service_call) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 265, in _async_notify_message_service await self.async_send_message(*kwargs) File "/usr/src/homeassistant/homeassistant/components/notify/legacy.py", line 241, in async_send_message await self.hass.async_add_executor_job( File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run result = self.fn(self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/divoom/notify.py", line 186, in send_message self._device.send_brightness(value=value) File "/config/custom_components/divoom/devices/divoom.py", line 314, in send_brightness self.send_command("set brightness", args, skipRead=True) File "/config/custom_components/divoom/devices/divoom.py", line 163, in send_command self.send_payload(payload, skipRead=skipRead) File "/config/custom_components/divoom/devices/divoom.py", line 138, in send_payload result = self.socket.send(bytes(request)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: [Errno 107] Socket not connected "

Can someone help me resolve this issue?

P.s. To the creditors and especially the author: I really appriciate your hard work in this project ❤️

d03n3rfr1tz3 commented 8 months ago

Hey you delicious salad, I have good news and bad news for you.

The good news is, you did nothing wrong (or at least I see no error in your configuration). 🙂 \ The bad news is, all the Divoom devices with Bluetooth use Bluetooth Classic and not Bluetooth Low Energy (BLE). 😐

The Bluetooth Proxies that HomeAssistant added are only working with BLE afaik. Bluetooth classic is not in a very good spot generally in Python, besides the native support through sockets. Thats why it needs an initial pairing through bluetoothctl or the older hcitool and rfcomm tooling. So for it to work, you would have to pair it once and have it near your actual HomeAssistant host, when you want to use it. I might have to rework that section in the readme and at least mention it a bit earlier probably.

Not to give you too much hope, but because ESP32 theoretically supports Bluetooth classic, it should be possible to also do some sort of Bluetooth classic proxy-like firmware/software for ESP32. Like sending the actual raw packets via WiFi to the ESP32, which then sends it to the connected BT classic device or something like that.

Eisbergsalat commented 8 months ago

Hey you delicious salad, I have good news and bad news for you.

The good news is, you did nothing wrong (or at least I see no error in your configuration). 🙂 The bad news is, all the Divoom devices with Bluetooth use Bluetooth Classic and not Bluetooth Low Energy (BLE). 😐

The Bluetooth Proxies that HomeAssistant added are only working with BLE afaik. Bluetooth classic is not in a very good spot generally in Python, besides the native support through sockets. Thats why it needs an initial pairing through bluetoothctl or the older hcitool and rfcomm tooling. So for it to work, you would have to pair it once and have it near your actual HomeAssistant host, when you want to use it. I might have to rework that section in the readme and at least mention it a bit earlier probably.

Not to give you too much hope, but because ESP32 theoretically supports Bluetooth classic, it should be possible to also do some sort of Bluetooth classic proxy-like firmware/software for ESP32. Like sending the actual raw packets via WiFi to the ESP32, which then sends it to the connected BT classic device or something like that.

Thanks a lot for your explanation!

Then I will reprogramm those as esp32 as ble trackers. I couldnt find any ESPHome Extension or alternative using Bluetooth classic for ESP32. And I am not really majoring in any kind of programming or computer science.

I will try to install a BT Dongle with passthrough. Hopefully both Linux based OS will be able to handle it. 😅

d03n3rfr1tz3 commented 7 months ago

Hey, just wanted to give an update, that might improve your situation. I just implemented and partially tested an ESP32 Bluetooth proxy explicitly for my Divoom integration. The ESP32 part already works quite good, besides a few bugs. The HA integration part is currently untested, but should also work. Obviously it's still WIP, but maybe you want to keep an eye on it already.

The ESP32 firmware (PlatformIO Project): https://github.com/d03n3rfr1tz3/esp32-divoom The branch on HASS-Divoom with support for it: https://github.com/d03n3rfr1tz3/hass-divoom/tree/feature/esp32-divoom