dknowles2 / ha-pitboss

Home Assistant Custom Integration for PitBoss smokers and grills
MIT License
32 stars 4 forks source link

Not working with BLE Proxy ESP32 boards #11

Closed TTLucian closed 10 months ago

TTLucian commented 1 year ago

System Health details

System Information

version core-2023.5.4
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.10.11
os_name Linux
os_version 6.1.29
arch x86_64
timezone Europe/Bucharest
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 4674 Installed Version | 1.32.1 Stage | running Available Repositories | 1297 Downloaded Repositories | 51
AccuWeather can_reach_server | ok -- | -- remaining_requests | 46
Airly can_reach_server | ok -- | -- requests_remaining | 36 requests_per_day | 100
Home Assistant Cloud logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | ok
Home Assistant Supervisor host_os | Home Assistant OS 10.2 -- | -- update_channel | stable supervisor_version | supervisor-2023.04.1 agent_version | 1.5.1 docker_version | 23.0.6 disk_total | 30.8 GB disk_used | 15.7 GB healthy | true supported | true board | ova supervisor_api | ok version_api | ok installed_addons | Mosquitto broker (6.2.1), Samba share (10.0.2), Node-RED (14.2.2), Home Assistant Google Drive Backup (0.110.4), InfluxDB (4.7.0), Grafana (8.3.0), Terminal & SSH (9.7.1), TasmoAdmin (0.24.4), SQLite Web (3.8.0), Zigbee2MQTT (1.31.0-1), ESPHome (2023.5.5)
Dashboards dashboards | 7 -- | -- resources | 33 views | 26 mode | storage
Recorder oldest_recorder_run | May 3, 2023 at 21:36 -- | -- current_recorder_run | June 2, 2023 at 18:50 estimated_db_size | 1095.63 MiB database_engine | sqlite database_version | 3.40.1
Sonoff version | 3.5.1 (122751c) -- | -- cloud_online | 19 / 22 local_online | 17 / 17

Checklist

Describe the issue

ESP32 ble proxy is getting api disconnects and reboots after attempting connection with the grill. I'm not sure if the integration is supposed to work with ble proxy devices or if the fault is in the esp32 device itself. Here are some logs:

