New integration: Magic Swithcbot

Hey, thanks!

I cannot reproduce these “freezes” in my installation, but there are more users reporting them.
I think there must be some kind of interaction between my component and some other components using bluetooth. This is an old known behaviour of the bluetooth stack and I’m trying to find a fix.

Hello,
Thank you for writing this integration. Since I don’t have all the skills and not linux, would it be possible to integrate it in HACS?
Thank you for your feedback and again thank you for the time spent on this integration

Hi,
I had also earlier this “freezes” issue, but after disabling bluetooth device trackers, the problem was solved. I am using this skill every day for (about) more then a week now, but without any issue. I am very glad for your work. Thank you!

1 Like

Hello.

The component is integrated in HACS but yet not in default repositories. You have to add the repository as “custom”. Please read the documentation in github README.

1 Like

Hi, thanks for the link.
How can i do this ?
" You can install this component with HACS. Add https://github.com/ec-blaster/magicswitchbot-homeassistant as an integration “custom repository” and install it. "
This can be a stupid question but im new in home assistant. I love the compatibility and opportunity of this software
Best regards. Bowen

Hi,

Thanks for sharing @ec-blaster!

I am a complete noob with regards to HA. I just got to make my first automations and scripts.
At the moment I am trying to understand and incorporate your code to integrate my MagicSwitchBot, but I am not able to get it to work.

Can somebody help me out a little to get me started? To be honest I do not understand much from the article on git-hub yet. Where do I for example run the sudo functions you are referring to? How can I run some py scripts on HA?

All help, tips and links to additional material to read are much appreciated!

Cheers,
Job

1 Like

1
2


Hi again,

I got a hole lot closer I feel. In the meantime I read a lot and watched some videos. I was able to integrate it as a custom repository via HACS.
However, the most important thing, it does not work yet. I can toggle the switch, but nothing happens. Can you see from these snapshots anything vital that I miss?

Thanks a lot!
Job

Edit: sorry for spamming this thread. After a lot of restarting and random tries I got it to work. I feel it only works for me when I have the Bluetooth tracker enabled. It started working when I had a timer active from the magic app itself, but might very much be random coincidence.

Only thing that I cannot get to work yet is an automation or script with switch. Anybody with issues there too?

Hi, @MassiveDynamic , and sorry for the delay, I’ve been busy.

In HACS you can search for “default” repositories or you can add your own ones.
My repository is not yet in the default list, so to add it as a cusstom repository you must do the foloowing:

  • Select the “Integrations” options in HACS.
  • At the top right you have a three- points icon. Press it and you get a menu.
  • In this menu, select the option “Custom repositories”.
  • A dialog appears and at the bottom you have three fields:
    • Custom repository URL: Enter here my repository url.
    • Category: Select “Integration”.
    • Now press the “Add” Button.
  • Now you have a new entry in the repository list, with the name Magic Switchbot.
  • Select it and install.
  • Now you only have to restart HASS and the component must be working.

Hope it helps.

Hi, @smartjob, and thanks for your feedback.

Don’t worry to be such a noob, we all are or were in some moment!

In regard to what you say, I think your configuration is fine, but some notes about the component and the device:

  • There is some kind of interaction when you use the same bluetooth adapter for different tasks.
  • In HASS you can install several components using bluetooth (device trackers, temperature sensors, my component, etc), but in the end, if 2 or more components are requesting to connect, they may clash, and this is the root cause of several freezes some users have. It’s difficult to synchronize several pieces of software built by several people in a way that they cooperate… Anyway I’m at it…
  • Other things to consider is that the device seems to have a poor antena or whatever so in my experience, you have to place the bluetooth adapter relatively near, or you can get into connection losts.
  • The original app is another piece of the puzzle: you cannot control the Magic Switchbot devices from two clients at the same time. This is: if you keep the smartphone app open, it stays connected to the switch, so it cannot be controlled by HASS. You must close the app before controlling it.

Anyway, if you have problems, you can attach your logs (preferably in debug mode) here or as a github issue and maybe I can investigate further.

Good evening.
I want to thank you for this tutorial. Don’t worry about the weather. I am very happy to have passed this step whose tutorials did not help me. Hoping to understand for myself even using the documentation later without having to bother you again.
Thank you again and see you soon :slight_smile:

1 Like

THANK YOU it work perfectly !!!

1 Like

Just a note to say that the component is now part of the “default” HACS repositories.
No need to add it as custom repository, you just search for “Magic Switchbot” and you can add the repository to your installation.

1 Like

Nice job! Thank you.

I have a problem to configure it.
installed via HA but seems I cannot connext to the device.

my HA version and logs in attachments. Thanks in advance for any piece of advice what shall I do.

Hi.

From what I see at your first log, you have a basic bluetooth connectivity problem. This happened to me at the very beginnings, and it was caused by not having permissions to use the bluetooth dongle.
I fixed it using the setcap command, as I wrote at the docs, but I think your case may be different as you are using HassOS (so it’s running inside docker). I have no experience about HassOS or docker as I am using HA core from the beginning, and I don’t know if you need anything additional to control the bluetooth dongle, or may be it cannot be done. This article talks about this but I don’get a clear conclusion. Maybe you could log into your docker and check if the bluetooth dongle (usually hci0) is working OK.

Some things you could try:

  • hciconfig
  • hcitool ble scan

Hope you can solve it, give me some feedback about your tests.

Hi, what’s the bluetooth range for device like raspberry pi 4 if paired with magic switchbot?

Also, other than using built in bluetooth, is there a way to extend bluetooth range?

Hi, @ferbulous.

I don’t run HA on a PI, so I cannot tell you about the range.
If you can run hcitool lescan and read “MagicSwitchbot” in the list of detected devices, you must be good to go.

About the second question, I have an external bluetooth dongle attached to an extension USB cord, and I can place it as near as I can to the devices I have to control.
If your internal device is for example hci0, your external one should be hci1 and so on…

1 Like

hi @ec-blaster
Is it possible to use this tool for extending bluetooth
coverage to the magic switchbot?

I didn’t know about that project. I understand it’s a way to decentralize the Bluetooth devices management.
It doesn’t seem to be very difficult, but I don’t have the time to investigate it, and I have no device to try it on.
In addition, I’ve been reading the code of the switchbot devices, and the logic is way simpler than the MagicSwitchbot’s. I could maybe give you some directionsif you want to try and code it.

Hi! I am not able to install the integration… Using HACS I am able to add the repo, but when I search for integrations, I can not see the magichome integration… I allready tried to wipe browser cache and restart HA.

In the custom components folder, I see the Magic switchbot folder… Also tried to add the device in configuration.yaml. But I cannot find the device itself… So I think the integration is still not installed??