Switchbot HUB integration

Hi all

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?

The API is available https://github.com/OpenWonderLabs/SwitchBotAPI

7 Likes

This only applies to the switches (which I don’t use) I use the Hubs which are IR blasters, but also connect via bluetooth to the thermometers.

I have connected the thermometers via a RPI running sbm2mqtt and that works well, but being able to control the devices would be great!

+1 for Switchbot Hub integration.

10 Likes

I’m also very interested in this as the hub can control various devices over IR, and it would be great to have them in HA.

There seem to be a python library already in progress to use this API: https://github.com/jonghwanhyeon/python-switchbot this could be used for the integration, as directly interacting with the API from a HA integration is generally discouraged

1 Like

I’d love to have Switchbot hub integrated in HA. Currently I trigger IR commands by calling Alexa (who can talk to the hub) routines from HA.

3 Likes

Has there been any update on this? Love to see it integrated. :slight_smile:

2 Likes

Any update?

definitely a push! hopefully someone will take care of it :smiley: I am unfortunately not able to…

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:

  1. Download the SwitchBot app on App Store or Google Play Store
  2. Register a SwitchBot account and log in into your account
  3. 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
  4. Now you have the token to use with the switchbot API (see below)
  5. 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
  6. Install Pyscript integration
  7. 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)
from switchbot import SwitchBot

@pyscript_executor
def switchfunction():
	your_switch_bot_token = '<COPY YOUR TOKEN HERE>'
	switchbot = SwitchBot(token=your_switch_bot_token)
	device = switchbot.device(id='deviceID')
	device.command('press')

@service
def switch1():
    switchfunction()
  1. Restart HA (perhaps not needed, but I did)
  2. You will now have a service called pyscript.switch1 that you can use to make the switchbot press once.

From here you can tinker around to add more functions as you need.

Sources used:

2 Likes

Is it also possible to connect a HA thermostat to this?

Isn’t the API limit a huge problem?

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.

Complete garbage.

1 Like

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

‘’’
from switchbot import SwitchBot

@pyscript_executor
def switchfunction():
your_switch_bot_token = ‘’
switchbot = SwitchBot(token=your_switch_bot_token)
device = switchbot.device(id=‘deviceID’)
device.command(‘press’)

@service
def switch1():
switchfunction()
‘’’

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”

dont see the service im supposed to call

Log showing me this
Exception in </config/pyscript/switch.py> line 1: from switchbot import SwitchBot ^ AttributeError: module ‘switchbot’ has no attribute ‘SwitchBot’

8:01:13 PM – (ERROR) Pyscript Python scripting (custom integration)

I think you need to install switchbot:

pip install python-switchbot

yes of course i did, just like your instructions said

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

6 Likes

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 :slight_smile:

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.