wez / govee-lan-hass

Control Govee lights via the LAN API from Home Assistant
MIT License
200 stars 9 forks source link

Add bluetooth #6

Closed max246 closed 8 months ago

max246 commented 1 year ago

Can you add a flag to enable the bluetooth discovery? I have 3 of the H6058 and they are very slow over the API, I suppose via bluetooth it will be much better.

It is odd because when I use with my google home, it works almost all the time, but using a scene to trigger 3 of them at the same time, they light up with some delay and sometimes one or two dont get triggered at all

wez commented 1 year ago

bluetooth discovery is already enabled by default, and will take advantage of any esphome bluetooth proxies you may have. However, the integration tries to avoid keeping a bluetooth connection to the devices persistently so that it doesn't prevent you from using the Govee app. That means that it can take several seconds to connect and respond to a command.

I have an H6058: that model (or at least, the one that I have: firmware version: 1.01.13, Hardware version: 3.02.02) doesn't support the LAN API and only works via bluetooth.

Does yours have the LAN API option in the Govee app?

If you put this into your configuration.yml, you'll see increased diagnostic information that might help inform what is happening:

logger:
  logs:
    custom_components.govee_lan: debug
    govee_led_wez: debug
max246 commented 1 year ago

My lamp which has LAN API is working fine, my lights are actually 1.01.11 but cant seems to upgrade the firmware anywhere.

I noticed a crash in the code when I press the button which it might the reason of the "slow communication"

