I am currently setting up HA to try and centralise all the different systems I have in place.
One system I rely quite heavily on is the Switchbot Hub system (And the temperature/humidity sensors)
I know the current integration is only for local control of the Switchbot switches themselves but I am looking for something for the hubs.
In my setup, the HUBs connect to the thermometers and retrieve their info, but also act as IR blasters to control tv’s/air conditioners etc.
I have scouted around and cannot see anything, but there is an API that appears to be able to control all these types of devices, whilst its across the internet, its better than nothing.
as a new user of HA, writing a new integration using this API is well beyond my skill level, but wondered if anybody had any input?
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.