-
Notifications
You must be signed in to change notification settings - Fork 6
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
Not working with Bluetooth Proxies (ESP32 based) #14
Comments
Thanks for sharing this. As stated, I can see the advertising messages of the Toothbrush in the BT Proxy Log, so I think it might be an issue of how the Sonicare integration reads/interprets these advertisement messages OR is the raspi BT passing BT messages differently than the ESP32 based BT proxies? |
That's exactly the question I hope bluetooth experts like @GrumpyMeow can verify. By the way: by only activating my toothbrush next to the BT proxy I could not find any activity in the logs (ESPHome). If i trigger other bluetooth devices (like SwitchBot buttons) next to the BT proxy, I see quite some activity. |
I think I played around with the advertising window / intervalls and could see the activity immediately when lifting the TB out of the glass... |
So, I've teste getting quite close to the server (like 2m) and the toothbrush was finally discovered. 😃 Now I will vote to add support for Bluetooth proxy. 😉 |
Same problem. Bluetooth proxy via the M5 atom lite via ESP home. @GrumpyMeow |
My toothbrush does connect if i'm close to my HA instance, but not from a Bluetooth Proxy. So, it would be great if support for Bluetooth proxies can be added. |
@GrumpyMeow are you reading/still maintaining this project? |
Same issue here, am able to connect via HA intgrated bt, but no luck via an esp32 based proxy. |
@GrumpyMeow you seem to be active, unfortunately not in this repo. Can you please give us an update on this? Fixing this "does not work with bluetooth proxies" issue is a mandatory killer feature immediately resolving a ton of open issues. |
This is the log output from home assistant after trying to connect my sonicare to ha via esphome: |
Seems @GrumpyMeow has abandoned this project. Would love to see some progress on this. Is this something that the Home Assistant dev team would pick up? It appears to have some good interest from the community. |
I don't think that is gonna happen. Usually a custom integration needs to prove it is "good enough" (like function in general, reliable, flexible in terms of reaction time for changes in core etc.) to become a core/default integration. Very sad here's no progress, which makes this basically really great integration basically completely useless for most users. Sell Philips, get a Oral-B? Just kidding. |
Summary of Errors and Troubleshooting Steps for ESP32 Bluetooth Proxy with Sonicare BLE ToothbrushUpdated: I found that although it will connect to a BT Dongle directly connected to the controller, it does not reconnect reliably after the toothbrush goes to sleep. I have to RELOAD the integration when the brush is awake to get it to reconnect. It only stays connected to that "session" and then will not reconnect. Therefore I suspect the integration has some issues that are just more severe when used with a proxy. IS ANYONE USING THIS RELIABLY WITH A DIRECT CONNECTION TO A BT DONGLE? I picked up a new Philips Sonicare and verified that it will not provision and connect when using a BT proxy, It will connect and operate properly when using a BT dongle connect to the Home Assistant Green controller. Although the toothbrush is discovered successfully, when attempting to add it to HA, when using an ESP32 Bluetooth proxy the Sonicare BLE toothbrush disconnects with error messages indicating "Connection reset by peer" (Errno 104). This issue occurs consistently, preventing the ability to add it to HA. I did a lot of troubleshooting............... Here are some of my logs and troubleshooting ESP32 Device Log Extract: BLE Connection Attempts and Errors: First Connection Attempt: Second Connection Attempt: Third Connection Attempt: Errors: Summary: Successful Initial Connections:
Frequent Disconnections:
Warnings and Errors:
Troubleshooting Steps Taken: Configuration Adjustments: Adjusted esp32_ble_tracker scan parameters to optimize BLE scanning:
Power Supply Verification: Ensured that the ESP32 is connected to a stable power source to avoid power-related disconnections. Reduced potential Bluetooth and Wi-Fi interference by positioning the ESP32 and Sonicare toothbrush closer together and away from other electronic devices. Firmware and Software Updates: Confirmed that all firmware and software (ESPHome, Home Assistant, and ESP32 firmware) are updated to the latest versions available at the time of testing. Core Logger Configuration: Enabled detailed logging to capture more granular details for debugging:
Alternative Connectivity Test:Verified that the Sonicare toothbrush connects successfully using a Bluetooth dongle plugged directly into the Home Assistant Green controller, indicating the issue is specific to the ESP32 Bluetooth proxy. |
Great work! For sure took a loooooot of time. How should we use those perfect information (you mentioned "the ESP home guys need to look at this issue")? Maybe someone can ping them? Another note: I also use Shelly's as bluetooth proxies, with the same (not working) results as with a ESP home powered bluetooth proxy. Shelly are also based on ESP, but not ESP Home - just as a small note. |
Unfortunately, I don't think they will look at it until someone takes over this integration and reviews the code for possible errors. It's sad because the Oral B is very expensive and the Sonicare has excellent hardware and is very affordable. |
I found that although it will connect to a BT Dongle directly connected to the controller, it does not reconnect reliably after the toothbrush goes to sleep. I have to RELOAD the integration when the brush is awake to get it to reconnect. It only stays connected to that "session" and then will not reconnect. Therefore I suspect the integration has some issues that are just more severe when used with a proxy. IS ANYONE USING THIS RELIABLY WITH A DIRECT CONNECTION TO A BT DONGLE?_ |
Unfortunately, no. 😩 |
So just to clarify, you have it connected to a BT dongle directly, but it is not reliable? |
Exactly. In the end, it's not useful. |
is there any good news to get this up and running? |
No. The author of this integration doesn't seem to be active in any way. This makes us (potential) users grumpy and leaves us with a non-working integration. Completely useless. |
I remember having similar issues when implementing QuietDrift for SwitchBot Curtain 3. Originally, it was a separate service called via HTTP from HA. However, I got into connection issues similar to those. I implemented various reconnecting mechanisms, but it was hard to make it working in long term. Then, I rewrote it as a custom component and let HA to manage the BT connection, which has fixed the connection issues. My original code was obtaining the device object from bleak_retry_connector.get_device. And this this custom component does something similar: sonicare-ble-hacs/custom_components/sonicare_bletb/__init__.py Lines 27 to 29 in 5ab0c8f
Well… It isn't exactly the same. It tries to use bluetooth.async_ble_device_from_address first. However, when the device isn't reachable, it returns None, which forces a fallback to bleak_retry_connector.get_device. And it is quite common that the device is unreachable. In this case, bleak_retry_connector.get_device is likely to also fail, but it doesn't have to, as it is called somewhat later, and apparently can wait a bit. In my logs, I've seen an error from bleak_retry_connector, which suggests that this sometimes happens. The code is in async_setup_entry, and it is the only place where async_ble_device_from_address/get_device is called, which has few consequences:
Not sure about async_ble_device_from_address, but I am pretty sure that bleak_retry_connector.get_device retries just in the first connection. Once the connection is lost, the returned object doesn't retry. Initially, I am removing the get_device fallback and will see how it affects the behavior. I am not sure why it was added, as 34508e3 doesn't explain much. |
Few more findings: First, it has connected to the toothbrush even with all BT adapters disabled, leaving only BT proxies. Second, it has still issues with disconnecting. Looking more about the code of this repo, the library and the documentation, it seems that the component (and/or its libraries) is responsible for reconnections. There is however some mechanism, but seemingly incomplete:
Looking from 10 feets:
What to do:
I'll probably do it later, it doesn't look that hard. EDIT: I got a bit struggles with the callbacks, HA's documentation isn't perfect. But maybe I was reinventing the wheel – it looks like ActiveBluetoothDataUpdateCoordinator has already implemented what I need. |
@v6ak Wow, impressive (as always when users see devs talking and doing their magic 😀). Sounds like maybe Christmas takes place a bit earlier this year: toothbrush working with BT proxies sounds so 👍 |
@v6ak I'm currently working with very unreliable workournds,. when the toothbrush connects to a tablet, the Soniccare app simply opens. Not particularly fancy ^^ Unfortunately I don't know coding, but if I can help e.g. with testing, please let me know. |
Well, not sure how to proceed. I've tried multiple ways to discover the device:
Expected results: the device gets discovered when I make the toothbrush active (move, brushing, briefly after brushing, briefly after charging), so I can connect it. Actual results: the device gets discovered immediately and seems to never disappear. However, I don't get a callback when the device is actually activated. I feel like I am missing something trivial, but not sure what… |
With all my testing, I got the impression that there was some bug in the brush itself. I just threw mine in the trash this week and purchased 4 Oral B Series 4 toothbrushes off eBay. Great brush and about $50 bucks new on eBay if you are patient. The are rock solid in Home Assistant. |
@v6ak : thank you very much for trying to solve the issue! Looking forward to test your fixes in the future with my philips toothbrush 👌 Regarding you missing callback: maybe you could as in the discord channel of HomeAssistant in the dev area. Maybe you get some hints 👍 |
@v6ak - I'd like to thank you as well. So happy to see someone trying to solve this issue. Truly appreciate your efforts on this. |
I was trying to perform a deeper rewrite of the BT handling, but ended with just conservative changes:
I don't think it will be 100% reliable, but it might be reliable enough for some uses, including my needs (battery monitoring and keeping the charge about 50 %). My adjustments in reconnect will probably work only after longer inactivity, which might be enough for typical use (brushing twice a day). Because testing needs longer inactivity, it is not much tested, but if you want to try it anyway, it's there: https://github.com/v6ak/sonicare-ble-hacs Some issues that aren't fixed:
How (re)connecting works, what are the challenges?It seems to be quite easy to initiate the connection to the toothbrush. However, you probably don't want to press a button (within the short time-frame) in order to do that. It should be done automatically. The toothbrush is apparently offline for most of the time, so it is crucial to detect when it becomes online. Also, it is crucial to detect is ASAP, because the time when you can connect is quite short. One could try to connect periodically (so called polling). The polling would have to be quite frequent (as the time for connection is quite short). This would not only take CPU (maybe not that much), it also uses Bluetooth communication. Depending on your BT adapter and other BT devices, you might reach the limit of maximum connected devices. This addon (well, the sonicare-blebt library) does this partially, but it seems to break in long term. The other way to do it is to somehow detect when a toothbrush is available, just by being passive and waiting for some indication. BT devices announce their presence (if they are configured to be visible), and it seems to be also the case of Sonicare toothbrush when it starts being active (brushing, charging ends, brush moves, …). However, apparently, I can't see all the beacons. The HA Bluetooth API documentation suggests that you probably will not receive two such notification in a short succession:
Yes, this is about unavailability notification, but availability notifications probably work in a similar manner. When HA doesn't see the device, it takes a time to consider it unavailable. When a beacon from the device is received, HA probably doesn't notify about its availability, as it didn't consider the device to be unavailable. In my testing, it looked like there is some longer period than just five minutes, but I might got something wrong or misunderstand something. Possible workaround for missing the availability notificationIf my changes aren't enough and HA doesn't detect the presence of the toothbrush enough, we could add a service that would connect the toothbrush when called. It would be up to user to call it when needed. This could work automatically in some setups, e.g.:
I hope this will not be needed, though. |
@v6ak : thanks again! today in the morning I briefly tried to connect my sonicare via a bluetooth proxi to HA, but sadly I couldn't connect. I didn't have time to check logs, but in theory the connection via bluetooth proxis should work (with your branch)? |
Do you try to add a new toothbrush, or to use an already added toothbrush? Using an already added toothbrush should work. At least, it works for me.
Adding a new toothbrush via BLE proxy? Not sure:
* I haven't tested adding a toothbrush with the modified addon.
* With the original addon, I had to try several (four?) times, even when having BT adapter enabled. Not sure if it went through the adapter or through BLE proxy. (I was about 5m from both proxy and adapter.)
* Also, the opportunity to connect is quite short. When your toothbrush is active (after brushing, after charging, when you move it, …), there is very short period to connect to the toothbrush. I don't think I can do anything about it.
EDIT: I've also found an example of what breaks the original reconnection BleakNotFoundError: bleak_retry_connector.BleakOutOfConnectionSlotsError: […] - AA:DD:55:EE:SS:SS: Failed to connect after 9 attempt(s): No backend with an available connection slot that can reach address AA:DD:55:EE:SS:SS was found: The proxy/adapter is out of connection slots or the device is no longer reachable; Add additional proxies (https://esphome.github.io/bluetooth-proxies/) near this device
|
It seems that the issue with device discovery was independently described by GrumpyMeow. Anyway, it looks like the connection to the toothbrush is successful if and only if the last attempt is old enough (EDIT) or fresh enough, but not few minutes after the last attempt. Not perfect, probably good-enough for me. Not sure if we can do much about it without changing the HA core, except adding a service for forcing a reload. What's not that good is that only some entities seem to be updated. Handle time seems to be updated, but battery state doesn't. This is kinda weird, as both seem to be implemented in the very same way. I hope I can work around by full reinitialization. EDIT3: I've also looked on active vs. passive scanning. I think that passive scanning would be faster and enough for the toothbrush connection. However, because HA actually ignores the mode for now, I'll keep active scanning, as I cannot test if passive scanning is enough and it has currently no benefit. |
Just pushed a new version:
Known issues that remain:
|
Well, I started getting issues with my BLE proxy. I have just a single proxy. It fails with the following error message:
Then, the device with BLE proxy keeps almost offline. It doesn't update sensor data and it cannot connect BT devices, but it can propagate advertisments and a button press. Maybe I have an outdated software on the BLE proxy. I'll see if update fixes something. |
Investigation of BLE proxies crashesESPhome upgrade didn't fix it. The weirdest part of the error is that it comes from this line (not sure if the version perfectly matches, but at least the specific line is the same in HA Docker image): How can this line cause a TypeError? Temporary workaroundI've disabled the async_rediscover_address call, which seems to cause some wrong state somewhere. Also, this call is probably not much frequently used, so it can be less tested. It seems that it has resolved the issues with BLE proxy crashes. The drawback is that the toothbrush doesn't reconnect that reliably. Again, this is likely not a big issue in common usage scenarios (brushing twice a day), but it can be annoying when testing. |
Just a timeline what happens when you activate toothbrush:
Between 6 and 7, the toothbrush is disconnected, but Home Assistant still considers it to be available. This means that when HA sees a new advertisment, it doesn't think the toothbrush becomes available. It thinks that the toothbrush is still available. As a result, it doesn't notify the addon. So, when user attempts to wake the toothbrush within this period, HA doesn't forward the advertisment to the addon. Even worse, it probably resets a timeout, so the user has actually to wait even more. (I think it is this 5min timeout). Attempts to resolve the issue:
|
Hey @v6ak Thank you so much for your effort—it’s brilliant! I tried setting it up today, but unfortunately, it doesn’t seem to work for me. The toothbrush does appear, but as soon as I try to add it, it just keeps loading endlessly. How did you manage to get it working? I’ve tried everything: adding it after charging, during brushing, while shaking it, spinning in circles… nothing seems to work. What I also noticed is that Shelly BT proxies don’t seem to function in this case (though they work fine for everything else and are set to active). To troubleshoot, I placed an ESPHome BT Proxy in the bathroom. If there’s any log or information I can provide, please let me know—I’m happy to help in any way I can! But really, thanks again! I’d love to get this integration up and running. |
Awesome to see this topic alive again! I will soon test it with shelly BT proxy if it works on my end. Unfortunately I do not have any other bluetooth proxies available to test it with. |
My effort was focused on reliability of connection after the toothbrush is added, not on adding the toothbrush. However, I've tried to remove my toothbrush and add it again while having all BT adapters (except BT proxies) disabled. So, it must have connected through the BT proxy and it succeeded. (I have just one BT proxy.) Reliability of adding a new toothbrush might have been improved as a side effect, because the addon no longer requires successful connection for initialization. But I am not sure. If you still have issues with adding the toothbrush to HA:
@Dodoooh If you can share some logs (related to Sonicare), you are welcome. Please try it with the newest version. Current known issues:
|
Observation: Battery is reported again not only HA reboot, but also after ESP32 reboot. Maybe after any reconnection between ESPHome and HA. (Would router reboot also do the trick?) However, I am not sure if I'll continue with working on the fork:
|
While I was lucky to initialy set up this integration without any issues (#2 (comment)), I discovered by manually reloading the integration that:
So where's the issue? Is it the BT proxy or this Sonicare BLE integration?
I bet this is one of the reasons for the most open "Can't connect to XYZ" issues in this integration, so really worth looking into this @GrumpyMeow! We should probably start asking for the specific bluetooth environment people use. I already found few users stating they are also using Bluetooth Proxy (e. g. here: #2 (comment)).
The text was updated successfully, but these errors were encountered: