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

home assistant freezes when using magic switch bot #4

Closed
bezlitza opened this issue Apr 9, 2021 · 25 comments
Closed

home assistant freezes when using magic switch bot #4

bezlitza opened this issue Apr 9, 2021 · 25 comments
Assignees

Comments

@bezlitza
Copy link

bezlitza commented Apr 9, 2021

my HA may hang when using switchbot. Xpenology docker. HA and plugin latest versions
image

@ec-blaster ec-blaster self-assigned this Apr 9, 2021
@ec-blaster
Copy link
Owner

Please attach your logs.
Set log level to debug

@bezlitza
Copy link
Author

bezlitza commented Apr 9, 2021

home-assistant.log

Please attach your logs.
Set log level to debug

@ec-blaster
Copy link
Owner

I changed some exception catching.
Please update the component (v1.0.1) and try again.
If you keep getting errors, please increase the magicswitchbot log level to DEBUG and attach the logs again

@bezlitza
Copy link
Author

it didn't help
home-assistant (3).log

@ec-blaster
Copy link
Owner

From what I can see, there's nothing wrong with the component that makes HA not starting.
There's a communication error, but I need more clues.
Could you please set the log level in your configuration.yaml to INFO:

logger:
  default: warn
  logs:
    custom_components.magicswitchbot: info
    magicswitchbot: info

@bezlitza
Copy link
Author

no, the problem is not that HomeAssistant doesn't start, but that when using magic switch bot, my HomeAssistant stops working

@bezlitza
Copy link
Author

home-assistant (4).log

@ec-blaster
Copy link
Owner

Still no logs from the component beyond warnings.
Please check the syntax I provided you yesterday. From the logs I can see your syntax is not correct.

@bezlitza
Copy link
Author

home-assistant (5).log

@bezlitza
Copy link
Author

bezlitza commented Apr 11, 2021

I also have the original Japanese switchbot with it there is no problem. The xiaomi watch is connected directly to the server via Bluetooth

@ec-blaster
Copy link
Owner

OK, I see the problem now.
It looks like it's a poor connection problem.
I don't know if the magic switchbot has a poor bluetooth sensitivity, but from what I can read in your logs:

  • The device (ocasionally) connects.
  • The token is (ocasionally) retrieved.
  • But in the middle of the process, the device disconnects by itself so it doesn't finish.

In my experience, I've had these issues when the bluetooth dongle (or internal bluetooth) is not close enough to the magic switchbot. I solved it by attaching an external dongle with an extension cable close enough to the devices. Currently I have 2 magic switchbots working fine, and my dongle (with its extension cable) is about 2 meters away.

Sorry but I cannot help to improve the connection quality. I know that other devices work ok at further distance, but these devices are this way.

@bezlitza
Copy link
Author

is there any way to reduce the connection timeout? I have the whole home assistant freezes when connected

@bezlitza
Copy link
Author

@ec-blaster
Copy link
Owner

Hello, @bezlitza.

Thanks for all the info you provide.

Several thoughts about your situation:

  • I saw that you are using another BLE custom component for Xiaomi LYWSD02 Hygrometer Thermometer, and that component fails just after the MagicSwitchbot fails disconnecting. I checked the library that LYWSD02 uses and it's bases upon bluepy, the same library that my component uses. So, I think there are 2 different components using the same resource and that makes a mess. I'll try to investigate further, and try to solve any interactions, but I don't have such a device connected.
  • On other hand, I also saw that bluepy has some issues regarding freezes on disconnect, specifically this issue. I'll try to investigate further if I can find a solution.
  • Finally, regarding to what you asked, in the next release I'll add some new configuration parameters to the component for the connection timeout and repeats.

@Zylazy
Copy link

Zylazy commented Apr 20, 2021

Dear ec-blaster,
Thank you for your wotk on this, I am glad you work on this component.
However it does not seem stable to me either. Also my home assistant freezes when I using the switch bot.
Once it hang for 8 minutes, then suddenly the switchbot was activated, and my home assistant started working again. (log is attached)
homeassistant.log

Second time it hang again, but after 30 minutes there was still no response.
home-assistant 2.log

@ec-blaster
Copy link
Owner

Hi, @Zylazy.

Thanks for your logs.
Could you give me more information:

  • Please set the magicswitchbot logs to debug level isntead of info.
  • Also, are you using any other component that works with bluetooth?

@Zylazy
Copy link

Zylazy commented Apr 20, 2021

Ok. I will, send it. I have enabed device_tracker: bluetooth, but I have disabled it now, so during the test the switchbot will be the only one.

@Zylazy
Copy link

Zylazy commented Apr 21, 2021

Hi @ec-blaster
Sorry for the late reply. Yesterday I was very busy.
I have attached the new log.
I have to mention, that now it was much more stable as before, but I could reproduce the bug again.
You can see, that at 2021-04-22 01:01:59 it hung the system for about 5 minutes. The home assistant was absolutly unavailable for that time, then it suddenly wake up.
I have disabled the bluetooth tracking and set the log level to debug.

I have one suggestion/question. I have seen that you have defined the magicswitchbot.push service. Woulf it be possible to add a magicswitchbot.pull service also?
magicswitchbot.log

@ec-blaster
Copy link
Owner

@Zylazy: I'm studying your case, I don't know the reason you have such freezes, it didn't ever happen to me. Give me some more time...
By the way, in respect to the "pull" service, I don't think you need it. If you want to "pull" the switch, that's the on/off case, you only have to use switch.turn_on and switch.turn_off the switch.

@Zylazy
Copy link

Zylazy commented Apr 26, 2021

Thank you! Btw way, I have played with it today, and I could not reproduce the issue now. But I will continue the testing tomorrow.
You are right about the pull service. I have tested the switch.turn_off service, and it worked. I could call it twice without calling turn_on. That was what I was looking for! :)

@denisov-vlad
Copy link

Hi!

I have the same issue. There are 2 connected devices:

Home Assistant OS 6.2, core-2021.8.0b5

@bezlitza
Copy link
Author

bezlitza commented Aug 3, 2021

My problem is also still relevant

@ec-blaster
Copy link
Owner

I'm on vacation right now.
When I arrive home I'll try to develop a solution or at least try to reproduce your issues

@mnowok
Copy link

mnowok commented Nov 10, 2021

Any progress? I confirm similar problems with extra USB bt dongle and without it (hasoss, raspberry pi 4). I also use ha builtin switchbot integration (no problems) and https://github.com/custom-components/ble_monitor.

@ec-blaster
Copy link
Owner

New version released.
Integrated with HA native bluetooth.
Should fix previous errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants