Skip to content

Instantly share code, notes, and snippets.

@mugifly mugifly/
Last active Oct 7, 2019

What would you like to do?
Simplest Switchbot Command

Simplest Switchbot Command


It tested on Raspberry Pi Zero W with Raspbian Stretch.

$ sudo apt-get install python-pip libglib2.0-dev bluez-tools
$ sudo pip install bluepy
$ sudo hciconfig hci0 down
$ sudo btmgmt le on
$ sudo hciconfig hci0 up


$ wget
$ chmod u+x

$ sudo hcitool lescan

$ ./ ff:ff:ff:ff:ff:ff on
$ ./ ff:ff:ff:ff:ff:ff off
$ ./ ff:ff:ff:ff:ff:ff press
#!/usr/bin/env python
# Simplest Switchbot Command
# Thanks to
import sys
import binascii
from bluepy.btle import Peripheral
if len(sys.argv) != 3:
print '[Usage] python %s ff:ff:ff:ff:ff:ff MODE' % sys.argv[0]
print '\nMODE: on, off, press'
print '\nYou can get a MAC address of Switchbot, with using $ sudo hcitool lescan'
mac = sys.argv[1]
mode = sys.argv[2]
print 'Connecting... ' + mac
p = Peripheral(mac, 'random')
hand_service = p.getServiceByUUID('cba20d00-224d-11e6-9fb8-0002a5d5c51b')
hand = hand_service.getCharacteristics('cba20002-224d-11e6-9fb8-0002a5d5c51b')[0]
if mode == 'on':
print 'On'
elif mode == 'off':
print 'Off'
elif mode == 'press':
print 'Press'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.