hcoohb / hass-yeelightbt

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

Add support for Home Assistant Operating System #3

Closed NoxNoctium closed 3 years ago

NoxNoctium commented 4 years ago

Currently this custom component doesn't seem to be compatible with Home Assistant Operating System. Adding the component and setting it up in the "integrations" menu works but connection to the actual bedside lamp fails. HAOS uses buildroot, setting permissions as instructed in the ReadMe fails, "setcap" is not available on the host system.

Relevant log entries:

2020-09-14 00:22:18 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for yeelight_bt 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.
2020-09-14 00:22:21 DEBUG (MainThread) [custom_components.yeelight_bt] async setup.
2020-09-14 00:22:21 DEBUG (MainThread) [custom_components.yeelight_bt]  List entries for domain:
2020-09-14 00:22:21 DEBUG (MainThread) [custom_components.yeelight_bt] [<homeassistant.config_entries.ConfigEntry object at 0x7f4be087fa40>]
2020-09-14 00:22:23 DEBUG (MainThread) [custom_components.yeelight_bt] async setup entry: {'entry_id': '6f68d7bcf5e311eaa0ab4fad0266453c', 'version': 1, 'domain': 'yeelight_bt', 'title': 'Schlafzimmer-Nachttischlampe', 'data': {'name': 'Schlafzimmer-Nachttischlampe', 'mac': 'F8:24:41:E5:CF:89'}, 'options': {}, 'system_options': {'disable_new_entities': False}, 'source': 'user', 'connection_class': 'local_poll', 'unique_id': 'f8:24:41:e5:cf:89'}
2020-09-14 00:22:25 DEBUG (MainThread) [custom_components.yeelight_bt.light] async_setup_entry:setting up the config entry Schlafzimmer-Nachttischlampe with data:{'name': 'Schlafzimmer-Nachttischlampe', 'mac': 'F8:24:41:E5:CF:89'}
2020-09-14 00:22:25 INFO (MainThread) [custom_components.yeelight_bt.light] Initializing Schlafzimmer-Nachttischlampe, F8:24:41:E5:CF:89
2020-09-14 00:22:25 DEBUG (MainThread) [custom_components.yeelight_bt.yeelightbt] Creating Yeelight Lamp F8:24:41:E5:CF:89
2020-09-14 00:22:56 DEBUG (SyncWorker_20) [custom_components.yeelight_bt.light] Requesting an update of the lamp status
2020-09-14 00:22:56 DEBUG (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Get_state
2020-09-14 00:23:37 WARNING (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Could not connect to lamp: error<class 'bluepy.btle.BTLEDisconnectError'>(Failed to connect to peripheral F8:24:41:E5:CF:89, addr type: public), Retrying in 0.1 seconds...
2020-09-14 00:24:18 WARNING (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Could not connect to lamp: error<class 'bluepy.btle.BTLEDisconnectError'>(Failed to connect to peripheral F8:24:41:E5:CF:89, addr type: public), Retrying in 0.1 seconds...
2020-09-14 00:24:59 ERROR (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Could not connect to lamp: error<class 'bluepy.btle.BTLEDisconnectError'>(Failed to connect to peripheral F8:24:41:E5:CF:89, addr type: public)
2020-09-14 00:24:59 DEBUG (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Writing  0x434402000000000000000000000000000000 on handle False
2020-09-14 00:24:59 WARNING (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Could not write to lamp: error<class 'bluepy.btle.BTLEInternalError'>(Helper not started (did you call connect()?)), Retrying now...
2020-09-14 00:24:59 DEBUG (SyncWorker_20) [custom_components.yeelight_bt.light] Got state notification from the lamp
2020-09-14 00:25:40 WARNING (SyncWorker_20) [custom_components.yeelight_bt.yeelightbt] Could not connect to lamp: error<class 'bluepy.btle.BTLEDisconnectError'>(Failed to connect to peripheral F8:24:41:E5:CF:89, addr type: public), Retrying in 0.1 seconds...
hcoohb commented 4 years ago

Hi, Thanks for reporting the issue! I do not use hassio and have never used it, so I might not be fully across the technical details, but from what I can read online, the hassio image already contains bluepy so I would assume they have already set the system permissions accordingly. But from the log it is clear that bluepy cannot connect to the device.

Can I ask what host you use for hassio? RPI, NUC? And are you using the integrated bt or a usb dongle? Also, do you have the bt working for other components?

NoxNoctium commented 4 years ago

Hi hcoohb, Thanks for looking into it!

I use an older laptop with Proxmox as host and Home Assistant OS running inside a virtual machine, with the USB device of the Intel bluetooth adapter (ID: 8087:0025) assigned to it. Yes bluepy is already included and I can scan for devices from inside the Home Assistant OS VM, I even got the bedside lamp into pairing mode with it. To try out bluetooth I've set up the mitemp_bt platform for three room temperature sensors, Home Assistant is able to read out and display the sensor data reliably.

I'll try out a "cleaner" approach at the weekend with a RPi3B+, Home Assistant OS and the included bluetooth adapter if you want me to.

hcoohb commented 4 years ago

So it seems bluetooth is definitely running well on your machine and hassio is able to control it. But the bluetooth-helper of the library could not establish a connection at all. I need to enable more trace for that (I'll do that in next release)

And then if you are familiar with your system, best way would be to ssh in hassio and try to connect to the lamp manually first.

ps, can I ask the process hassio to scan for device as another user has the issue to find the mac address of the lamp using hassio...?

NoxNoctium commented 4 years ago

I've played around with bluetoothctl inside the Home Assistant OS VM and also the host machine this evening and unfortunately it seems I was wrong about being able to pair the lamp. It flashed a few times (indicating pairing process) during my attempts but it actually failed to pair, rather it was listed as a"trusted" device. Judging from the related journald loglines it errors out after the device interview and during the start of the pairing process. I can pair other devices though without an issue. I'll try out the pairing behaviour on another bluetooth adapter and a RPi and get back to you next week.

To your ps: I don't know of any bluetooth related funtions in hass-cli but you can always enter "login" and access the OS directly, from there you can use bluetoothctl for the scanning/pairing process. I'd also suggest waiting for the wifi/bluetooth-integration in the Home Assistant OS network manager as teased in this blog post: https://www.home-assistant.io/blog/2020/09/16/supervisor-joins-the-party/

This is just the start to make advanced host management more accessible and it only touches a minimal part of what we will be able to do with it. Support for Wi-Fi and Bluetooth will follow later as part of our usability improvements.