All Projects → Betree → Magicblue

Betree / Magicblue

Licence: mit
💡 Unofficial Python API to control Magic Blue bulbs over Bluetooth

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Magicblue

Blinker Doc
blinker中文文档
Stars: ✭ 139 (+51.09%)
Mutual labels:  raspberry-pi, ble, iot
Web Bluetooth Terminal
Progressive Web Application for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 130 (+41.3%)
Mutual labels:  ble, iot, bluetooth
Rubble
(going to be a) BLE stack for embedded Rust
Stars: ✭ 292 (+217.39%)
Mutual labels:  ble, iot, bluetooth
Pedalinomini
Same features of Pedalino™ in a compact form.
Stars: ✭ 139 (+51.09%)
Mutual labels:  ble, iot, bluetooth
Johnny Five
JavaScript Robotics and IoT programming framework, developed at Bocoup.
Stars: ✭ 12,498 (+13484.78%)
Mutual labels:  raspberry-pi, iot, bluetooth
Platypush
A versatile and extensible platform for home and life automation with hundreds of supported integrations
Stars: ✭ 192 (+108.7%)
Mutual labels:  raspberry-pi, iot, bluetooth
Blynk Library
Blynk library for embedded hardware. Works with Arduino, ESP8266, Raspberry Pi, Intel Edison/Galileo, LinkIt ONE, Particle Core/Photon, Energia, ARM mbed, etc.
Stars: ✭ 3,305 (+3492.39%)
Mutual labels:  raspberry-pi, iot, bluetooth
Cutehmi
CuteHMI is an open-source HMI (Human Machine Interface) software written in C++ and QML, using Qt libraries as a framework. GitHub repository is a mirror!
Stars: ✭ 90 (-2.17%)
Mutual labels:  raspberry-pi, iot
Bthidhub
Bluetooth HID hub
Stars: ✭ 65 (-29.35%)
Mutual labels:  raspberry-pi, bluetooth
Rxbluetoothkotlin
Bluetooth low energy reactive framework for Android written in Kotlin
Stars: ✭ 68 (-26.09%)
Mutual labels:  ble, bluetooth
Ha Bt Proximity
Distributed Bluetooth Room Presence Sensor for Home Assistant
Stars: ✭ 77 (-16.3%)
Mutual labels:  raspberry-pi, bluetooth
Ble Midi For Android
MIDI over Bluetooth LE driver for Android 4.3 or later
Stars: ✭ 90 (-2.17%)
Mutual labels:  ble, bluetooth
Qdomyos Zwift
Zwift bridge for smart treadmills and bike/cyclette
Stars: ✭ 63 (-31.52%)
Mutual labels:  raspberry-pi, bluetooth
Blinker Library
An IoT Solution,Blinker library for embedded hardware. Works with Arduino, ESP8266, ESP32.
Stars: ✭ 1,095 (+1090.22%)
Mutual labels:  ble, iot
Phony
Easy to use bluetooth hands free telephony, with python
Stars: ✭ 57 (-38.04%)
Mutual labels:  raspberry-pi, bluetooth
Screenly Ose
The most popular digital signage project on Github!
Stars: ✭ 1,196 (+1200%)
Mutual labels:  raspberry-pi, iot
Pytile
📡 A simple Python API for Tile® Bluetooth trackers
Stars: ✭ 56 (-39.13%)
Mutual labels:  ble, bluetooth
Swiftygpio
A Swift library for hardware projects on Linux/ARM boards with support for GPIOs/SPI/I2C/PWM/UART/1Wire.
Stars: ✭ 1,188 (+1191.3%)
Mutual labels:  raspberry-pi, iot
Rxbluetoothkit
iOS & OSX Bluetooth library for RxSwift
Stars: ✭ 1,213 (+1218.48%)
Mutual labels:  ble, bluetooth
Rpieasy
Easy MultiSensor device based on Raspberry PI
Stars: ✭ 85 (-7.61%)
Mutual labels:  raspberry-pi, iot

MagicBlue Bulb

MagicBlue - Cheap bluetooth bulbs

Documentation Status

The Magic Bulb is, as far as I know, the cheapest bluetooth RGB light bulb on the market : you can get it for as low as ~8€/9$ on sites like Gearbest. It works pretty good and comes with mobile apps.

Unfortunately I haven't found any API or documentation for it, which is why I started this project.

There are multiple versions of the bulb, some of them may need development to be compatible with this project. If you have a different bulb version you can try to sniff bluetooth communications. Reverse-engineering information and pull requests are more than welcome 😺

