New integration: Magic Swithcbot

Tags: #<Tag:0x00007f3265bc8e70>

Hi there.

I am developing a new component that allows to integrate Magic Switchbot devices, similar to others like the “Switchbot”. It uses BLE (Bluetooth Low Energy) and has 2 modes:

  • Push mode.
    It allows us to push momentary switches. It presses for a second and then retracts its little “finger”.
  • On/Off mode.
    With the help of a “hook” that you can stick, it has 2 states: “On” state presses and stays there and “Off” state pulls from the hook and lets the original switch to deactivate.

The component creates the new switch integration “magicswitchbot” and also publishes a service that allows us to activate the “push” mode.

You can follow the progress of the component in my GitHub repository:

You can test the component witch HACS using this as a “custom repository”.

Also there’s a Python library I developed that’s used internally by the component and can be used on other projects. There’s a lot of documentation here:

I hope it works for you.

2 Likes

New release v0.0.3 at the component repository. Available in HACS.

A lot of changes.

The connection strategy has changed:

  • In previous releases, the connection was made at start and tried to be kept active every minute (when we got the battery level) and every time we issued a command to the device.
  • Now, there is no connection made until the moment we need to do it. When you:
    • Turn on.
    • Turn off.
    • Call the “push” service.

If no connection is active, the component tries to connect (3 times, for 5 seconds evert attempt) and then execute the command. If the command succeeds, the state of the switch is changed accordingly. If it fails, the state does not change and the attribute last_action gets the Error value.

The attribute battery_level is updated only when a command is executed.
Once the command is executed, the connection stays for 30 seconds. If you don’t issue a command in this time, the connection is closed. There’s also an attribute connection that holds a boolean with the current connection status.

This approach has some advantages:

  • You can control the device from several points: another HA instance, the original app, etc.
  • The connection is established only when needed.

But also it has some cons:

  • If the connection is not established when you want to switch on or off the device, it has to connect first, so it is slower.
  • You don’t have an updated value of the battery if no action is taken on the switch.

I hope it works OK for you.

At the moment It works perfectly! Very good job!! It’s perfect to activate my A/C from home assistant. Thank you very much!!

1 Like

New release: v1.0.0

Hope it helps.
Thanks @chronoszgz for pointing me about this bug.

I finaly got my magicswitchbot and I’m able to work with it using the on/off method. Unfortunately I’m not able to make it work with the push method, probably because I’m doing something wrong. I’m running Hassio and the latest official HA 2021.4.2.
When I use the service to send the push nothing happens and I see in the log "There is no Magic Switchbot defined as ‘switch.magic_sofa_lamp’ but it is defined because I can use the on/off switch. Probably I’m not using the correct syntax calling the service.
I’m using the following data:

service: magicswitchbot.push
data:
  entity_id: switch.magic_sofa_lamp

Please can anyone help me?
Thanks in advance