Skip to content

Instantly share code, notes, and snippets.

@ayman
Last active June 8, 2021 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayman/cc45be4bf30994f4c7c42b77bac300e1 to your computer and use it in GitHub Desktop.
Save ayman/cc45be4bf30994f4c7c42b77bac300e1 to your computer and use it in GitHub Desktop.
Control a LumeCubeAir from Python via BLE + bluepy.
from bluepy import btle
import struct
class LumeCube:
def __init__(self, mac):
self.mac = mac
self.SERVICE_UUID = "33826A4C-486A-11E4-A545-022807469BF0"
self.LIGHT_CHARACTERISTIC = "33826A4D-486A-11E4-A545-022807469BF0"
self.LIGHT_ON = struct.pack('>L', 0xFCA16400)
self.LIGHT_OFF = struct.pack('>L', 0xFCA00000)
def on(self):
self._cube = btle.Peripheral(self.mac, addrType=btle.ADDR_TYPE_RANDOM)
service = self._cube.getServiceByUUID(self.SERVICE_UUID)
self._ch = service.getCharacteristics(self.LIGHT_CHARACTERISTIC)[0]
self._ch.write(self.LIGHT_ON)
def off(self):
self._ch.write(self.LIGHT_OFF)
self._cube.disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment