hcoohb / hass-yeelightbt

Home assistant custom component for Yeelight bluetooth
50 stars 16 forks source link

Will not work with 2022.7 #19

Closed velijv closed 2 years ago

velijv commented 2 years ago

Setup failed for custom integration yeelight_bt: Requirements for yeelight_bt not found: ['bluepy>=1.3.0'].

breaking changes

These integrations rely on the bluepy library, which no longer works in newer versions of Python. bluepy has seen its last update in December 2018 and hasn’t kept up with changes in the Python world.

It is not possible for us to mitigate this issue. If you are using one of these integration, these will no longer work.

If you like to help out to fix or upgrade one of these integrations, we would be grateful. We recommend migrating these integrations onto the Bleak libary instead.

dinozavrix commented 2 years ago

hi @hcoohb, really love your integration! Thank you for it. Is there any chance you will update it to new library?

hcoohb commented 2 years ago

Thanks @velijv for the heads up. @dinozavrix , yes, I will try to see if we can use bleak instead. It might take a few days/weeks as my free time is limited at the moment... I was working on a component for esphome as the bluepy lib was pretty temperamental to start with... but hopefully bleak is more robust.

NielsDigitalLink commented 2 years ago

Hi @hcoohb,

First I wanted to say thank you and I greatly appreciate your work for integrating Yeelight Bluetooth into Home Assistant. I've tried your newest commit with the conversion to Bleak, but am experiencing some issues.

I use Home Assistant OS on a Raspberry Pi 4B and have updated to 2022.7.5. I manually replaced custom_components\yeelight_bt with the 'bleak' branch. I have two Yeelight Candelas and am trying to get them working in HA again, without success. Both have been reset successfully, but I don't get to see the pairing sequence when restarting HA.

I have enabled debug logging (see below) and tried to connect 1 lamp. When I change the brightness by turning, it does get notifications, but I see the error "BleakError: [org.bluez.Error.Failed] Operation failed with ATT error: 0x0e (Connection Rejected Due To Security Reasons)". Is there something on OS level that I should change? Or something in configuration.yaml or in the GUI in HA? What am I missing here?

https://pastebin.com/tDGZhi2X

(edited to place log in pastebin so this thread is more readable)

hcoohb commented 2 years ago

Hi @NielsDigitalLink , Thanks for trying it out and for the log. I do not use HAOS nor do I have a candela, so that is going to be interesting... I can see from the log that the issue seems to happen during the request for notifications, even though it seems to go through as the lamp does receive notif, but the pairing step is never started... confusing. The Candela might be a bit more sensitive than the yeelight.

To have a bit more details on your system and lights, could you try the updated bleak branch doing the following:

I don't really expect it to work better since I did not just change any connection logic, but the log from scan might be helpful. Also:

NielsDigitalLink commented 2 years ago

Hi @hcoohb,

So, this is what I've got from logging. I tried it with one Candela, the other one was physically turned off (so there is no impact).

https://pastebin.com/t8R7Gu9B

To answer your questions:

(edited to place log in pastebin so this thread is more readable)

NielsDigitalLink commented 2 years ago

An addition: I just noticed that after 10 minutes it requested to pair and the logging stated it was succesfull. However, the lamp is still unavailble in HA. Here you can find the extended logging (with the pairing). I also restarted HA after that, but that didn't help.

https://pastebin.com/t8R7Gu9B

(edited to place log in pastebin so this thread is more readable)

NielsDigitalLink commented 2 years ago

Hi again @hcoohb,

Yesterday around 23 o'clock, it suddenly seemed to work (after leaving it alone for a couple of hours): I could change the brightness using the UI in HA. However, it only lasted for a few seconds. You can see in the logging below, I could turn it on at 22:56:46, set the brightness to 45 at 22:56:47, change the brightness to 79 at 22:57:26 and then at 22:57:29 it got disconnected again and I couldn't control the lamp anymore. Hope this helps.

https://pastebin.com/0aEyDEFe

(edited to place log in pastebin so this thread is more readable)

BrendanxP commented 2 years ago

Hi @NielsDigitalLink , Thanks for trying it out and for the log. I do not use HAOS nor do I have a candela, so that is going to be interesting... I can see from the log that the issue seems to happen during the request for notifications, even though it seems to go through as the lamp does receive notif, but the pairing step is never started... confusing. The Candela might be a bit more sensitive than the yeelight.

To have a bit more details on your system and lights, could you try the updated bleak branch doing the following:

  • remove integration from UI or uncomment all yeelightbt lights from yaml
  • enable debug logs for yeelightbt
  • restart HA
  • reset the lamp
  • add the yeelightbt integration through the UI
  • Please do a scan, and hopefully it should find your lamps
  • Add one by naming it (might need to finish the pair process by touching the lamp)
  • wait about 30s
  • modify the brightness physically on hte lamp
  • wait a bit
  • modify the brightness through the UI if lamp is available
  • Collect the logs and post here please

I don't really expect it to work better since I did not just change any connection logic, but the log from scan might be helpful. Also:

  • you had those lights working previously with this integration when on HA 2022.6?
  • Do you have any other bluetooth devices being controlled by HA?

I also own a Candela and had it set-up using your Integration. However, I barely used the control via Home Assistant as the Bluetooth reach was quite terrible. I recently installed an esp32 to gateway the signal from some other devices to HA. It would be amazing if I could do the same for the Candela. If you need more logs I could try to get it to work again using your new branch. Let me know!

moridew commented 2 years ago

Thank you for your efforts. I look forward to using it someday. Have a nice day.

hcoohb commented 2 years ago

@NielsDigitalLink , Thank for those logs, but I find all this even more confusing... Only difference with my scan is that the yeelight appears to be trusted and not your candela. The logs prove it can connect sometimes... It struggles to send the pair command and that is why the lamp disconnect after 10sec anyway. But it work once and most of the time it seems it is not necessary the lamp but the bluetooth stack that is refusing to connect. The light is not too far from the BT adapter, right?

Bleak is using a different bluetooth stack than the previous bluepy, so apologies but I am learning about bluez at the same time, and it seems that it does not appear to be the most robust piece of software...

I did try to iron a few issues around handling connection and re-connection, so that might be worth trying again, Can you also enable bleak:debug in the HA configuration.yaml like shown below? And also maybe post the logs on pastebin so to keep this thread readable.

logger:
  default: error
  logs:
    custom_components.yeelight_bt: debug
    bleak: debug

Also if anyone else could try the bleak branch that would be useful to try on different hardware and see if the same issue or not, as the bedside yeelight works perfect for me...

varakirill commented 2 years ago

Hi. I can confirm - Yeelight Bedside Lamp (BT) works perfect with bleak.

mfabiani53 commented 2 years ago

Hi. I can confirm - Yeelight Bedside Lamp (BT) works perfect with bleak.

Can you tell me where to get the working code with bleak and how to switch from the old code?

moridew commented 2 years ago

i think bleak branch

https://github.com/hcoohb/hass-yeelightbt/tree/bleak

jussapaavo commented 2 years ago

Can you create a beta version of this branch? I can then install it via HACS and see if it works with Candela lights.

jussapaavo commented 2 years ago

Already, I cloned the files and tested the integration.

The integration found the Candela light succesfully and the setup went through as it should. However, after the setup it just showed the Candela light as 'unavailable' in the device menus. I had similar issues with the previous implementation as well, where the communication with the Candela light was very unstable.

Here's my logs after a restart and setup: https://pastebin.com/LqysbqQ4

tribela commented 2 years ago

I got this error with bleak branch:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 397, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 641, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 775, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/yeelight_bt/light.py", line 110, in async_added_to_hass
    await self._dev.connect()
  File "/config/custom_components/yeelight_bt/yeelightbt.py", line 129, in connect
    await self._client.connect()
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/bluezdbus/client.py", line 112, in connect
    device = await BleakScannerBlueZDBus.find_device_by_address(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/scanner.py", line 220, in find_device_by_address
    return await cls.find_device_by_filter(
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/scanner.py", line 249, in find_device_by_filter
    async with cls(detection_callback=apply_filter, **kwargs):
  File "/usr/local/lib/python3.10/site-packages/bleak/backends/scanner.py", line 95, in __aenter__
    await self.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
hcoohb commented 2 years ago

Thanks everyone for testing, I have to say that the combo bleak and bluez does not seem to have the robustness and stability I was hoping for... Issues from @NielsDigitalLink seems very random with the candela showing that is can connect, but most of the time not... I am under the suspicion that bleak might be a lot more susceptible to the bluetooth hardware and that it may not work well with all bluetooth out there... maybe one thing to ask everyone that report faults.

@varakirill, thanks for confirming that.

@mfabiani53, I just published v1.0.0, so it should appear in HACS for you to update.

@jussapaavo, thanks for reporting, it really looks like the connection could never been established. Is the light far away from bt adapter? It was not connected to the smartphone app at the same time?

@tribela, this look like a library issue as it is right down at the dbus level. Do you have HAOS, HA container or Core? if not HAOS, you will need to give HA the right permissions to talk over dbus (and make sure that bluetoothctl is installed on host). I added comments in the README.

tribela commented 2 years ago

@hcoohb I tested. It seems working almost perfectly. But there a few problem.

I have yeelight bedside(bluetooth), Call "turning on" and "Change mode(color<->temp)" is not working properly.

Step to reproduce

  1. Set colour to red
  2. Turn off
  3. Call light.turnon service with parameters - Colour temp = 1700, brightness = 70
  4. Expected - Turn on and colour temp=1700 / Happened - Turned on 70% brightness, but still red
NielsDigitalLink commented 2 years ago

@hcoohb Hi, sorry I didn't answer yet. I'm on holidays and don't have access to my Candela at the moment. As soon as I'm back I'll test it again and keep you updated. Thank you for your feedback, your time and your effort.

hcoohb commented 2 years ago

Sorry didn't mean to close that one just yet

hcoohb commented 2 years ago

We now have some working versions for the newer HA.

Closing this issue for now