Bulb Version
v6 v7 v8 v9 v10
Status ☑️ ☑️ ☑️
☑️ ☑️

Installation

HomeAssistant

If you want to use this project with HomeAssistant you'll need to install magicblue as described below then use the component available here: https://github.com/Betree/homeassistant-magicblue

MagicBlue is not compatible with Windows.

Linux

You must use python 3+ and have a proper Bluetooth 4.0 interface installed on your machine.

  • Prerequisite

    • Debian: sudo apt-get install libglib2.0-dev
    • Fedora: sudo dnf install glib2-devel
  • Install

    sudo pip3 install magicblue

    Library needs elevated permissions to use Bluetooth features. You can either run as root (required for magicblueshell), or give hcitool special capabilities (see this link)

Known errors

  • Bluepy not compiled (very common)

If you get an error like No such file or directory: '/usr/local/lib/python3.4/dist-packages/bluepy/bluepy-helper' or ERROR:magicblue.magicblueshell:Unexpected error with command "ls": Helper exited: this is a known bug in bluepy that sometimes doesn't get compiled when installed from Pypi. You can fix it by compiling the helper yourself : Go to the lib folder (usually /usr/local/lib/python3.5/dist-packages/bluepy-1.1.2-py3.5.egg/bluepy/ but could be different, especially if you're using a virtual env) and run sudo make (make should be enought for a virtual env).

More info: https://github.com/IanHarvey/bluepy/issues/158

  • Other errors

If you run into problems during devices listing or connect, try to follow this procedure to ensure your Bluetooth interface works correctly : How to use manually with Gatttool page

Usage

Python API

Check the API documentation

From shell

Script must be run as root.

You can always specify which bluetooth adapter (default: hci0) you want to use by specifying it with the -a option.

Using the interactive shell

Just launch magicblueshell as root user :

$ sudo magicblueshell
Magic Blue interactive shell v0.3.0
Type "help" for a list of available commands
> help
 ----------------------------
| List of available commands |
 ----------------------------
COMMAND         PARAMETERS                    DETAILS
-------         ----------                    -------
help                                          Show this help
list_devices                                  List Bluetooth LE devices in range
ls              //                            //
list_effects                                  List available effects
connect         mac_address or ID             Connect to light bulb
disconnect                                    Disconnect from current light bulb
set_color       name or hexadecimal value     Change bulb's color
set_warm_light  intensity[0.0-1.0]            Set warm light
set_effect      effect_name speed[1-20]       Set an effect
turn            on|off                        Turn on / off the bulb
read            name|device_info|date_time    Read device_info/datetime from the bulb
exit                                          Exit the script
> ls
Listing Bluetooth LE devices in range for 5 minutes.Press CTRL+C to stop searching.
ID    Name                           Mac address 
--    ----                           ----------- 
1     LEDBLE-1D433903                c7:17:1d:43:39:03
^C

> connect 1
INFO:magicblue.magicblueshell:Connected
> set_color red
> exit
Bye !

Passing command as an option

Script can also be used by command line (for example to include it in custom shell scripts):

usage: magicblueshell [-h] [-l LIST_COMMANDS] [-c COMMAND] [-m MAC_ADDRESS]
                      [-a BLUETOOTH_ADAPTER] [-b BULB_VERSION]

Python tool to control MagicBlue bulbs over Bluetooth

optional arguments:
  -h, --help            show this help message and exit
  -l LIST_COMMANDS, --list_commands LIST_COMMANDS
                        List available commands
  -c COMMAND, --command COMMAND
                        Command to execute
  -m MAC_ADDRESS, --mac_address MAC_ADDRESS
                        Device mac address. Must be set if command given in -c
                        needs you to be connected
  -a BLUETOOTH_ADAPTER, --bluetooth_adapter BLUETOOTH_ADAPTER
                        Bluetooth adapter name as listed by hciconfig
  -b BULB_VERSION, --bulb-version BULB_VERSION
                        Bulb version as displayed in the official app

So if you want to change the color of bulb with mac address "C7:17:1D:43:39:03", just run :

sudo magicblueshell -c 'set_color red' -m C7:17:1D:43:39:03

Contributing

To contribute to this repo, start with CONTRIBUTING.md then check open issues

The protocol isn't fully retro-engineered but Characteristics list page and How to use manually with Gatttool page should give you enough details to start working on your own implementation if you need to port this for another language / platform. On the research/bluetooth branch you'll also find capture of bluetooth packets exchanged between Android and the bulb (open hci_capture.log with Wireshark).

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].