icanos / hassio-plejd

Hass.io add-on for Plejd home automation devices
Apache License 2.0
126 stars 36 forks source link

Support for bluetooth-proxy? #247

Open jompa68 opened 2 years ago

jompa68 commented 2 years ago

https://esphome.github.io/bluetooth-proxies/

SweVictor commented 2 years ago

Cool project! Does it work? 😄 (both in general and for this addon specifically)

In all seriousness - if the underlying libs support the proxy I'm guessing it could work. Many issues here are about BLE issues though, so it is one of the more tricky parts of hassio-plejd.

victorcarl commented 2 years ago

My ESP32 arrived yesterday and I installed it via the webinstaller. The Bluetooth proxy seems to work, but there's no connection to the Plejd integration. I.e. none of my plejd devices show upp and in the Plejd integration log I get:

> 2022-10-27 09:12:57 ERR [plejd-ble] Uh oh, no Plejd device!
> 2022-10-27 09:12:58 ERR [plejd-ble] Discovery timeout elapsed, no devices found. Starting reconnect loop...

My HA server is located in the basement in a server rack, so there's no way I can get Bluetooth coverage via the internal Bluetooth adapter (which works fine. Tried it when installing HA, closer to the Plejd devices).

I'm not sure if reinstalling the Plejd integration would solve this problem. Anyone else having the same issue?

SweVictor commented 2 years ago

I can't give many specific requirements, but I suggest starting with the built-in terminal commands in HA if you haven't. bluetoothctl would be where I would start. If you can discover BLE devices there you at least have a chance in the addon.

victorcarl commented 2 years ago

Thank you. I'll look into it. I did a bluetoothctl and got a lot responses, so there's hope!

victorcarl commented 1 year ago

So I've tried to find controllers via bluetoothctl in the terminal in HA.

First of all, there's just ONE controller shown and it's the internal BTcontroller on the server, not the proxy. When trying to list devices HA detects the BTdevices in the basement (ie. the PAX3 fan in the sauna which has BT for some reason), but none of the devices on first floor are detected.

Skärmavbild 2022-11-03 kl  12 31 09

I did some more digging using VERBOSE mode for logging on the ESP32 board and found that ESP32 is proxying signals from my devices. (In this case a lamp in one of our bedrooms.) I know it's a weak signal, I'm in the basement while configuring the ESP32 and I'll move it to the first floor when configuration is done.

Skärmavbild 2022-11-03 kl  12 12 47

And this is where I'm stuck. It seems that the Plejd integration doesn't pick up the proxied signals.

> 2022-11-03 12:33:30 ERR [plejd-ble] Uh oh, no Plejd device!
> 2022-11-03 12:33:30 ERR [plejd-ble] Uh oh, no Plejd device!
> 2022-11-03 12:33:30 ERR [plejd-ble] Uh oh, no Plejd device!
> 2022-11-03 12:33:30 ERR [plejd-ble] Uh oh, no Plejd device!
> 2022-11-03 12:33:31 ERR [plejd-ble] Discovery timeout elapsed, no devices found. Starting reconnect loop...

Any suggestions on where to dig deeper into this?

SweVictor commented 1 year ago

Start by setting logs to verbose (or potentially even silly to see absolutely everything)

Developing section in readme has instructions on how to extract more logs than are seen

victorcarl commented 1 year ago

Update: I found that the BT proxy is sending signals to HA. (See the post above). I moved the BT proxy a bit closer and connected it. That's when I got the error with "Failed to start discovery."

2022-11-03 21:07:41 ERR [plejd-ble] Failed to start discovery. Operation already in progress
DBusError: Operation already in progress
    at _methodReturnHandlers.<computed> (/plejd/node_modules/dbus-next/lib/bus.js:343:27)
    at handleMessage (/plejd/node_modules/dbus-next/lib/bus.js:101:11)
    at EventEmitter.<anonymous> (/plejd/node_modules/dbus-next/lib/bus.js:151:9)
    at EventEmitter.emit (events.js:314:20)
    at /plejd/node_modules/dbus-next/lib/connection.js:116:14
    at Socket.<anonymous> (/plejd/node_modules/dbus-next/lib/message.js:63:9)
    at Socket.emit (events.js:314:20)
    at emitReadable_ (_stream_readable.js:557:12)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)

I managed to turn off the integrated BT controller, as suggested, and now Plejd finds my devices. I added 3 buttons for 3 scenes in HA and got this respons in the Plejd log:

2022-11-03 21:07:12 INF [device-comm] Plejd got turn on command for Vitrinskåp  (EC1E7A908BEC_1), brightness 255
2022-11-03 21:07:12 INF [device-comm] Plejd got turn on command for Diskho belysning (DC165267C0A5_0), brightness 255
2022-11-03 21:07:12 INF [device-comm] Plejd got turn on command for Fönster 2st (D255ACA926E0_0), brightness 255
2022-11-03 21:07:12 INF [device-comm] Plejd got turn on command for Köksbord (FBE7E0827CD0_0), brightness 255
2022-11-03 21:07:12 INF [device-comm] Plejd got turn on command for Soffbord belysning tak (ED5A50256C77_0), 

This LOOKS good in the log, but there's nothing happening with the lights. And I still get the same error as stated above. It feels like HA and the BT proxy is't communicating correctly. But I'm not good enough at troubleshooting this error.

Would be nice to hear if someone else has managed to get a BT proxy (ESP32) working, and also HOW.

jompa68 commented 1 year ago

I run this now and it is working with bluetooth proxies

https://github.com/thomasloven/hass_plejd

victorcarl commented 1 year ago

I run this now and it is working with bluetooth proxies

https://github.com/thomasloven/hass_plejd

THANK YOU! Tried it and it works! Not 100%, but close enough. Some of my scenes are missing or not available.