Skip to content

Instantly share code, notes, and snippets.

@aerialist
Created May 1, 2017 11:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aerialist/163a5794e95ccd28dc023161324009ed to your computer and use it in GitHub Desktop.
Save aerialist/163a5794e95ccd28dc023161324009ed to your computer and use it in GitHub Desktop.
Activate switchbot by python with bluepy on Raspberry Pi
# Activate switchbot by python with bluepy on Raspberry Pi
# https://github.com/IanHarvey/bluepy
#
# Switchbot's API is taken from this
# https://github.com/OpenWonderLabs/python-host
import binascii
from bluepy.btle import Peripheral
# find your switchbot address by
# pi@raspberry:~ $ sudo hcitool lescan
# replace "ff:..:ff"
p = Peripheral("ff:ff:ff:ff:ff:ff", "random")
hand_service = p.getServiceByUUID("cba20d00-224d-11e6-9fb8-0002a5d5c51b")
hand = hand_service.getCharacteristics("cba20002-224d-11e6-9fb8-0002a5d5c51b")[0]
hand.write(binascii.a2b_hex("570100"))
p.disconnect()
@vladeha
Copy link

vladeha commented Mar 7, 2021

same thing...no luck. does anyone have a solution to this problem?

@remko2000
Copy link

I follow

@EngineeredEntropy
Copy link

Try entering your mac address with all lowercase letters, fixed this issue for me.

@scargill
Copy link

scargill commented Apr 8, 2022

I can't even get that far on my RPI4 - I just entered the code as above but chaning my MAC number - no mistakes - yet...

pi@mainpi:~:11:46[0]> ./switchbot_bluepi.py
./switchbot_bluepi.py: line 7: import: command not found
from: too many arguments
./switchbot_bluepi.py: line 13: syntax error near unexpected token `('
./switchbot_bluepi.py: line 13: `p = Peripheral("fb:ff:1f:00:4d:aa", "random")'
pi@mainpi:~:11:46[2]>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment