All Projects → chvolkmann → govee_btled

chvolkmann / govee_btled

Licence: other
A Python wrapper for controlling a cheap Bluetooth RGB light bulb.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to govee btled

Rgb.net
The one-stop SDK for RGB-peripherals
Stars: ✭ 311 (+522%)
Mutual labels:  rgb, led
Blink1
Official software for blink(1) USB RGB LED by ThingM
Stars: ✭ 888 (+1676%)
Mutual labels:  rgb, led
Msirgb
Alternative to MSI Mystic Light for controlling motherboard LEDs, without the fixed 7 colour limitation.
Stars: ✭ 276 (+452%)
Mutual labels:  rgb, led
ioBroker.wled
IoBroker integration to WLED project
Stars: ✭ 22 (-56%)
Mutual labels:  rgb, led
RGB Audio Backlight
Arduino Sketch for controlling WS2812 RGB Led Strip + Audio Visualizer
Stars: ✭ 19 (-62%)
Mutual labels:  rgb, led
Arduino Rgb Tools
A arduino library with tools for controlling an RGB-LED
Stars: ✭ 37 (-26%)
Mutual labels:  rgb, led
Polychromatic
RGB lighting management front-end application for GNU/Linux. Powered by OpenRazer (but soon to be vendor agnostic)
Stars: ✭ 581 (+1062%)
Mutual labels:  rgb, led
acer-predator-turbo-and-rgb-keyboard-linux-module
Linux kernel module to support Turbo mode and RGB Keyboard for Acer Predator notebook series
Stars: ✭ 125 (+150%)
Mutual labels:  rgb, led
mqtt-dmx-controller
A simple ArtNet / DMX Controller with MQTT Interface 💡🎬
Stars: ✭ 48 (-4%)
Mutual labels:  rgb, led
RGB-Fusion-Tool-PS
Powershell that use RGB Fusion CLI to associate profiles with Windows Processes
Stars: ✭ 30 (-40%)
Mutual labels:  rgb, led
eruption
Realtime RGB LED Driver for Linux
Stars: ✭ 140 (+180%)
Mutual labels:  rgb, led
NeewerLite
NeewerLite is an un-official Neewer LED light control app for macOS.
Stars: ✭ 54 (+8%)
Mutual labels:  bluetooth, led
ruuvitag-demo
Demo of reading Bluetooth Low Energy sensor measurements of RuuviTag environmental sensors and feeding them to MQTT, a database and dashboards
Stars: ✭ 14 (-72%)
Mutual labels:  bluetooth
pigment
A powerful library that provides color-conversions, palette/scheme generation, color manipulation and many more features intended to provide a great UX.
Stars: ✭ 23 (-54%)
Mutual labels:  rgb
pybluez-examples
Example Bluetooth tasks using the Python PyBluez module
Stars: ✭ 59 (+18%)
Mutual labels:  bluetooth
Raspberry-Pi-Electricity-Monitor
Software for monitoring the electricity consumption of a home with a Raspberry Pi
Stars: ✭ 33 (-34%)
Mutual labels:  energy
deskbluez
Connects to a low energy actuator system via bluetooth and allows remote control via command line or internal managed interface.
Stars: ✭ 56 (+12%)
Mutual labels:  bluetooth
TM1637TinyDisplay
Arduino library to display numbers and text on a 4 and 6 digit 7-segment TM1637 display modules.
Stars: ✭ 23 (-54%)
Mutual labels:  led
BleLab
Bluetooth LE Lab - UWP application for interaction with BLE GATT devices
Stars: ✭ 68 (+36%)
Mutual labels:  bluetooth
Electronic-Cheat-Sheet-and-Schematics-MegaCollection
A lot of Files of various Electronic Shit that I have collected over the years. Cheatsheet, Schematics, Pinouts, Pdf, and More... Enjoy it ;)
Stars: ✭ 43 (-14%)
Mutual labels:  led

govee_btled

A Python wrapper for controlling a cheap Bluetooth RGB light bulb.

The LED in question is the Govee H6001 available for about 13€ on Amazon Germany. I also noticed that it is available under the name Minger H6001.

Installation

Requires Python 3.
Tested under Python 3.7 on Linux. Should also work for Windows.

pip install -U git+https://github.com/Freemanium/govee_btled

Usage

The wrapper uses pygatt to interface with Bluetooth and requires root permissions.

See __main__.py for a full example in action.

import time
from govee_btled import BluetoothLED

led = BluetoothLED('<your MAC here>')
led.set_state(True)
led.set_color('blue')
time.sleep(1)
led.set_color('#facd03')
time.sleep(1)
# The bulb seems to have a white-mode which uses cold/warm white LEDs instead of the RGB LEDs.
# Supply a value between -1 (warm) and 1 (cold)
led.set_color_white(-0.4)

Windows compatibility

While the wrapper has not been tested on Windows, you should be able to use it by replacing the backend pygatt uses internally.

import pygatt
led = BluetoothLED('<your MAC here>', bt_backend_cls=pygatt.BGAPIBackend)

Credit

  • Henje
    Major help in reverse engineering both Govee's app and the Bluetooth protocol.

Reverse engineering notes

The reverse engineering was done by analyzing the Bluetooth Low Energy communication between Govee's Android app and the LED.

Getting the traffic

Android has a developer feature that enables you to log and export Bluetooth traffic. Retrieving the dump is a bit different for Samsung phones, see this StackOverflow post. You can then pull the log with the Android debug bridge. This script pulls the latest log, in the case of Samsung phones

#!/bin/bash
# The last entry in the second-to-last row of (ls -l /sdcard/log)
filename=$(adb shell "ls -l /sdcard/log | grep snoop | tail -n 2 | head -n 1 | cut -d ' ' -f 9")
echo "Pulling $filename..."
adb pull "/sdcard/log/$filename"

To analyze the traffic, Wireshark was used. The following filter was helpful in understanding the protocol:

(btatt or btgatt) and (btatt.handle in {0x15 0x11}) and btatt.opcode == 0x52 and not (btatt.value[0] == 0xaa)
  • I noticed a lot of request-ack messages with handles 0x15 <--> 0x11 respectively. Hexcodes for RGB values recognizable, so I filtered those out.
  • Opcode 0x52 filters for write commands as we are only interested in the traffic we send.
  • There were two types of prefixes in these packets: 0xaa and 0x33, where 0x33 carried the RGB data.

I exported the dump as its own PCAP file and reopened it in Wireshark to export it as JSON. In order to make it easier to analyze the packets' payloads, I put every packet's payload in a row of a text file.

Analyzing the traffic

For this scenario

  1. the LED is turned on, then off, then on again
  2. the color is changed
  3. the brightness is changed
  4. the warm/cold-white slider in the app is used
  5. the LED is turned off again

This was mostly done with a delay of approx. 5 seconds in between to recognize the timestamps in Wireshark.

Sample snooped traffic:

33 01 01 000000 00 000000 000000000000000000 33
33 09 12 320503 00 000000 000000000000000000 1c
33 09 12 321103 00 000000 000000000000000000 08
33 01 00 000000 00 000000 000000000000000000 32
33 01 01 000000 00 000000 000000000000000000 33
33 09 12 322503 00 000000 000000000000000000 3c
33 05 02 ff0000 00 ff8912 000000000000000000 af
33 05 02 00ff00 00 ff8912 000000000000000000 af
33 05 02 0000ff 00 ff8912 000000000000000000 af
33 05 02 ffff00 00 ff8912 000000000000000000 50
33 05 02 8b00ff 00 ff8912 000000000000000000 24
33 05 02 00ffff 00 ff8912 000000000000000000 50
33 05 02 ffffff 00 ff8912 000000000000000000 af
33 04 7f 000000 00 000000 000000000000000000 48
33 04 2e 000000 00 000000 000000000000000000 19
33 04 14 000000 00 000000 000000000000000000 23
33 04 fe 000000 00 000000 000000000000000000 c9
33 05 02 ffffff 01 d7e2ff 000000000000000000 00
33 05 02 ffffff 01 ff932c 000000000000000000 8a
33 01 00 000000 00 000000 000000000000000000 32

Spaces were added according to how I understood the boundaries of the protocol.

  • 0x33 seems to be a command indicator (the only alternative value for the first byte is 0xaa)
  • The second byte seems identify the packet type
    • 0x01: power
    • 0x04: brightness
    • 0x05: color
  • The third byte differs based on type.
    • For power packets, it's a boolean indicating the power state.
    • For brightness packets, it corresponds to a uint8 brightness value.
    • For color packets, this indicates an operation mode. The app offers a microphone, a scenes and a manual mode (labeled "color" in the app). We are only interested in manual mode, which is 0x02.
  • Color packets now carry an RGB value, followed by a boolean and a second RGB value. The boolean seems to switch the set of LEDs used within the bulb. There is one set for RGB values and one for warm/cold-white values, where True corresponds to the warm/cold-white LEDs. When the flag is set, the first RGB value seems to be ignored and vice-versa. The values for warm/cold-white LEDs cannot be set arbitrarily. The slider within the app UI uses a list of hardcoded color codes. (thanks Henje!)
  • Zeropadding follows.
  • Finally, a checksum over the payload is calculated by XORing all bytes.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].