INFO ESPHome 2023.5.5
INFO Reading configuration /config/esphome/ble-proxy-front.yaml...
INFO Detected timezone 'Europe/Bucharest'
INFO Starting log output from BLE-Proxy-Front.lh using esphome API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:06:29][I][app:102]: ESPHome version 2023.5.5 compiled on Jun  2 2023, 13:58:53
[19:06:39][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:06:39][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:06:59][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:06:59][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:07:20][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:07:20][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:12:21][I][ota:113]: Boot seems successful, resetting boot loop counter.
[19:12:50][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:12:50][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:13:10][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:13:10][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:13:31][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:13:31][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh
[19:13:51][I][bluetooth_proxy:254]: [0] [77:0B:D5:EF:93:53] Connecting v3 without cache
[19:13:51][I][esp32_ble_client:064]: [0] [77:0B:D5:EF:93:53] 0x01 Attempting BLE connection
WARNING BLE-Proxy-Front.lh: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for BLE-Proxy-Front.lh
WARNING Disconnected from API
INFO Successfully connected to BLE-Proxy-Front.lh

Debug logs

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/pitboss/coordinator.py:58
Integration: PitBoss (documentation, issues)
First occurred: 19:07:40 (1 occurrences)
Last logged: 19:07:40

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 570, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 569, in bluetooth_device_connect
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.10/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.10/site-packages/aioesphomeapi/client.py", line 596, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to 77:0B:D5:EF:93:53 after 20.0s, disconnect timed out: False,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 344, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 272, in connect
    connected = await super().connect(**kwargs)
  File "/usr/local/lib/python3.10/site-packages/bleak/__init__.py", line 531, in connect
    return await self._backend.connect(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
asyncio.exceptions.TimeoutError: Timeout waiting for connect response while connecting to 77:0B:D5:EF:93:53 after 20.0s, disconnect timed out: False,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/pitboss/coordinator.py", line 58, in reset_device
    await self.conn.reset_device(device)
  File "/usr/local/lib/python3.10/site-packages/pytboss/ble.py", line 104, in reset_device
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/pytboss/ble.py", line 72, in connect
    self._ble_client = await bleak_retry_connector.establish_connection(
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 361, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.10/site-packages/bleak_retry_connector/__init__.py", line 310, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError: PBL-013B250 - 77:0B:D5:EF:93:53: Failed to connect: Timeout waiting for connect response while connecting to 77:0B:D5:EF:93:53 after 20.0s, disconnect timed out: False,  after 5.0s
Logger: aioesphomeapi.connection
Source: runner.py:179
First occurred: 18:55:15 (12 occurrences)
Last logged: 19:14:10

ble-proxy-study @ 192.168.1.55: Connection error occurred: [Errno 104] Connection reset by peer
ble-proxy-front @ 192.168.1.56: Connection error occurred: [Errno 104] Connection reset by peer
dknowles2 commented 1 year ago

Do you have active mode enabled on the bluetooth proxy? (See: https://esphome.io/components/bluetooth_proxy.html) The PitBoss client currently requires an active connection to the device.

I haven't tested this with a bluetooth proxy yet. I need to, because my HA instance is too far away from my smoker and doesn't get a strong enough Bluetooth signal. (I've always tested this with my laptop) So it's possible this just flat out doesn't work over the proxy. I think I can make the client library work over passive BLE, but I haven't had time to tinker with that lately.

TTLucian commented 1 year ago

Yes. Active scanning is enabled in all the proxies! Let me know if I can be of any help. My setup includes 1 bluetooth dongle and 5 esp32 ble proxies. I can get the integration to work by unplugging all ble proxies but as soon as I plug one closer to the grill, it stops working. Getting all kinds of errors from the esp32 boards, disconnects and reboots. Proxies were working fine with existing devices (6 switchbot curtains and 4 bots) but the PitBoss grill integration started wreaking havoc! πŸ˜… I have no ideea where to start debugging. I've tried lowering the ram usage on the proxies by lowering the logging level but they keep disconnecting. I've even changed their power supply. I really don't know where to look! I've just got the grill but the official PitBoss app really sucks. Much more can be done with Home Assistant. πŸ˜‰ This is my ble proxy esphome yaml:

substitutions:
  name: "ble-proxy-front"
  upper_devicename: BLE Proxy Front
  hostname: BLE-Proxy-Front.lh
  domain: .lh

esphome:
  name: ${name}
  name_add_mac_suffix: false

esp32:
  board: esp32dev
  framework:
    type: esp-idf

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: $domain
  use_address: $hostname

  ap:
    ssid: $upper_devicename
    password: !secret ap_password

time:
  - platform: homeassistant
    id: homeassistant_time

api:
  encryption:
    key: !secret api_key
logger:
  level: INFO
ota:
  password: !secret web_server_password 

improv_serial:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

button:
- platform: safe_mode
  name: $upper_devicename Safe Mode Boot
  entity_category: diagnostic

- platform: restart
  name:  $upper_devicename Reboot
  entity_category: diagnostic
dknowles2 commented 1 year ago

I just installed esphome on a spare esp32 attached it to my development Home Assistant. The PitBoss integration was able to use the proxy to attach to my fake PitBoss board without any errors.

It's possible my fake PitBoss board isn't set up exactly like the grill. So I'd have to pull out my actual grill to test it, and I probably won't be able to do that this weekend.

TTLucian commented 1 year ago

Can you post yout esphome yaml for the proxy?

dknowles2 commented 1 year ago
substitutions:
  name: esp32-bluetooth-proxy-a48fbc
  friendly_name: Bluetooth Proxy a48fbc

esphome:
  name: ${name}
  name_add_mac_suffix: false
  friendly_name: ${friendly_name}

esp32:
  board: esp32dev

api:
  encryption:
    key: !secret api_key

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

ota:

logger:
  level: INFO
TTLucian commented 1 year ago

Hi. I tested by using your esphome yaml and the connection seems to be stable so far (further testing required). Only difference is you're using the arduino framework instead of esp-idf. Could this be the issue?

dknowles2 commented 1 year ago

That sounds like a likely culprit. The frameworks are probably using different Bluetooth stacks.

I'm sort of surprised the ESP-IDF framework is less stable though, since that's written by the ESP32 developers themselves. Maybe the Arduino code just has more mileage? 🀷🏻

TTLucian commented 1 year ago

The connection has been stable since yesterday, no resets, no api disconnects. So it definitely works only with the arduino framework. According to the esphome website "The [ESP32 Platform] component should be configured to use the esp-idf framework, as the arduino framework uses significantly more memory and performs poorly with the Bluetooth proxy enabled." Well, I guess I'll have to keep one proxy on the arduino framework just for the grill and the others on the esp-idf for now.

dknowles2 commented 1 year ago

When I first tried it out I just did the vanilla install from https://esphome.github.io/bluetooth-proxies/ and it worked. I think that's this config? https://github.com/esphome/bluetooth-proxies/blob/main/esp32-generic.yaml

TTLucian commented 1 year ago

Yes. But now they've changed to:

esp32:
  board: esp32dev
  framework:
    type: esp-idf

The config you posted doesn't specify the framework type so it defaults to arduino if not specified. I think you should put a mention of this in the documentation. You could reflash the board and test it when you have the time. Maybe you can figure out the issue. I have no ideea how to debug this any further. πŸ˜• Anyway, thanks a lot for the integration. I should be able to use it better than the official PitBoss android app (which sucks πŸ˜…)

dknowles2 commented 1 year ago

I'll give it another shot with the esp-idf framework when I get a chance. If it doesn't work I'll add a warning in the docs.

Please file more bugs if you run into other issues! I haven't actually had a chance to try out the integration with my own smoker yet, so I'm sure there's still some rough edges. πŸ˜„

(And the new PitBoss app is much better than the previous one. But that's a low bar.)

srvoets commented 1 year ago

I'll give it another shot with the esp-idf framework when I get a chance. If it doesn't work I'll add a warning in the docs.

Please file more bugs if you run into other issues! I haven't actually had a chance to try out the integration with my own smoker yet, so I'm sure there's still some rough edges. πŸ˜„

(And the new PitBoss app is much better than the previous one. But that's a low bar.)

The enw app is alot better.

However, I am having issues using this integration with bluetooth proxy, I made sure I updated my esphome config to match yours, but its not detecting my austin xl

dknowles2 commented 1 year ago

I just re-flashed my ESP32 with the framework type as esp-idf and it still seems to be working for me. Here's the full YAML config:

esphome:
  name: kitchen-esphome
  friendly_name: Kitchen ESPHome

esp32:
  board: esp32dev
  framework:
    # type: arduino
    type: esp-idf

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:
  encryption:
    key: !secret api_encryption

ota:
    password: !secret ota_password
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Kitchen-Esphome Fallback Hotspot"
    password: "kitchen-esphome"

# NOTE: Only works when framework type is arduino
# captive_portal:

esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

bluetooth_proxy:
  active: true
TTLucian commented 1 year ago

What kind of ESP32 board are you using?

dknowles2 commented 1 year ago

ESP-WROOM-32 (https://a.co/d/0qFHS4y)

I've got a few of these I could try too but I'm pretty sure it's the same chipset. https://a.co/d/cLTFRdR

Maybe it's a distance thing? Maybe it's drawing too much power trying to use a weak signal and crashing the esp32? Once I get my kid to bed I'll try a few experiments to see if I can reproduce.

TTLucian commented 1 year ago

I am using the exact same board. The PitBoss integration doesn't work on the esp-idf framework at all. On the arduino framework it works fine. I have no ideea of what's going on. The board is 3 meters away from the grill but sometimes it connects to another proxy, farther away. I have 13 ble devices (6 switchbot curtains, 4 strip lights and 3 bots and one homewhiz washing machine) and 5 esp proxies. All are working fine. Don't know if they are using active or passive connections. The grill's connection is somewhat stable on the arduino framework (meaning sometimes the integration "gets stuck" it requires a reload). The esp-idf doesn't work at all with this integration. I've flashed all the proxies with the arduino framework. I am using 2 amps power supplies for the proxies.

dknowles2 commented 1 year ago

I repurposed one of my ESPresense ESP32's as an ESPHome bluetooth proxy with the esp-idf framework. I haven't noticed it crash-looping like the initial report here, but I'm not watching it too closely.

Hopefully the fix I just pushed for #13 will help here, as it should help with Bluetooth disconnects. I'm not sure what else I can do--I'm by no means a Bluetooth expert, and I'd prefer to keep it that way. πŸ€•

TTLucian commented 1 year ago

I tried again with esp-idf and it still doesn't work. Again proxy API disconnects and failed connections. It started working again as soon as I reverted to arduino.

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/pitboss/coordinator.py:62
Integration: PitBoss (documentation, issues)
First occurred: 18:26:00 (1 occurrences)
Last logged: 18:26:00

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 570, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 569, in bluetooth_device_connect
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.11/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.11/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 596, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to 75:F2:B1:26:8D:AD after 20.0s, disconnect timed out: False,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 344, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 272, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 531, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
TimeoutError: Timeout waiting for connect response while connecting to 75:F2:B1:26:8D:AD after 20.0s, disconnect timed out: False,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/pitboss/coordinator.py", line 62, in reset_device
    await self.conn.reset_device(device)
  File "/usr/local/lib/python3.11/site-packages/pytboss/ble.py", line 123, in reset_device
    await self.connect()
  File "/usr/local/lib/python3.11/site-packages/pytboss/ble.py", line 86, in connect
    self._ble_client = await bleak_retry_connector.establish_connection(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 361, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 310, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError: PBL-013B250 - 75:F2:B1:26:8D:AD: Failed to connect: Timeout waiting for connect response while connecting to 75:F2:B1:26:8D:AD after 20.0s, disconnect timed out: False,  after 5.0s
Logger: homeassistant.components.esphome.bluetooth.client
Source: components/esphome/bluetooth/client.py:733
Integration: ESPHome (documentation, issues)
First occurred: 18:32:43 (1 occurrences)
Last logged: 18:32:43

BLE Proxy Front [e0:5a:1b:a1:e0:ac]: PBL-013B250 - 6C:7F:1F:16:EF:47: ESPHomeClient bleak client was not properly disconnected before destruction
Logger: homeassistant
Source: components/esphome/bluetooth/client.py:174
First occurred: 18:32:43 (1 occurrences)
Last logged: 18:32:43

Error doing job: Exception in callback ESPHomeClient._async_disconnected_cleanup()
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 198, in _async_disconnected_cleanup
    self._unsubscribe_connection_state()
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 174, in _unsubscribe_connection_state
    self._cancel_connection_state()
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 565, in unsub
    self._connection.remove_message_callback(on_msg, msg_types)
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/connection.py", line 535, in remove_message_callback
    self._message_handlers[msg_type].remove(on_message)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: <class 'api_pb2.BluetoothDeviceConnectionResponse'>
This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/pitboss/coordinator.py:58
Integration: PitBoss (documentation, issues)
First occurred: 18:24:26 (3 occurrences)
Last logged: 18:34:59

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 570, in bluetooth_device_connect
    await event.wait()
  File "/usr/local/lib/python3.11/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 569, in bluetooth_device_connect
    async with async_timeout.timeout(timeout):
  File "/usr/local/lib/python3.11/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.11/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
TimeoutError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 102, in _async_wrap_bluetooth_operation
    return await func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 317, in connect
    await self._client.bluetooth_device_connect(
  File "/usr/local/lib/python3.11/site-packages/aioesphomeapi/client.py", line 596, in bluetooth_device_connect
    raise TimeoutAPIError(
aioesphomeapi.core.TimeoutAPIError: Timeout waiting for connect response while connecting to 6C:7F:1F:16:EF:47 after 20.0s, disconnect timed out: True,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 344, in establish_connection
    await client.connect(
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/wrappers.py", line 272, in connect
    connected = await super().connect(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak/__init__.py", line 531, in connect
    return await self._backend.connect(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/esphome/bluetooth/client.py", line 104, in _async_wrap_bluetooth_operation
    raise asyncio.TimeoutError(str(err)) from err
TimeoutError: Timeout waiting for connect response while connecting to 6C:7F:1F:16:EF:47 after 20.0s, disconnect timed out: True,  after 5.0s

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/pitboss/coordinator.py", line 58, in reset_device
    await self.api.start()
  File "/usr/local/lib/python3.11/site-packages/pytboss/api.py", line 143, in start
    await self._conn.connect()
  File "/usr/local/lib/python3.11/site-packages/pytboss/ble.py", line 86, in connect
    self._ble_client = await bleak_retry_connector.establish_connection(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 361, in establish_connection
    _raise_if_needed(name, device.address, exc)
  File "/usr/local/lib/python3.11/site-packages/bleak_retry_connector/__init__.py", line 310, in _raise_if_needed
    raise BleakNotFoundError(msg) from exc
bleak_retry_connector.BleakNotFoundError: PBL-013B250 - 6C:7F:1F:16:EF:47: Failed to connect: Timeout waiting for connect response while connecting to 6C:7F:1F:16:EF:47 after 20.0s, disconnect timed out: True,  after 5.0s
jbandy2020 commented 1 year ago

Here's the config that's working for me on my PBV4PS2 Pitboss Using cheap AITRIP ESP32 from amazon

substitutions: name: esp32-bluetooth-proxy-f49f90 friendly_name: Bedroom Bluetooth Proxy

esphome: name: ${name} name_add_mac_suffix: false friendly_name: ${friendly_name}

esp32: board: esp32dev framework: type: arduino

web_server: port: 80

logger:

api: encryption: key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

esp32_ble_tracker: scan_parameters: interval: 1100ms window: 1100ms active: true

bluetooth_proxy: active: true

button:

wifi: ssid: !secret wifi_ssid password: !secret wifi_password

ota:

TTLucian commented 1 year ago

It works fine on the arduino framework. However, I can't get it to work at all on the esp framework.

dknowles2 commented 10 months ago

I'm still not able to reproduce this. My setup is using an esphome bluetooth proxy on an esp32 with the arduino framework and it seems to work just fine. AFAIK I'm not doing anything crazy with the bluetooth interactions, so I'm not sure what else to do here.