sopelj / hass-ember-mug-component

Ember Mug Integration for Home Assistant
MIT License
111 stars 4 forks source link

Ember mug wont reconnect after resting HA from backup #38

Closed rybackisback closed 7 months ago

rybackisback commented 10 months ago

Description

After restoring from backup ember mug does not connect to home assistant

What I Did

I reset the mug, I uninstalled and re-installed both hacs integration and ha  integration and attempted repair. I also ran bluetoothctl and put the mug into pairing mode but still it wont connect

Logs / Errors

2023-11-17 20:52:43.351 DEBUG (MainThread) [ember_mug.mug] Set new device from DB:7C:3C:36:0C:88: Ember Ceramic Mug to DB:7C:3C:36:0C:88: Ember Ceramic Mug 2023-11-17 20:52:43.351 DEBUG (MainThread) [ember_mug.mug] Callback <bound method MugDataUpdateCoordinator._async_handle_callback of <custom_components.ember_mug.coordinator.MugDataUpdateCoordinator object at 0x7f040cea6010>> already registered 2023-11-17 20:52:43.351 DEBUG (MainThread) [custom_components.ember_mug.coordinator] Updating 2023-11-17 20:52:43.351 DEBUG (MainThread) [ember_mug.mug] Updating the following attributes: {'meta', 'firmware'} 2023-11-17 20:52:43.351 DEBUG (MainThread) [ember_mug.mug] Establishing a new connection from mug (ID: 139655508168464) to DB:7C:3C:36:0C:88: Ember Ceramic Mug 2023-11-17 20:52:44.375 DEBUG (MainThread) [ember_mug.mug] DB:7C:3C:36:0C:88: Ember Ceramic Mug: Failed to connect to the mug: (DB:7C:3C:36:0C:88) - DB:7C:3C:36:0C:88: Failed to connect after 8 attempt(s): [org.bluez.Error.Failed] Operation already in progress 2023-11-17 20:52:44.375 DEBUG (MainThread) [custom_components.ember_mug] Finished fetching ember-mug-db7c3c360c88 data in 12.542 seconds (success: False) 2023-11-17 20:52:44.375 DEBUG (MainThread) [ember_mug.mug] Unregistered callback: <function async_setup_entry.. at 0x7f04093ec2c0>

sopelj commented 10 months ago

That's very strange. I have noticed Bluetooth Issues since upgrading to Home Assistant OS 11, is that what you are using? Bluetooth Proxies work fine, but it very rarely can connect via the USB dongle. I thought it might have been my dongle that was failing, but maybe there is another problem.

rybackisback commented 10 months ago

That's very strange. I have noticed Bluetooth Issues since upgrading to Home Assistant OS 11, is that what you are using? Bluetooth Proxies work fine, but it very rarely can connect via the USB dongle. I thought it might have been my dongle that was failing, but maybe there is another problem.

Yes correct I am on OS 11.1

fowlermv commented 9 months ago

I have the same issue. I moved my HA to new hardware and cannot get the ember to reconnect. Mine just says "failed setup, will retry". The mug is auto detected but never successfully adds into the restored HA instance. I've even gotten a new Bluetooth adapter since this and it didn't help. Any thoughts?

sopelj commented 9 months ago

Ok, that is very strange. I will do some investigation this week. Do either of you have errors on the host? I know, I am getting a bunch of kernel errors related to my Bluetooth adapter. I thought that was the cause.

Are your mugs far from the adapter? I've noticed that it only seems to work when much closer now.

Either this is an issue with Home Assistant OS 11 or it may be related to #36, where instead of retrying endlessly it now reports unavailable after a few tries. So, either it is a bit too lax or perhaps the former constant retrying was covering up issues with poor signal strength. It is strange however, that it doesn't seem to have this issue with Bluetooth Proxies, which is why I thought it might be the former.

I'll try some tests this week.

rybackisback commented 9 months ago

I tried reconnecting 2 to 3m away from the BT adaptor and it is still the same.

sopelj commented 9 months ago

In my testing I noticed an official Bluetooth integration I use (the Idasen Desk also stopped working with my proxy disabled. There are a few different issues open in the core for it. I don't know if it's the same issue or not. The official documentation for that integration says:

The recommended way to connect the desk to Home Assistant is by using an ESPHome Bluetooth Proxy, as they provide the best experience. [...] The connection process is also less reliable than with ESPHome, so you may need to retry a few times until it succeeds. This is due to a limitation in the third-party Bluetooth implementation used by Home Assistant. Also, if not using an ESPHome Bluetooth Proxy, you may experience the desk becoming unavailable and needing re-pairing after a restart of Home Assistant or a reload of the integration

I'll spend some more time investigating and trying to fix this weekend, but in the meantime using Bluetooth Proxies is a good workaround and should offer a better experience regardless.

sopelj commented 9 months ago

I dug through the changelogs of all the bluetooth related commits and I can't find anything in 2023.11 that would account for this issue.

I did however manage to get the mug working again by going into bluetoothctl, removing the Mug and factory resetting it. After that it the integration re-connected it and it has been working stably since then. Does that work for anyone else?

The alternative is of course using a Proxy as they seem to have no problem at all.

robert-cpl commented 8 months ago

Have two mugs, Ember 1 and 2 versions. None of them managed to connect first try. Digging in the logs, I found the same issue as OP. I managed to fix my issue by, as sopelj suggested, to remove the mugs using bluetoothctl and retrying the integration.

fowlermv commented 7 months ago

I still cannot get it to work. I do think it has to do with the bluetooth in home assistant but I cannot remove the ember mug from my HA. I get "device MAC is not available" no matter what I do. It's listed in the device list but I cannot do anything about it.

sopelj commented 7 months ago

I still cannot get it to work. I do think it has to do with the bluetooth in home assistant but I cannot remove the ember mug from my HA. I get "device MAC is not available" no matter what I do. It's listed in the device list but I cannot do anything about it.

Hi @fowlermv , have you tried removing the device from bluetoothctl and factory resetting it? Have you tried with a Bluetooth Proxy? Perhaps your Bluetooth adapter is problemtic. Does it work with other devices in Home Assistant?

fowlermv commented 7 months ago

My problem is that bluetoothctl does not work to actually remove the device. It has done this since restoring a backup while migrating from a virtual machine to hardware. All other bluetooth devices work fine though and I have tried two different bluetooth adapters which were both on the HA list of recommended hardware.

sopelj commented 7 months ago

My problem is that bluetoothctl does not work to actually remove the device. It has done this since restoring a backup while migrating from a virtual machine to hardware. All other bluetooth devices work fine though and I have tried two different bluetooth adapters which were both on the HA list of recommended hardware.

Removing it does not work? How do you mean? Is it listed in the devices in bluetoothctl? If it never correctly connected that makes sense. Does it show up in bluetoothctl when in pairing mode if you set scan on? When using physical adpaters you might need to have the shell with bluetoothctl open in order for the device to pair. You can also manually connect and pair the device in bluetoothctl and then try reloading the intergration. You can see the Idasen Integration warning for an example as this is a core one that also relies on pairing.

That is a limitation in the bluetooth library. Not sure why. Your other devices may not need to be paired. Most will jsut freely advertise their data.

sopelj commented 7 months ago

Did that help at all?

fowlermv commented 7 months ago

Well I just decided to give it another shot today and it seems to have worked when previously it had not. We've been through a couple of HA updates though so maybe something got fixed somewhere.

sopelj commented 7 months ago

Awesome! I'm glad. I'll close this issue then, but don't hesitate if there are other issues.