Switchbot HUB integration

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

7 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.

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.

See this: Switchbot intergration not working after 2022.4.7

1 Like

I stopped with the integration I described here as it was way to unreliable. I switched to SwitchBot bot/curtain/meter/contact/motion MQTT ESP32 bridge - Local control - Share your Projects! - Home Assistant Community (home-assistant.io) and that one works so much more reliable.

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?

The actual click would be more or less a 50% chance to work. So if I told Home Assistant to click, it sometimes worked and sometimes didn’t.

it actually worked nicely
just the recent update broke it somehow
cant get it to work again

news for ir command?

I am the same, but I have fully returned to the ESP32 solution. Anything else so far just seems to sporadically fail for me. From being slow to respond to simply stopping to function and not responding at all. Every update it seems to improve, but not to a level it for my setup at least can be depended upon enough.

ok so my first question is do you have the switchbot hub, second do you use the hub to control any ir devices, as the ir devices have virtual ids (device ids). i am not able to figure out how to get the ir devices intgerated which have been configured via the hub.

1 Like

if it can be helpful: Switch-Bot API integration - #117 by SiriosDev

For any of you out there still struggling, I finally managed to get the original pyscript method to work (credit to @john2014) without the need for an MQTT ESP32 bridge. This method takes advantage of the shell_commands in HASS and fixes the default switchbot python package that comes with the HASS python on start. Here are the steps:

  • assuming you’ve already installed pyscript, a tutorial for which you can find here: pyscript
  • note that this is HASS running in docker. This is not HASS OS nor am I a HACS user.

1) Create the .py script inside the /config/pyscript folder and ensure that you have the following at the top of your code:

import switchbot
from switchbot import SwitchBot

2) after this code, you can then type the now switchbot code you need. For example (my code turns a projector on or off):

@pyscript_executor
def switchfunction():
	your_switch_bot_token = 'YOUR_TOKEN' #replace with the token you generated in the SwitchBot app
	your_switch_bot_secret = 'YOUR_SECRET_KEY' #replace with the secret key you generated in the SwitchBot app
	switchbotter = SwitchBot(token=your_switch_bot_token, secret=your_switch_bot_secret)
	remote = switchbotter.remote(id='THE_ID_OF_THE_REMOTE') #replace with the ID of your remote
	remote.turn('off')

@service
def projector_power():	
	switchfunction()

Now we take care of the python packages issue

3) Create a new automation that will execute 4 shell commands on every start of HASS. Here is the yaml for that automation:

alias: Start Python Packages #rename to your liking
description: ""
trigger:
  - platform: homeassistant #rename if yours has a different name
    event: start
condition: []
action:
  - service: shell_command.restart #the text after the dot should match the configuration.yaml file
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 20 #waits for 20 seconds to give the bash ample time to run. If your machine is powerful, feel free to reduce
      milliseconds: 0
  - service: shell_command.restart1 #the text after the dot should match the configuration.yaml file
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 20 #waits for 20 seconds to give the bash ample time to run. If your machine is powerful, feel free to reduce
      milliseconds: 0
  - service: shell_command.restart2 #the text after the dot should match the configuration.yaml file
    data: {}
  - service: pyscript.reload
    data: {}
mode: single

4) Change your configuration.yaml file to include the following:

shell_command:
  restart: pip uninstall pyswitchbot -y #the text before the colon should match the automation text after the dot
  restart1: pip uninstall python_switchbot -y #the text before the colon should match the automation text after the dot
  restart2: pip install python-switchbot #the text before the colon should match the automation text after the dot

5) Once you restart homeassistant, your pyscript @service (in my case “projector_power”) should now be available to be called as a service inside HASS. The rest has already been taken care of, so I won’t explain it. I will only remind you that the most important thing to do is make sure your configuration.yaml file includes the following code:

pyscript:
   allow_all_imports: true

Hope this helps :slight_smile: Works flawlessly for me. I am running this on an RPi4B within docker

2 Likes

Hi, I started developing an Integration.

This get the switchbot devices (only remote) and create entities on HA.

Have a look here: GitHub - KiraPC/ha-switchbot-remote

Appreciate the interest and work put in to getting started on an integration @KiraPC . Just replying to let you know I’ve got it installed and will be keeping an eye on progress. I have one device configured on the Hub Mini, and the integration finds the device to configure, but when I hit submit the “Configure Device” window after is empty. Just the title and submit button.

Thanks again for getting this up and going!!

Hi @djdubd please report an issue on the repository so I can analyze it. Maybe if you have also the information about how the devices is configured on switchbot and its type.

Hi, @KiraPC. This looks pretty good so far. Is it local or cloud based? Fairly new to HA and not sure, but I want to keep things locally controlled as much as possible.

Hello @TopHatTurtle this has to be cloud based because the hub does not expose local APIs