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
73.71k stars 30.83k forks source link

Slow response times after enabling BLE tracker #4442

Closed lawrencecraft closed 6 years ago

lawrencecraft commented 8 years ago

Home Assistant release (hass --version): 0.32.4

Python release (python3 --version): 3.4.2

Component/platform: Bluetooth Low-Energy

Description of problem: Enabling the Bluetooth LE tracker on HASS running on a Raspberry Pi 3 significantly slows the UI. Ordinarily light switching is near-instantaneous, but after enabling BLE I get delays of 2 to 10 seconds.

Note that it does seem to work: I can see my BLE device on the UI.

Expected: No significant performance impact.

abmantis commented 6 years ago

@usul27 It is not normal. HA should not lock.

fanaticDavid commented 6 years ago

@usul27 And this issue also occurs when you use a wired connection, even if you completely disable the wi-fi connection on a Raspberry Pi.

gthieleb commented 6 years ago

I have this issue also when not using the BLE device tracker but when trying to use a 3rd party library to connect to a BLE thermostat [1].

When using this library inside a sensor module:

class CometBlueSensor(Entity):
    """Representation of a Sensor."""

    def __init__(self):
    """Initialize the sensor."""
    self._state = None

    @property
    def name(self):
    """Return the name of the sensor."""
    return 'Comet Blue'

    @property
    def state(self):
    """Return the state of the sensor."""
    return self._state

    @property
    def unit_of_measurement(self):
    """Return the unit of measurement."""
    return TEMP_CELSIUS

    def update(self):
    """Fetch new state data for the sensor.

    This is the only method that should fetch new data for Home Assistant.
    """

    data = {}

    with cometblue.device.CometBlue('FF:FF:FF:FF:FF', pin=1234) as dev:

        _LOGGER.info("Get data from cometblue device...")
        params = dev.SUPPORTED_VALUES['temperatures']
        data = dev._read_value(params['uuid'],
                            params['decode'],
                            params['read_requires_pin'])

    _LOGGER.info(
            "Data {data} received from cometblue device..." \
            .format(data=data)
    )

    self._state = data['current_temp']

18-01-02 17:36:53 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:37:15 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:37:37 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:38:00 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:38:22 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:38:46 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting 18-01-02 17:39:09 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting

When using this library within a AppDaemon app:

2018-01-02 23:04:29.313475 INFO Connected to Home Assistant 0.61.0.dev0 2018-01-02 23:04:35.773139 WARNING Scheduler clock skew detected - delta = 4.773107051849365 - resetting 2018-01-02 23:06:38.826483 WARNING Scheduler clock skew detected - delta = 8.053345918655396 - resetting 2018-01-02 23:08:37.377797 WARNING Scheduler clock skew detected - delta = 6.551317930221558 - resetting 2018-01-02 23:10:36.184562 WARNING Scheduler clock skew detected - delta = 5.806763172149658 - resetting 2018-01-02 23:12:36.441549 WARNING Scheduler clock skew detected - delta = 6.256987810134888 - resetting 2018-01-02 23:14:37.798728 WARNING Scheduler clock skew detected - delta = 7.357161998748779 - resetting 2018-01-02 23:16:35.904803 WARNING Scheduler clock skew detected - delta = 5.106091022491455 - resetting 2018-01-02 23:18:34.509723 WARNING Scheduler clock skew detected - delta = 3.604917049407959 - resetting

[1] https://github.com/im-0/cometblue

balloobbot commented 6 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 :+1:

Eina61 commented 6 years ago

I just updated to 0.66 (Hassbian) and as usual BLE Tracker won't even install.

Front page indications are:

Invalid Config device_tracker.bluetooth_le_tracker

Log files are:

2018-03-31 01:36:25 ERROR (Thread-9) [homeassistant.util.package] Unable to install package gattlib==0.20150805: Command "/srv/homeassistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-e7h0vwdh/gattlib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-udbmtkuo-record/install-record.txt --single-version-externally-managed --compile --install-headers /srv/homeassistant/include/site/python3.5/gattlib" failed with error code 1 in /tmp/pip-build-e7h0vwdh/gattlib/

2018-03-31 01:36:25 ERROR (MainThread) [homeassistant.requirements] Not initializing device_tracker.bluetooth_le_tracker because could not install requirement gattlib==0.20150805

2018-03-31 01:36:25 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform device_tracker.bluetooth_le_tracker: Could not install all requirements.
quenbert commented 6 years ago

Hello @Eina61 , the following should manually install gattlib, and fix your troubles on Hassbian 0.66(.1)

First, the line below is a ugly hack to remove the error message mentionned here: https://bitbucket.org/OscarAcena/pygattlib/issues/41/ld-cannot-find-lboost_python-py34

$ sudo ln -s /usr/lib/arm-linux-gnueabihf/libboost_python-py35.so /usr/lib/arm-linux-gnueabihf/libboost_python-py34.so 

Then, manual installation of gattlib in homeassistant environment:

$ sudo systemctl stop home-assistant@homeassistant.service
$ sudo su -s /bin/bash homeassistant
$ source /srv/homeassistant/bin/activate
$ pip3 install gattlib
$ exit
$ sudo systemctl start home-assistant@homeassistant.service
Eina61 commented 6 years ago

That has definitely improved things. The previous errors are all gone & I have no card in the main screen to tell me of failure. I now get the following 2 warnings in the log file - in this order.

2018-04-10 09:11:51 WARNING (Thread-19) [homeassistant.components.device_tracker.bluetooth_le_tracker] No Bluetooth LE devices to track!
2018-04-10 09:11:51 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform bluetooth_le_tracker

Strange that it first says nothing to track and then only later says it has an error setting up the ble tracker. But that is definitely a step forward so thank you very much for this. I will bring some more ble beacons home & do some more testing to see if I can get further.

I can see a few hits when I Google search on that last error so I have more I can do myself. I do NOT have the "Set scan parameters failed (are you root?)" message appearing anywhere.

braddo99 commented 6 years ago

pygatt vs gattlib and support for bluetooth LE: I was excited to see in HA v70 support for a newer version of pygatt, was wondering if it could impact the bluetooth LE limitation HA running on non-raspbian systems. I have seen pygatt mentioned as an alternative to gattlib (but it may also depend on it, not sure) so wondered if this might be a step forward in supporting bluetooth low energy beacons etc.

renekliment commented 6 years ago

Unfortunately I don't know enough about Bluetooth (LE), nor Python async to tackle this issue, but I was thinking about writing a small standalone script to run as a service, that would scan for devices and report to HA via MQTT.

Do any of you guys have this and if that's the case don't mind sharing so I don't have to duplicate the effort needlessly?

idfxken commented 6 years ago

On the Ha forum there's this: https://community.home-assistant.io/t/ble-custom-component/48355 As a direct replacement for the official component.

Which is working perfectly for a few months now @ my home.

michaelarz commented 6 years ago

Hi! I use room-assistant on separate Pi (my HA lives inside VM) for a few month to track ble beacons https://github.com/mKeRix/room-assistant So far no problems.

idfxken commented 6 years ago

There should be a fix now. https://github.com/home-assistant/home-assistant/pull/16592