{"id":24576461,"url":"https://github.com/k0rventen/avea","last_synced_at":"2026-05-17T02:01:08.605Z","repository":{"id":43331548,"uuid":"181440389","full_name":"k0rventen/avea","owner":"k0rventen","description":"Control Elgato's Avea bulb using python3 !","archived":false,"fork":false,"pushed_at":"2022-03-31T20:50:55.000Z","size":45,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-23T17:05:00.810Z","etag":null,"topics":["bluepy","bluetooth-low-energy","elgato-avea","hacktoberfest","python3","reverse-engineering"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/k0rventen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-15T08:02:52.000Z","updated_at":"2023-02-10T11:52:16.000Z","dependencies_parsed_at":"2022-07-12T18:18:55.913Z","dependency_job_id":null,"html_url":"https://github.com/k0rventen/avea","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0rventen%2Favea","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0rventen%2Favea/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0rventen%2Favea/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/k0rventen%2Favea/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/k0rventen","download_url":"https://codeload.github.com/k0rventen/avea/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250477811,"owners_count":21437049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bluepy","bluetooth-low-energy","elgato-avea","hacktoberfest","python3","reverse-engineering"],"created_at":"2025-01-23T22:39:13.112Z","updated_at":"2026-05-17T02:01:08.596Z","avatar_url":"https://github.com/k0rventen.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Control of an Elgato Avea bulb using Python\n\n[![PyPI](https://img.shields.io/pypi/v/avea.svg)](https://pypi.org/project/avea/)\n[![Build \u0026 Publish](https://github.com/k0rventen/avea/actions/workflows/python-publish.yml/badge.svg)](https://github.com/k0rventen/avea/actions/workflows/python-publish.yml)\n\n\nThe [Avea bulb from Elgato](https://www.amazon.co.uk/Elgato-Avea-Dynamic-Light-Android-Smartphone/dp/B00O4EZ11Q) is a light bulb that connects to an iPhone or Android app via Bluetooth.\n\nThis project aim to control it using a Bluetooth 4.0 compatible device and some Python magic.\n\nTested on Raspberry Pi 3 and Zero W (with integrated bluetooth). \n\n- [Control of an Elgato Avea bulb using Python](#control-of-an-elgato-avea-bulb-using-python)\n  - [TL;DR](#tldr)\n  - [Library usage](#library-usage)\n  - [Code documentation](#code-documentation)\n  - [Reverse engineering of the bulb](#reverse-engineering-of-the-bulb)\n  - [Communication protocol](#communication-protocol)\n    - [Intro](#intro)\n    - [Commands and payload explanation](#commands-and-payload-explanation)\n    - [Color command](#color-command)\n    - [Brightness command](#brightness-command)\n  - [Walkthrough \u0026 Example](#walkthrough--example)\n    - [Brightness](#brightness)\n      - [Color](#color)\n  - [Python implementation](#python-implementation)\n    - [One-liner for color computation](#one-liner-for-color-computation)\n    - [Bleak write\\_gatt\\_char usage](#bleak-write_gatt_char-usage)\n    - [Working with notifications using Bleak](#working-with-notifications-using-bleak)\n  - [TODO](#todo)\n\n## TL;DR\n\nThe lib requires [bleak](https://github.com/hbldh/bleak), so we must install the following dependency, whether we use pip or install from source.\n\n**Dependencies**\n\nEnsure your system Bluetooth stack is available (for example `bluez` on Linux or the built-in CoreBluetooth framework on macOS). The Python dependency `bleak` is installed automatically when using pip.\n\n**Then install from pip3**\n\n```bash\nsudo apt install python3-pip\nsudo pip3 install --upgrade avea\n```\n\n**or if you prefer installing from source**\n\n```bash\ngit clone https://github.com/k0rventen/avea\ncd avea\nsudo python3 setup.py install\n```\n\n## Library usage\n\nYou can check the example script `example.py`, to try it directly onto your bulbs :\n\n```bash\nsudo python3 example.py\n```\n\nBelow is a quick how-to of the various methods of the library.\n\n**Note : depending on your operating system configuration, Bluetooth discovery may require additional permissions (for example running with sudo on Linux or granting Bluetooth access on macOS).**\n\n```python\nimport avea # Important !\n\n# Get nearby bulbs in a list, then retrieve the name of all bulbs\n# discovery might require elevated privileges depending on the platform\nnearbyBulbs = avea.discover_avea_bulbs()\nfor bulb in nearbyBulbs:\n    bulb.get_name()\n    print(bulb.name)\n\n# Or create a bulb if you know its address (after a scan for example)\nmyBulb = avea.Bulb(\"xx:xx:xx:xx:xx:xx\")\n\n# You can set the brightness, color and name\nmyBulb.set_brightness(2000)                 # ranges from 0 to 4095\nmyBulb.set_color(0,4095,0,0)                # in order : white, red, green, blue\nmyBulb.set_rgb(0,255,0)                     # RGB compliant function\nmyBulb.set_smooth_transition(255,255,0,4,30)   # change to rgb(255,255,0) in 4s with 30 iterations per second\nmyBulb.set_name(\"bedroom\")                  # new name of the bulb\n\n# And get the brightness, color and name\nprint(myBulb.get_name())                # Query the name of the bulb\ntheColor = myBulb.get_color()           # Query the current color\ntheRgbColor = myBulb.get_rgb()          # Query the bulb in a RGB format\ntheBrightness = myBulb.get_brightness() # query the current brightness\ntheAddr = myBulb.addr                   # query the bulb Bluetooth addr\ntheFwVersion = myBulb.get_fw_version()  # query the bulb firmware version\ntheHardwareRevision = myBulb.get_hardware_revision()  # query the bulb hardware revision\ntheManufacturerName = myBulb.get_manufacturer_name()  # query the bulb manufacturer name\n```\n\nThat's it. Pretty simple.\n\nCheck the explanations below for more informations, or check the sources !\n\n\n## Code documentation\n\n## Reverse engineering of the bulb\n\nI've used the informations given by [Marmelatze](https://github.com/Marmelatze/avea_bulb) as well as some reverse engineering using a `btsnoop_hci.log` file from an Android device and Wireshark.\n\nBelow is a pretty thorough explanation of the BLE communication and the python implementation to communicate with the bulb.\n\nAs BLE communication is quite complicated, you might want to skip all of this if you just want to use the library. But it's quite interesting.\n\n\n## Communication protocol\n\n### Intro\n\nTo communicate the bulb uses Bluetooth 4.0 \"BLE\", which provide some interesting features for communications, to learn more about it go [here](https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt).\n\nTo sum up, the bulb emits a set of `services` which have `characteristics`. We use the latter to communicate to the device.\n\nThe bulb uses the service `f815e810456c6761746f4d756e696368` and the associated characteristic `f815e811456c6761746f4d756e696368` to send and receive informations about its state (color, name and brightness). We'll transmit over this characteristic.\n\n### Commands and payload explanation\n\nThe first bytes of transmission is the command. A few commands are available :\n\nValue | Command\n--- | ---\n0x35 | set / get bulb color\n0x57 | set / get bulb brightness\n0x58 | set / get bulb name\n\n### Color command\n\nFor the color command, the transmission payload is as follows :\n\nCommand | Fading time | Useless byte | White value | Red value | Green value | Blue value\n---|---|---|---|---|---|---\n\nEach value of the payload is a 4 hexadecimal value. (The actual values are integers between 0 and 4095)\n\nFor each color, a prefix in the hexadecimal value is needed :\n\nColor | prefix\n---|---\nWhite| 0x8000\nRed | 0x3000\nGreen | 0x2000\nBlue | 0X1000\n\nThe values are then formatted in **big-endian** format :\n\nInt | 4-bytes Hexadecimal | Big-endian hex\n---|---|---\n4095 | 0x0fff| **0xff0f**\n\n### Brightness command\n\nThe brightness is also an Int value between 0 and 4095, sent as a big-endian 4-bytes hex value. The transmission looks like this :\n\nCommand | Brightness value |\n---|---\n0x57 | 0xff00\n\n## Walkthrough \u0026 Example\n\nLet say we want the bulb to be pink at 75% brightness :\n\n### Brightness\n\n75% brightness is roughly 3072 (out of the maximum 4095):\n\nInt | 4-bytes Hexadecimal | **Big-endian hex**\n---|---|---\n3072 |0x0C00| **0x000C**\n\nThe brightness command will be `0x57000C`\n\n#### Color\n\nPink is 100% red, 100% blue, no green. (We assume that the white value is also 0.) For each color, we convert the int value to hexadecimal, then we apply the prefix, then we convert to big-endian :\n\nVariables | Int Values | Hexadecimal values | Bitwise XOR | Big-endian values\n---|---|---|---|---\nWhite| 0| 0x0000| 0x8000| 0x0080\nRed | 4095| 0x0fff| 0x3fff| 0xff3f\nGreen | 0 | 0x0000| 0x2000 | 0x0020\nBlue | 4095| 0x0fff | 0x1fff| 0xff1f\n\n\nThe final byte sequence for a pink bulb will be :\n\nCommand | Fading time | Useless byte | White value | Red value | Green value | Blue value\n---|---|---|---|---|---|---\n`0x35`|`1101`| `0000`| `0080`|`ff3f`|`0020`|`ff1f`\n\n\n## Python implementation\nBelow is some python3 code regarding various aspects that are quite interesting.\n\n### One-liner for color computation\nTo compute the correct values for each color, I created the following conversion (here showing for white) :\n\n```python\nwhite = (int(\u003cvalue\u003e) | int(0x8000)).to_bytes(2, byteorder='little').hex()\n```\n\n### Bleak write_gatt_char usage\nBleak lets us send raw binary payloads straight to a characteristic without any extra overrides. The library now prepares the payload as bytes and calls the client directly:\n\n```python\nawait client.write_gatt_char(CONTROL_CHARACTERISTIC_UUID, payload, response=False)\n```\n\n### Working with notifications using Bleak\nNotifications are enabled through `BleakClient.start_notify`. During the connection phase the library subscribes to the Avea control characteristic and routes every notification to a callback that updates the cached bulb state. Synchronous getters wait on an `asyncio.Event` that is set when the expected command is received, keeping the public API blocking while leveraging bleak under the hood.\n\n## TODO\n- Reverse engineer the `ambiances` (which are mood-based scenes).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk0rventen%2Favea","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fk0rventen%2Favea","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fk0rventen%2Favea/lists"}