esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
290 stars 34 forks source link

ble_client sensor keep connecting after disconnect even huge update_interval #2220

Open myhomeiot opened 3 years ago

myhomeiot commented 3 years ago

Operating environment/Installation (Hass.io/Docker/pip/etc.): Ubuntu 20.04, esphome installed as Home Assistant addon.

ESP (ESP32/ESP8266, Board/Sonoff): ESP32, esp32dev

ESPHome version (latest production, beta, dev branch) 1.19.4

Affected component: ble_client sensor https://esphome.io/components/sensor/ble_client.html

Description of problem: ble_client sensor keep connecting after disconnect even huge update_interval, this drain the battery of device, I expect that sensor will connect according update_interval

Problem-relevant YAML-configuration entries:


esp32_ble_tracker:

ble_client:
  - mac_address: !secret mi_band_mac
    id: ble_client_mi_band

sensor:
  - platform: template
    id: sensor_mi_band
    name: Mi Band Battery
    device_class: battery
    unit_of_measurement: '%'
    state_class: measurement
    accuracy_decimals: 0

  - platform: ble_client
    id: ble_client_mi_band_data
    internal: true
    ble_client_id: ble_client_mi_band
    service_uuid: FEE0
    characteristic_uuid: 00000006-0000-3512-2118-0009AF100700
    notify: false
    update_interval: 1h
    lambda: |-
      id(sensor_mi_band).publish_state(x[1]);
      return 0;

Logs (if applicable):

[19:12:04][D][ble_client:045]: Found device at MAC address [DA:51:XX:XX:XX:XX]
[19:12:04][I][ble_client:083]: Attempting BLE connection to da:51:xx:xx:xx:xx
[19:12:05][I][ble_sensor:033]: [ble_client_mi_band_data] Connected successfully!
...
[19:13:05][W][ble_sensor:039]: [ble_client_mi_band_data] Disconnected!
[19:13:31][D][ble_client:045]: Found device at MAC address [DA:51:XX:XX:XX:XX]
[19:13:31][I][ble_client:083]: Attempting BLE connection to da:51:xx:xx:xx:xx
[19:13:32][I][ble_sensor:033]: [ble_client_mi_band_data] Connected successfully!

Additional information and things you've tried: I tried to change notify and update_interval

probot-esphome[bot] commented 3 years ago

ble_client source ble_client issues ble_client recent changes (message by IssueLinks)

randysnel commented 3 years ago

I can confirm the same behaviour as well when connecting to a switchbot curtain as 'server'.

myhomeiot commented 3 years ago

I'm not sure that this behavior can be fixed soon, meanwhile I made component which will solves this problem. If anybody interested, the component can be found here.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

randysnel commented 2 years ago

I'm not sure that this behavior can be fixed soon, meanwhile I made component which will solves this problem. If anybody interested, the component can be found here.

can't you issue a pull request?

myhomeiot commented 2 years ago

can't you issue a pull request?

Unfortunately no, my component based on rewrites ble_client and can't work with regular ble_client simultaneously. From ESPHome version 2021.10 my component stops working because lot of changes in ESPHome BLE which I will try to fix when 2021.11 will be released.

robloh commented 2 years ago

@myhomeiot did you ever get this merged? Thanks!

myhomeiot commented 2 years ago

@robloh No because it's out of the scope of regular BLE Client, if you want to have this functionality, you can use my component, some examples you can find here.

My component can co-exists with regular BLE Client, just take into account that current platform limit it's three BLE Client's and my component (MyHomeIOT BLE Host) take one slot but can work with many MyHomeIOT BLE Client's simultaneously, so if you have for example 5 MiFlora's you can read battery information without any problems.

BTW You can also have this functionality using regular BLE Client if you enable/disable it using BLE Client Switch but in this case you should remember about platform limitation of three BLE Client's.