I’m working on replicating this and I get an error when I try to run the last line: (sudo pip install bluepy)

sudo apt-get update
sudo apt-get install python-pexpect
sudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev 
sudo apt-get install libudev-dev libical-dev libreadline-dev
sudo pip install bluepy
openhabian@openhabian:~ $ sudo pip install bluepy
sudo: pip: command not found

If I try to run the script, I’m getting “No module named bluepy.btle”

I have an RPi 3 that has Bluetooth, so I do not have a dongle.

I found the issue, used

sudo pip3 install bluepy

I spoke too soon, I still have an issue when I try to run the script from the Pi where is the Mac Address of my device:

openhabian@openhabian:~/python-host $ python switchbot.py <mac add> Press

Traceback (most recent call last):
  File "switchbot.py", line 17, in <module>
    from bluepy.btle import Scanner, DefaultDelegate

Hi all,

just FYI, OpenMQTTGateway has almost all (save for the Plug Mini) SwitchBot devices integrated into its BLE gateway, with the Bot control already directly implemented, and the Curtain control working by direct MQTT commands so far. The remaining SwitchBot devices are status read only, e.g. Motion Sensor, Contact Sensor …

So with a small ESP32 and OpenMQTTGateway installed on it this is fully compatible with the OpenHAB MQTT implementation, including auto-discovery.

The challenge is that the documentation is written for those who already understand it. It is not a tutorial on ‘how’ to do it. The original post was somewhat a step-by-step tutorial, but the issue is that it is now outdated, doesn’t work and no one seems to know how to fix it.

I use this gateway implementation which is pretty easy to use and also offers auto detection:

However I agree that a solution like this, even if easily configurable, is not something for everyone.

Apologies, I just assumed that with a web installation on an ESP32 would be quite easy, and then receiving MQTT states (stateTopic) for all the implemented SwitchBot devices, and being able to control them with MQTT commands (commandTopic) would be manageable with so many other MQTT tutorials already in the forum. But as DrRSatzteil stated above, it’s not for everyone, especially if there is no previous experience with MQTT.

Unfortunately, since I’m using all textual configurations, I’m not the best one to give an easy tutorial either, but a search for OpenMQTTGateway or the above mentioned gateway should come up with many results for other device’s implementations, adhering to the same paradigm. And once familiar with the general OpenHAB MQTT functionality it opens up a a wide range of future device possibilities, without the need for specific bindings or scripts.

EDIT - a tutorial has just been posted

No doubt if you have an ESP32, all the required pieces, and know how to use it, then it would be simple.

I have the same question. I’m using OH 3.2.0
I can’t find the Switchbot binding


thanks dietah for your post :+1:. Unfortunately I have problems with the deployment.

I’m using a Raspi 4B with Raspberry Pi OS (64-bit). On the Raspi, there are running OH and MQTT containers. I’m using Portainer for container administration. I have connected a z-Wave USB-stick and the EnOncean Pi module on GPIO of the Raspi. My plan is to use the internal Bluetooth interface on the Raspi to control Switchbot switches.

I tried the following according to your readme. I am listing everything in detail as I am still quite a beginner:

  1. Installing of the necessary Bluetooth libraries => worked well
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev
  1. Read out Bluetooth interface (i have changed Bluetooth to mini-UART because of the EnOcean Pi on the GPIO):
root@*******:~# ls -l /sys/class/bluetooth
insgesamt 0
lrwxrwxrwx 1 root root 0 10. Aug 01:19 hci0 -> ../../devices/platform/soc/fe215040.serial/tty/ttyS0/hci0

As far as I understand, Bluetooth is now on device /ttyS0/hci0

  1. Own directory created for the switchbot container
mkdir /opt/switchbot
  1. The docker-compose.yml is created in it (mode privileged: true and network_mode: host added):
version: '3.6'
    container_name: switchbot
    image: deetoreu/mqtt-switchbot
    restart: always
    privileged: true
      MQTT_HOST: "192.xxx.xxx.xxx"
      MQTT_PORT: 1883
      MQTT_USERNAME: xxxxx
      MQTT_PASSWORD: xxxxx
      MQTT_TOPIC: switchbot
      SCAN_DURATION: 5*1000
      DEVICE_LIST: "xx:xx:xx:xx:xx:xx,xx:xx:xx:xx:xx:xx"
      - "/dev/ttyS0"
      - "/dev/hci0"
      - "/dev/ttyS0/hci0"
    network_mode: host
      - ./volumes/switchbot/logs:/usr/src/app/logs
  1. Apply the container with:
docker-compose -f docker-compose.yml up -d

The switchbot container is running well according to Portainer. Unfortunately, I still don’t see any incoming topics from the Switchbot switch in the MQTT Explorer :confused:

I have also checked Bluetooth connections with

sudo bluetoothctl
agent on
scan on

The switchbot switches are listed and have good RSSI values. So I think that the Bluetooth connection generally works.

  1. In OH I created a generic MQTT thing, created an on-off switch as a channel and adapted the code for the value to be transferred:
UID: mqtt:topic:2e5f0240eb:Switchbottest
label: Switchbottest
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:2e5f0240eb
  - id: Switchbottest
    channelTypeUID: mqtt:switch
    label: Switchbottest
    description: ""
      commandTopic: /switchbottest
      stateTopic: /switchbottest
      off: switchbottest/switch/xx:xx:xx:xx:xx:xx/set off
      on: switchbottest/switch/xx:xx:xx:xx:xx:xx/set on

The topic with the values ​​arrives correctly at the MQTT broker.

Unfortunately, the Switchbot switch is not responding. Anyone have any ideas what could be wrongly configured? Are the topic settings in the .yml correct? Should the Switch also send it’s status (battery, linkquality) after operate with the Switchbot app?

Hello, is it possible to recover theaddon-binding.jar file somewhere because I don’t have the skills to compile it myself. thanks in advance.

am under openHAB 3.4.4 on an openhabian RPI4


Can you help me to do this because I am totally beginner. THANKS