Closed TTLucian closed 10 months 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.
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
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.
Can you post yout esphome yaml for the proxy?
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
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?
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? π€·π»
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.
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
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 π )
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.)
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
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
What kind of ESP32 board are you using?
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.
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.
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. π€
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
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:
platform: safe_mode name: $friendly_name Safe Mode Boot entity_category: diagnostic
platform: restart name: $friendly_name Reboot entity_category: diagnostic
wifi: ssid: !secret wifi_ssid password: !secret wifi_password
ota:
It works fine on the arduino framework. However, I can't get it to work at all on the esp framework.
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.
System Health details
System Information
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 | 51AccuWeather
can_reach_server | ok -- | -- remaining_requests | 46Airly
can_reach_server | ok -- | -- requests_remaining | 36 requests_per_day | 100Home Assistant Cloud
logged_in | false -- | -- can_reach_cert_server | ok can_reach_cloud_auth | ok can_reach_cloud | okHome 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 | storageRecorder
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.1Sonoff
version | 3.5.1 (122751c) -- | -- cloud_online | 19 / 22 local_online | 17 / 17Checklist
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:
Debug logs