klali / ha-plejd

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

No devices found #32

Closed mist0706 closed 4 years ago

mist0706 commented 4 years ago

So after the dbus up and working i still am not able to find any devices

2020-05-05 15:08:02 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for plejd 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-05-05 15:08:02 INFO (MainThread) [homeassistant.components.light] Setting up light.plejd
2020-05-05 15:08:04 DEBUG (MainThread) [custom_components.plejd.light] Discovered bluetooth adapter /org/bluez/hci0
2020-05-05 15:08:06 WARNING (MainThread) [custom_components.plejd.light] No plejd devices found
2020-05-05 15:08:06 WARNING (MainThread) [homeassistant.components.light] Platform plejd not ready yet. Retrying in 30 seconds.

There are no apparent error messages but "No plejd devices found".

Running hcitool lescan works SOMETIMES. For some reason the interface seems to not work, i don't understand why:

root@lampberry:~# hcitool dev
Devices:
        hci0    C4:D9:87:37:60:71
root@lampberry:~# hciconfig
hci0:   Type: BR/EDR  Bus: USB
        BD Address: C4:D9:87:37:60:71  ACL MTU: 310:10  SCO MTU: 64:8
        UP RUNNING
        RX bytes:18095661 acl:0 sco:0 events:462779 errors:0
        TX bytes:30380 acl:0 sco:0 commands:3554 errors:0

root@lampberry:~# hcitool lescan
Set scan parameters failed: Input/output error
root@lampberry:~# hciconfig hci0 down
root@lampberry:~# hciconfig hci0 up
root@lampberry:~# hcitool lescan
LE Scan ...
43:CD:4A:3F:72:82 (unknown)
43:CD:4A:3F:72:82 (unknown)
C8:A6:2D:3A:25:6B P mesh
C8:A6:2D:3A:25:6B (unknown)
63:73:36:6D:74:E7 (unknown)
63:73:36:6D:74:E7 (unknown)
F1:BE:89:F0:DD:8F P mesh
63:73:36:6D:74:E7 (unknown)
klali commented 4 years ago

It's possible that the bluetooth hardware (and/or software) gets into sad states after alot of fiddling (especially with the raw hci tools), can you try a reboot and see if it behaves better?

mist0706 commented 4 years ago

Unfortunately the same result after a reboot, however the bluetooth adapter seems to always respond to hcitool scan now which is an improvement


2020-05-06 06:14:51 INFO (MainThread) [homeassistant.components.light] Setting up light.plejd
2020-05-06 06:14:51 DEBUG (MainThread) [custom_components.plejd.light] Discovered bluetooth adapter /org/bluez/hci0
2020-05-06 06:14:53 WARNING (MainThread) [custom_components.plejd.light] No plejd devices found
2020-05-06 06:14:53 WARNING (MainThread) [homeassistant.components.light] Platform plejd not ready yet. Retrying in 180 seconds.
klali commented 4 years ago

Do you get anything in syslog or dmesg about bluetooth when this happens? What version of bluez are you running with? What hardware is this with?

mist0706 commented 4 years ago

bluez is already the newest version (5.37-0ubuntu5.3). (This is from the host OS which i assume you're interested in?)

The hardware is a intel nuc 54250wyk

Nothing in particular in either the syslog nor dmesg.

klali commented 4 years ago

5.37 is quite old, I'm running 5.48 (from ubuntu 18.04) (yes, host is what matters).

It should be possible to run bluetoothd with debugging enabled (--debug), I don't know if that could possible shed some light on what's happening.

mist0706 commented 4 years ago

I'm running ubuntu 16 lts, i'll upgrade to 18 since it has to be done anyway. Then i'll update the package to see if that fixes it, if not i'll get some debug logs from bluetoothd.

mist0706 commented 4 years ago

After an upgrade to ubuntu 18 it started working!

2020-05-07 14:40:42 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:40:42'
2020-05-07 14:40:42 DEBUG (MainThread) [custom_components.plejd.light] No match for device '27' (b'270110009800ffff00')
2020-05-07 14:40:43 DEBUG (MainThread) [custom_components.plejd.light] No match for device '19' (b'190110009801131300')
2020-05-07 14:40:44 DEBUG (MainThread) [custom_components.plejd.light] No match for device '28' (b'280110009800ffff00')
2020-05-07 14:40:58 DEBUG (MainThread) [custom_components.plejd.light] No match for device '17' (b'170110009800000000')
2020-05-07 14:41:12 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:41:18'
2020-05-07 14:41:44 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:41:51'
2020-05-07 14:42:03 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:42:10'
2020-05-07 14:42:16 DEBUG (MainThread) [custom_components.plejd.light] No match for device '2d' (b'2d0110009801000000')
2020-05-07 14:42:23 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:42:30'
2020-05-07 14:42:32 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:42:38'
2020-05-07 14:43:38 DEBUG (MainThread) [custom_components.plejd.light] Plejd network reports time as '2020-05-07 15:43:44'

Before we close this. Is there a simple way of translating which number is which device name? Otherwise i'll write a python script to try and figure that out and generate a yaml for homeassistant

mist0706 commented 4 years ago

So i hacked something together but it doesn't take into consideration cron dimmers properly. If anyone has a clue you can ping me. This can be marked as closed.

#!/usr/bin/env python3

import json

_json = json.loads(open('site.json').read())
adresses = {}
output = _json['PlejdMesh']['outputAdresses']
output.pop('$type')
for device_id in output:
    adresses[output[device_id].get('0')] = device_id
    adresses[output[device_id].get('1')] = device_id

final_data = {}
device_info = _json['DeviceInfos']['$values']
for device in device_info:
    for device_id in adresses:
        if device['DeviceID'] == adresses[device_id]:
            print("%s:\n  name: %s" % (device_id, device['Title']))
root@mango:/home/mist# ./devicenames.py
11:
  name: Spotar tak
13:
  name: Spotar tak hall
15:
  name: Spot tak wc/d
17:
   ....
klali commented 4 years ago

Awesome, glad to hear that it works.