Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ESPHome raw bluetooth advertisements #94138

Merged
merged 15 commits into from
Jun 7, 2023
Merged

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Jun 7, 2023

Edit: After running this in production for a bit, the results wildly exceed expectations. The overall runtime to process the incoming data on the ha system is down by at least 10%, and esphome incoming data path run time is down by at least 50% when coupled with the new Bluetooth-data-tools.

I know it's a bit counterintuitive to have a remote device be faster than a local one, but I don't even have to profile them to tell that my olimex Poe iso ea proxies are faster than the local adapter now as the time it takes to lock and unlock a Yale lock is a about half the time with the proxy vs the local adapter.

I'll work on a pr to bump the recommended esphome version for Bluetooth proxies to 2023.6.0+

Proposed change

We now send advertisements in bundles of up to 16. The raw bytes are parsed by bluetooth_data_tools to take the load of the esp device and reduce the amount of time the wifi radio is being used. In testing the reduced number of packets and the redunction in processing of the packets more than offset the cost of doing the parsing in the library vs the ESP. This improves Bluetooth and Wi-Fi co-existance since we significantly reduce the number of packets (being sent over Wi-Fi) needed to get the bluetooth data from the ESP to HA.

Note that packets are only bundled together if the esphome code already bundled them together which means there is no significant change in latency (faster in most cases since the overhead to read and unpack the protobuf packet had to be done between each ble packet before)

esphome/esphome#4924 is required to use the new code path (but is backwards compatible)

library bump:
aioesphomeapi esphome/aioesphomeapi@v13.9.0...v14.0.0

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

We now send advertisements in bundles of 16. The raw bytes are parsed by
bluetooth_data_tools to take the load of the esp device and reduce the
amount of time the wifi radio is on which improves Bluetooth and Wi-Fi
co-existance since we significantly reduce the number of packets needed
to get the bluetooth data from the ESP to HA
@home-assistant
Copy link

home-assistant bot commented Jun 7, 2023

Hey there @OttoWinter, @jesserockz, mind taking a look at this pull request as it has been labeled with an integration (esphome) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of esphome can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign esphome Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@bdraco bdraco closed this Jun 7, 2023
@bdraco bdraco reopened this Jun 7, 2023
bdraco added a commit to Bluetooth-Devices/ruuvitag-ble that referenced this pull request Jun 7, 2023
unblocks home-assistant/core#94138

bluetooth-data-tools got a major version bump (not breaking for this lib)
bdraco added a commit that referenced this pull request Jun 7, 2023
@bdraco bdraco mentioned this pull request Jun 7, 2023
20 tasks
@bdraco bdraco marked this pull request as ready for review June 7, 2023 06:20
@bdraco
Copy link
Member Author

bdraco commented Jun 7, 2023

Toothbrush test is much smoother now. The esp has yet to complain about too many packets to process anymore.

@bdraco
Copy link
Member Author

bdraco commented Jun 7, 2023

tested all day. looks good 👍

@bdraco bdraco merged commit 88bfd94 into dev Jun 7, 2023
@bdraco bdraco deleted the esphome_bundled_advs branch June 7, 2023 23:36
mover85 pushed a commit to mover85/core that referenced this pull request Jun 8, 2023
…94138)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2023
@bdraco bdraco added the noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) label Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed integration: esphome noteworthy Marks a PR as noteworthy and should be in the release notes (in case it normally would not appear) Quality Scale: No score small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants