I did some tinkering around and found a quite straight forward way to use the Switchbox hub within Home Assistant. It uses Python-switchbot which is then called through pyscript. This will give you a service that then switches the switchbot and you can use the service in any automation.
Switchbot hub integration instructions:
Download the SwitchBot app on App Store or Google Play Store
Register a SwitchBot account and log in into your account
Generate an Open Token within the app
a) Go to Profile > Preference
b) Tap App Version 10 times. Developer Options will show up
c) Tap Developer Options
d) Tap Get Token
Now you have the token to use with the switchbot API (see below)
Install python-switchbot (you might want to have this also install on every startup of HA in case you are running it in Docker) pip install python-switchbot
Create a python file with the following contents in folder <config>/pyscript, i called it switch.py:
(to get your device id see documentation of python-switchbot)
no idea, at this moment my switchbot is in the “useless gadget” drawer. What a crap piece of hardware. Completely unreliable. Sometimes it will switch (using their own app) and sometimes it will just fail.
Hi do you think you could maybe explain further how to get this working
i got the token from the app, the deviceid too (deviceid=BLE MAC without “:” right?)
installed python-switchbot by ssh to my HA
installed psycript from HASS and then from integration on HA , made the switch.py file, placed it in the psycript folder
used this content
inserted the token between the ’ ’
same goes for the deviceID
and saved the file restarted everything
on the switchbot app i also enabled cloud services on the switchbot.
i can only see two services added, one of “reload” and one of “start juniper kernel”
Log showing me this
Exception in </config/pyscript/switch.py> line 1: from switchbot import SwitchBot ^ AttributeError: module ‘switchbot’ has no attribute ‘SwitchBot’
GOT IT RESOLVED
im on HA OS
i SSH before and then did the pip install
i had to SSH and then go into the actual docker
by entering
docker exec -it homeassistant /bin/bash
and then do the pip install from there
that did the trick and got things working
hope this helps someone one day
Thanks for the additional info Ron, definitely helping me here. I’m still having trouble with the install python-switchbot command, also running HA OS. Outside of the Docker command, was there anything else you did to execute the installation?
Hello, I’m blocked on the step to retreive Switchbot device ID. I don’t understand what I have to do… I installed python-switchbot with ssh. Someone could help me ?
I’m on python-switchbot site.
Thanks in advance
You can either use the aforementioned CURL command or you can use your switchbot app on your smart phone to find the MAC address. Both work.
If using the app on your phone, the MAC addresses you want will be from the front menu, click the item (e.g. door sensor, light bulb) and then select the gear icon (top right of screen) and look for the menu item “Device Info” - click that and you’re presented with the MAC address. HTH.
Doing this seems to break the official switchbot integration. It overwrites /usr/local/lib/python3.9/site-packages/switchbot/__init__.py with the one used by python-switchbot, so if you try to uninstall and install the official switchbot component again, it will fail.
How was it unreliable? I have a hub mini as part of the a recent combo sale and would prefer to take advantage of that rather than building an esp32 to mqtt bridge. I would expect their cloud API to be what they also use so it should be as reliable as their cloud options?