home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.75k stars 30k forks source link

Errors with bluetooth_le_tracker and non-working Mi Flora #23967

Closed Spirituss closed 4 years ago

Spirituss commented 5 years ago

Home Assistant release with the issue:

HA 0.93

Last working Home Assistant release (if known): ~0.86 (?)

Operating environment (Hass.io/Docker/Windows/etc.):

Home Assistant, Rasprberry

Component/platform:

bluetooth_le_tracker

Description of problem: Have BLE errors in log when activates BLE device_tracker. Mi Flora stops working (!!), it is Unavailable most of the time.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

device_tracker: # Device trackers
  - platform: bluetooth_le_tracker
    interval_seconds: 150
sensor:
  - platform: miflora 
    name: MiFlora
    mac: !secret miflora_mac
    force_update: true
    median: 1
    monitored_conditions:
      - light
      - battery
      - temperature

Traceback (if applicable):

2019-05-18 18:48:32 ERROR (Thread-2) [pygatt.backends.gatttool.gatttool] BLE adapter requires reset after a scan as root- call adapter.reset()
2019-05-18 18:48:32 ERROR (Recorder) [homeassistant.core] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 166, in read_nonblocking
    s = os.read(self.child_fd, size)
OSError: [Errno 5] Input/output error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 111, in expect_loop
    incoming = spawn.read_nonblocking(spawn.maxread, timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/pty_spawn.py", line 459, in read_nonblocking
    incoming = super(spawn, self).read_nonblocking(size)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 171, in read_nonblocking
    raise EOF('End Of File (EOF). Exception style platform.')
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/pygatt/backends/gatttool/gatttool.py", line 341, in scan
    scan.expect('foooooo', timeout=timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 341, in expect
    timeout, searchwindowsize, async_)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/spawnbase.py", line 369, in expect_list
    return exp.expect_loop(timeout)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 117, in expect_loop
    return self.eof(e)
  File "/srv/homeassistant/lib/python3.5/site-packages/pexpect/expect.py", line 63, in eof
    raise EOF(msg)
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
<pexpect.pty_spawn.spawn object at 0x635dcd30>
command: /usr/bin/hcitool
args: ['/usr/bin/hcitool', '-i', 'hci0', 'lescan']
buffer (last 100 chars): b''
before (last 100 chars): b'Set scan parameters failed: Input/output error\r\n'
after: <class 'pexpect.exceptions.EOF'>
match: None
match_index: None
exitstatus: 1
flag_eof: True
pid: 31405
child_fd: 50
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile(b'foooooo')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/bluetooth_le_tracker/device_tracker.py", line 104, in update_ble
    devs = discover_ble_devices()
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/components/bluetooth_le_tracker/device_tracker.py", line 66, in discover_ble_devices
    devs = adapter.scan()
  File "/srv/homeassistant/lib/python3.5/site-packages/pygatt/backends/gatttool/gatttool.py", line 352, in scan
    raise BLEError(message)
pygatt.exceptions.BLEError: BLE adapter requires reset after a scan as root- call adapter.reset()

Additional information: BLE tracking was installed according to official manual: Bluetooth LE Tracker

Spirituss commented 5 years ago

Any ideas re. the issue? I still can't use Mi Flora via HA integration.

ahd71 commented 5 years ago

I have the same, or a very similar, issue and get almost the same error (see below)

Some observations:

My log:

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pexpect/spawnbase.py", line 166, in read_nonblocking
    s = os.read(self.child_fd, size)
OSError: [Errno 5] I/O error
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pexpect/expect.py", line 111, in expect_loop
    incoming = spawn.read_nonblocking(spawn.maxread, timeout)
  File "/usr/local/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 485, in read_nonblocking
    return super(spawn, self).read_nonblocking(size)
  File "/usr/local/lib/python3.7/site-packages/pexpect/spawnbase.py", line 171, in read_nonblocking
    raise EOF('End Of File (EOF). Exception style platform.')
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 341, in scan
    scan.expect('foooooo', timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/pexpect/spawnbase.py", line 341, in expect
    timeout, searchwindowsize, async_)
  File "/usr/local/lib/python3.7/site-packages/pexpect/spawnbase.py", line 369, in expect_list
    return exp.expect_loop(timeout)
  File "/usr/local/lib/python3.7/site-packages/pexpect/expect.py", line 117, in expect_loop
    return self.eof(e)
  File "/usr/local/lib/python3.7/site-packages/pexpect/expect.py", line 63, in eof
    raise EOF(msg)
pexpect.exceptions.EOF: End Of File (EOF). Exception style platform.
<pexpect.pty_spawn.spawn object at 0x7f757f11a1d0>
command: /usr/bin/hcitool
args: ['/usr/bin/hcitool', '-i', 'hci0', 'lescan']
buffer (last 100 chars): b''
after: <class 'pexpect.exceptions.EOF'>
match: None
match_index: None
exitstatus: None
flag_eof: True
pid: 1921
child_fd: 60
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
searcher: searcher_re:
    0: re.compile(b'foooooo')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_le_tracker/device_tracker.py", line 110, in update_ble
    devs = discover_ble_devices()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth_le_tracker/device_tracker.py", line 69, in discover_ble_devices
    devs = adapter.scan()
  File "/usr/local/lib/python3.7/site-packages/pygatt/backends/gatttool/gatttool.py", line 352, in scan
    raise BLEError(message)
pygatt.exceptions.BLEError: Unexpected error when scanning:
thawizard commented 5 years ago

Do you have MiFlora listed in known_devices.yaml? I'd try to mark MiFlora to "track=false" or even better remove it from straight from the list.

I've had similar problems with BLE, but it seems to work after I removed every single BLE device from the knowndevices list. (This is when you will get the warning : No BLE devices to track) and then I only added specific BLE devices (Mi Band, etc). I don't get BLE entities populated in known_devices anymore for whatever reason, but I don't mind that.

It seems to me, that the components are trying to scan each on their own to the same BLE address, so when device_tracker is trying to access a MiFlora-running scan (or vice-versa), it goes sideways. Same thing goes to the MiTemp component

Spirituss commented 5 years ago

@thawizard May be it works with Mi Flora since it has own platform component where the MAC can be specified, but I have the same issue also with BLE beacon (I use NUT Tracker). For it I can't set track=false because in this case platform: bluetooth_le_tracker doesn't know my device.

As a possible solution, I propose to implement additional parameter for platform: bluetooth_le_tracker such as "hosts" for platform: nmap_tracker or platform: ping.

Spirituss commented 5 years ago

Guys, is there any news on the issue?

stale[bot] commented 4 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

WhimsySpoon commented 4 years ago

It's still an issue.

Megachip commented 4 years ago

Same issue here … is miflora and bluetooth_le_tracker incompatible?

track: false did not solve the issue.

Looks like #16698 is also related to this

2020-03-24 21:08:23 ERROR (SyncWorker_6) [pygatt.backends.gatttool.gatttool] Unexpected error when scanning: LE Scan ...
C4:7C:8D:ZZ:ZZ:ZZ (unknown)
C4:7C:8D:ZZ:ZZ:ZZ Dial TEST
Disable scan failed: I/O error

2020-03-24 21:08:23 ERROR (SyncWorker_6) [homeassistant.components.bluetooth_le_tracker.device_tracker] Error during Bluetooth LE scan: Unexpected error when scanning: LE Scan ...
C4:7C:8D:ZZ:ZZ:ZZ (unknown)
C4:7C:8D:ZZ:ZZ:ZZ Dial TEST
Disable scan failed: I/O error

2020-03-24 21:09:41 ERROR (SyncWorker_17) [pygatt.backends.gatttool.gatttool] Unexpected error when scanning: LE Scan ...
0A:6A:A5:  (unknown)
63:C5:46:XX:XX:XX (unknown)
63:C5:46:XX:XX:XX (unknown)
75:3A:CA:GG:GG:GG (unknown)
75:3A:CA:GG:GG:GG (unknown)
4A:7A:D5  (unknown)
C4:7C:8D:YY:YY:YY (unknown)
Disable scan failed: I/O error

2020-03-24 21:09:41 ERROR (SyncWorker_17) [homeassistant.components.bluetooth_le_tracker.device_tracker] Error during Bluetooth LE scan: Unexpected error when scanning: LE Scan ...
0A:6A:A5:  (unknown)
63:C5:46:XX:XX:XX (unknown)
63:C5:46:XX:XX:XX (unknown)
75:3A:CA:GG:GG:GG (unknown)
75:3A:CA:GG:GG:GG (unknown)
4A:7A:D5:  (unknown)
C4:7C:8D:YY:YY:YY (unknown)
Disable scan failed: I/O error

2020-03-24 21:10:19 ERROR (SyncWorker_17) [pygatt.backends.gatttool.gatttool] Unexpected error when scanning: LE Scan ...
...
63:C5:46:XX:XX:XX (unknown)
63:C5:46:XX:XX:XX (unknown)
C4:7C:8D:YY:YY:YY (unknown)
C4:7C:8D:YY:YY:YY Flower care
Disable scan failed: I/O error

2020-03-24 21:10:19 ERROR (SyncWorker_17) [homeassistant.components.bluetooth_le_tracker.device_tracker] Error during Bluetooth LE scan: Unexpected error when scanning: LE Scan ...
...
63:C5:46:XX:XX:XX(unknown)
63:C5:46:XX:XX:XX (unknown)
C4:7C:8D:YY:YY:YY (unknown)
C4:7C:8D:YY:YY:YY Flower care
Disable scan failed: I/O error
Megachip commented 4 years ago

@danielhiversen @ChristianKuehnel