klali / ha-plejd

Plejd component for Home Assistant
Apache License 2.0
69 stars 16 forks source link

Homeassistant will not connect to Plejd #22

Closed iCarl closed 4 years ago

iCarl commented 4 years ago

I've tried three separate fresh installs in order to get this working. Fresh installs on both Raspbian and Homeassistant in venv.

I get error


Nov 03 15:37:46 raspberrypi hass[1540]: 2019-11-03 15:37:46 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Nov 03 15:37:46 raspberrypi hass[1540]: Traceback (most recent call last):
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
Nov 03 15:37:46 raspberrypi hass[1540]:     result = self.fn(*self.args, **self.kwargs)
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 322, in _start_plejd
Nov 03 15:37:46 raspberrypi hass[1540]:     connect(plejdinfo)
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 140, in connect
Nov 03 15:37:46 raspberrypi hass[1540]:     devs = sorted(list(scanner.scan(1)), key=lambda d: d.rssi)[::-1]
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/srv/homeassistant/lib/python3.7/site-packages/bluepy/btle.py", line 852, in scan
Nov 03 15:37:46 raspberrypi hass[1540]:     self.start(passive=passive)
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/srv/homeassistant/lib/python3.7/site-packages/bluepy/btle.py", line 790, in start
Nov 03 15:37:46 raspberrypi hass[1540]:     self._mgmtCmd("le on")
Nov 03 15:37:46 raspberrypi hass[1540]:   File "/srv/homeassistant/lib/python3.7/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
Nov 03 15:37:46 raspberrypi hass[1540]:     raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
Nov 03 15:37:46 raspberrypi hass[1540]: bluepy.btle.BTLEManagementError: Failed to execute management command 'le on' (code: 17, error: Invalid Index)

I'm now running version 0.101.2 through virtual environment. This used to work a while ago, but stopped, hence the reinstall. What could be causing this?

klali commented 4 years ago

I'm getting similar issues on a new install.

what does running "hcitool dev" show for you? for me it doesn't detect any bluetooth devices on the raspberry pi at all. I'll investigate more.

klali commented 4 years ago

So.

I had issues with running bionic and not raspbian on this system, that leads to some issues: there is a bogus hci0, get rid of it: $ rmmod btsdio

then attach the correct device: $ hciattach /dev/ttyAMA0 bcm43xx 921600

after this it works fine.

iCarl commented 4 years ago

hcitool dev outputs:

Devices:
        hci0    B8:27:EB:C0:22:DD

sudo rmmod btsdiooutputs

rmmod: ERROR: Module btsdio is not currently loaded

hciattach /dev/ttyAMA0 bcm43xx 921600 outputs:

bcm43xx_init
Failed to write reset command
Can't initialize device: Success
klali commented 4 years ago

You have a different error than I had then, your bluetooth module seems to be found correctly.

Does hcitool lescan work for you?

iCarl commented 4 years ago

It works, and detects the Plejd as "P mesh"

klali commented 4 years ago

I've just merged a partial re-write using dbus instead of bluepy, this works for me and might fix this. Please re-open if this is still an issue.