2023-01-06 20:28:15.021 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration ble_monitor 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-01-06 20:28:15.027 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration govee_lan 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-01-06 20:28:15.032 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration google_home 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-01-06 20:28:15.037 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration bodymiscale 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-01-06 20:28:15.042 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs 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-01-06 20:28:15.047 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration spotcast 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-01-06 20:28:47.777 WARNING (MainThread) [homeassistant.components.bluetooth_le_tracker.device_tracker] No Bluetooth LE devices to track!
2023-01-06 20:28:47.802 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform legacy bluetooth_le_tracker
2023-01-06 20:29:03.212 WARNING (MainThread) [homeassistant.components.light] Setup of light platform govee_lan is taking over 10 seconds.
2023-01-06 20:29:03.216 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of binary_sensor platform ble_monitor is taking over 10 seconds.
2023-01-06 20:29:03.221 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform ble_monitor is taking over 10 seconds.
2023-01-06 20:29:03.225 WARNING (MainThread) [homeassistant.components.binary_sensor] Setup of binary_sensor platform roku is taking over 10 seconds.
2023-01-06 20:29:03.228 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform roku is taking over 10 seconds.
2023-01-06 20:29:03.796 WARNING (MainThread) [homeassistant.config_entries] Config entry 'HP DeskJet 3630 series [6635E2]' for ipp integration not ready yet: Invalid response from API: Timeout occurred while connecting to IPP server.; Retrying in background
2023-01-06 20:29:14.990 WARNING (MainThread) [aioesphomeapi.reconnect_logic] Can't connect to ESPHome API for esp-rflink @ 192.168.50.100: Error connecting to ('192.168.50.100', 6053): [Errno 113] Connect call failed ('192.168.50.100', 6053)
2023-01-06 20:29:36.635 ERROR (MainThread) [homeassistant.components.roku.coordinator] Error fetching roku data: Invalid response from API: Error occurred while communicating with device
2023-01-06 20:36:41.136 DEBUG (MainThread) [govee_led_wez.govee] _lan_poller_process_broadcast msg={'msg': {'cmd': 'devStatus', 'data': {'onOff': 0, 'brightness': 100, 'color': {'r': 255, 'g': 200, 'b': 36}, 'colorTemInKelvin': 0}}} from ('192.168.50.233', 49849)
2023-01-06 20:36:41.137 DEBUG (MainThread) [govee_led_wez.govee] F4:0B:CF:33:34:36:72:66 state is same as previous, skip callback
2023-01-06 20:36:41.843 DEBUG (MainThread) [govee_led_wez.govee] sending ble control to A3:94:CB:31:30:30:26:8E: b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
2023-01-06 20:36:41.844 DEBUG (MainThread) [govee_led_wez.ble] Attempt to connect to CB:31:30:30:26:8E: Govee_H6058_268E
2023-01-06 20:36:44.470 DEBUG (MainThread) [govee_led_wez.govee] Updating BLE device association for CB:31:30:30:26:8E with A3:94:CB:31:30:30:26:8E
2023-01-06 20:36:44.480 DEBUG (MainThread) [govee_led_wez.ble] calling write_gatt_char CB:31:30:30:26:8E: Govee_H6058_268E b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
2023-01-06 20:36:44.485 DEBUG (MainThread) [govee_led_wez.govee] ble control was sent successfully
2023-01-06 20:36:44.500 DEBUG (MainThread) [govee_led_wez.govee] sending ble control to F3:DC:CC:31:30:30:39:1A: b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
2023-01-06 20:36:44.500 DEBUG (MainThread) [govee_led_wez.ble] Attempt to connect to CC:31:30:30:39:1A: Govee_H6058_391A
2023-01-06 20:36:46.179 DEBUG (MainThread) [govee_led_wez.govee] _lan_poller_process_broadcast msg={'msg': {'cmd': 'scan', 'data': {'ip': '192.168.50.233', 'device': 'F4:0B:CF:33:34:36:72:66', 'sku': 'H6072', 'bleVersionHard': '3.02.00', 'bleVersionSoft': '2.03.03', 'wifiVersionHard': '1.00.10', 'wifiVersionSoft': '1.02.11'}}} from ('192.168.50.233', 49850)
2023-01-06 20:36:50.247 DEBUG (MainThread) [govee_led_wez.govee] unable to connect to F3:DC:CC:31:30:30:39:1A via BLE
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/govee.py", line 373, in _ble_device_control
    await entry.write_gatt_char(pkt)
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/ble.py", line 65, in write_gatt_char
    client = await self.connect()
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/ble.py", line 52, in connect
    client = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 342, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 250, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 206, in connect
    await self.get_services(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 590, in get_services
    self.services = await manager.get_services(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 573, in get_services
    await self._wait_for_services_discovery(device_path)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 663, in _wait_for_services_discovery
    done, pending = await asyncio.wait(
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 384, in wait
    return await _wait(fs, timeout, return_when, loop)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 491, in _wait
    await waiter
asyncio.exceptions.CancelledError
2023-01-06 20:36:50.280 DEBUG (MainThread) [govee_led_wez.ble] Disconnecting client from D9:31:30:30:55:5D: Govee_H6058_555D
2023-01-06 20:36:50.280 DEBUG (MainThread) [govee_led_wez.ble] Attempt to connect to CC:31:30:30:39:1A: Govee_H6058_391A
2023-01-06 20:36:51.840 DEBUG (MainThread) [govee_led_wez.ble] calling write_gatt_char CC:31:30:30:39:1A: Govee_H6058_391A b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
2023-01-06 20:36:51.860 DEBUG (MainThread) [govee_led_wez.govee] sending ble control to 70:43:D9:31:30:30:55:5D: b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
2023-01-06 20:36:51.860 DEBUG (MainThread) [govee_led_wez.ble] Attempt to connect to D9:31:30:30:55:5D: Govee_H6058_555D
2023-01-06 20:36:56.182 DEBUG (MainThread) [govee_led_wez.govee] _lan_poller_process_broadcast msg={'msg': {'cmd': 'scan', 'data': {'ip': '192.168.50.233', 'device': 'F4:0B:CF:33:34:36:72:66', 'sku': 'H6072', 'bleVersionHard': '3.02.00', 'bleVersionSoft': '2.03.03', 'wifiVersionHard': '1.00.10', 'wifiVersionSoft': '1.02.11'}}} from ('192.168.50.233', 49851)
2023-01-06 20:36:57.233 DEBUG (MainThread) [govee_led_wez.govee] unable to connect to 70:43:D9:31:30:30:55:5D via BLE
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/govee.py", line 373, in _ble_device_control
    await entry.write_gatt_char(pkt)
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/ble.py", line 65, in write_gatt_char
    client = await self.connect()
  File "/usr/local/lib/python3.10/site-packages/govee_led_wez/ble.py", line 52, in connect
    client = await establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 342, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 250, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 471, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 206, in connect
    await self.get_services(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 590, in get_services
    self.services = await manager.get_services(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 573, in get_services
    await self._wait_for_services_discovery(device_path)
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/manager.py", line 663, in _wait_for_services_discovery
    done, pending = await asyncio.wait(
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 384, in wait
    return await _wait(fs, timeout, return_when, loop)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 491, in _wait
    await waiter
asyncio.exceptions.CancelledError
2023-01-06 20:36:57.236 DEBUG (MainThread) [govee_led_wez.ble] Disconnecting client from CB:31:30:30:26:8E: Govee_H6058_268E
2023-01-06 20:36:57.237 DEBUG (MainThread) [govee_led_wez.ble] Attempt to connect to D9:31:30:30:55:5D: Govee_H6058_555D
2023-01-06 20:37:00.466 DEBUG (MainThread) [govee_led_wez.ble] calling write_gatt_char D9:31:30:30:55:5D: Govee_H6058_555D b'3\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x002'
wez commented 8 months ago

I have no plans to work on this. I've shifted my focus to my new Govee2MQTT AddOn. However, I've made the conscious choice to not support BLE in that addon. I did look into it and what I found was that it was too slow and unreliable compared to the LAN and HTTP APIs.