klali / ha-plejd

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

Rejected at scanend #16

Closed fabianpk closed 4 years ago

fabianpk commented 4 years ago

I am running Home Assistant on a Ubuntu Linux machine. Home assistant is installed using virtual environment. I also have three Plejd dimmers installed, which works when I connect to them with the iOS app. I extracted the cryptokeys and removed the "" before and after the key and added it to my configuration.yaml.

I get this error message when I added the debug flag to the logging. The final message "Rejected" sounds to me like the cryptokey is wrong, I added my configuration.yaml at the bottom. The addresses in the first few lines when it reports "failed connecting" does match the Plejd dimmers.

2019-08-27 17:37:36 DEBUG (SyncWorker_10) [custom_components.plejd.light] Starting plejd connection
2019-08-27 17:37:37 WARNING (SyncWorker_10) [custom_components.plejd.light] failed connecting to device 'c8:e4:1a:d3:de:3c' : 'Failed to connect to peripheral c8:e4:1a:d
3:de:3c, addr type: random'
2019-08-27 17:37:37 WARNING (SyncWorker_10) [custom_components.plejd.light] failed connecting to device 'fe:dc:4b:78:c2:16' : 'Failed to connect to peripheral fe:dc:4b:7
8:c2:16, addr type: random'
2019-08-27 17:37:37 WARNING (SyncWorker_10) [custom_components.plejd.light] no device found on iteration 1
2019-08-27 17:37:37 ERROR (MainThread) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 311, in _start_plejd
    connect(plejdinfo)
  File "/home/homeassistant/.homeassistant/custom_components/plejd/light.py", line 133, in connect
    devs = sorted(list(scanner.scan(1)), key=lambda d: d.rssi)[::-1]
  File "/srv/homeassistant/lib/python3.6/site-packages/bluepy/btle.py", line 852, in scan
    self.start(passive=passive)
  File "/srv/homeassistant/lib/python3.6/site-packages/bluepy/btle.py", line 797, in start
    self._mgmtCmd(self._cmd()+"end")
  File "/srv/homeassistant/lib/python3.6/site-packages/bluepy/btle.py", line 312, in _mgmtCmd
    raise BTLEManagementError("Failed to execute management command '%s'" % (cmd), rsp)
bluepy.btle.BTLEManagementError: Failed to execute management command 'scanend' (code: 11, error: Rejected)

configuration.yaml extract:

light:

  • platform: plejd crypto_key: !secret plejdsec devices: 11: name: trappa1 12: name: trappa2 14: name: trappa3

I extracted the cryptokeys through ibackup viewer and did like the readme:

cat site.json | jq '.PlejdMesh.CryptoKey' | sed 's/-//g'

parse error: Invalid numeric literal at EOF at line 1, column 18688
"5FB3B****************************19CA4"

The above string is what I put in my secrets.yaml but without the "". I tried with the "" as well just to be sure but that didn't work either.

Any help would be much appreciated.

klali commented 4 years ago

Does it behave exactly like that on every try?

The 'scanend' failure is something internal to bluepy failing as it tries to stop the scanning and start over, not related to plejd at all. The real error is that it fails to connect to both plejds it finds, I think it will fail to connect if you have an active connection from a phone at the same time, maybe try killing the plejd app?

fabianpk commented 4 years ago

That solved it, thanks. Killing the plejd app and disabling bluetooth on my phone (just to be 100 % sure), and then rebooted Home assistant solved it. I do get some strange things in my log. Just FYI, it works to turn off and on.

2019-09-01 23:04:53 DEBUG (SyncWorker_13) [custom_components.plejd.light] turning off trappa2(0c)
2019-09-01 23:04:54 DEBUG (SyncWorker_15) [custom_components.plejd.light] trappa2(0c) turned False with brightness ffff
2019-09-01 23:04:57 DEBUG (SyncWorker_10) [custom_components.plejd.light] turning on trappa2(0c) with brigtness 00
2019-09-01 23:05:00 DEBUG (SyncWorker_13) [custom_components.plejd.light] trappa2(0c) turned True with brightness ffff
2019-09-01 23:05:47 DEBUG (SyncWorker_13) [custom_components.plejd.light] no match for device '1' (b'010110001bc8406c5d01')
2019-09-01 23:05:52 DEBUG (Thread-10) [custom_components.plejd.light] trappa1(0b) turned True with brightness ffff
2019-09-01 23:06:16 DEBUG (SyncWorker_10) [custom_components.plejd.light] trappa2(0c) turned True with brightness ffff
2019-09-01 23:06:18 DEBUG (SyncWorker_13) [custom_components.plejd.light] trappa3(0e) turned True with brightness 0000
2019-09-01 23:06:24 DEBUG (Thread-10) [custom_components.plejd.light] no match for device '1' (b'010110001bed406c5d01')

After 23:05:00 I didn't do anything. Could this be due to the fact that I have three switches which I associated in Plejd to control one light bulb (which is in a staircase)? Only one of them is actually connected to the lamp, so I'm assuming some inter-device communication is necessary.

Thanks alot anyway!

klali commented 4 years ago

Yeah, the plejds have some traffic in communicating the current state. Great that it works better now!