{"id":17053498,"url":"https://github.com/yeemachine/magicblue","last_synced_at":"2025-03-23T05:24:28.560Z","repository":{"id":107657272,"uuid":"165458603","full_name":"yeemachine/magicblue","owner":"yeemachine","description":"Control Magicblue Smart Bulbs over Web Bluetooth","archived":false,"fork":false,"pushed_at":"2020-05-22T14:31:11.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T11:49:09.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://magicblue.glitch.me/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yeemachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-13T02:44:15.000Z","updated_at":"2024-06-06T20:04:10.000Z","dependencies_parsed_at":"2023-03-25T20:34:52.522Z","dependency_job_id":null,"html_url":"https://github.com/yeemachine/magicblue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeemachine%2Fmagicblue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeemachine%2Fmagicblue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeemachine%2Fmagicblue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yeemachine%2Fmagicblue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yeemachine","download_url":"https://codeload.github.com/yeemachine/magicblue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245059707,"owners_count":20554344,"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":[],"created_at":"2024-10-14T10:12:27.781Z","updated_at":"2025-03-23T05:24:28.545Z","avatar_url":"https://github.com/yeemachine.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magicblue.js\n\n**Control Magicblue Smart Bulbs over Web Bluetooth**\n\n![Light Demo](https://cdn.glitch.com/00fa2c64-1159-440f-ad08-4b1ef2af9d8b%2Fmagicbluedemo.gif)\n\nThis is a small project aimed at reverse engineering one of the [cheaper Bluetooth lightbulbs](https://www.gearbest.com/smart-light-bulb/pp_230349.html) out there and controlling it directly through a browser without the official app. As of writing this, **Web Bluetooth is only supported in Chrome**. \n\nThere are multiple versions of the **Magicblue** bulb that are floating around. It's possible some versions are configured slightly differently and need further developement. I personally used [this bulb](https://www.amazon.com/Magic-Light-Bluetooth-Smart-Bulb/dp/B00Y6X93EQ?ref_=bl_dp_s_web_9321634011\u0026th=1) for my experiments.\n\nI began the project by reading [Urish's Medium post](https://medium.com/@urish/reverse-engineering-a-bluetooth-lightbulb-56580fcb7546) and later referenced [Betree's unofficial python library](https://github.com/Betree/magicblue) for more specific bluetooth commands and schedule/status formats.\n\n#### Compatibility\nI haven't yet tested all Magicblue bulb versions. But V6-V10 bulbs should work. \nV1 is still unstable, being unable to set schedule. May come back to it in the future.\n\n![Connect Demo](https://cdn.glitch.com/00fa2c64-1159-440f-ad08-4b1ef2af9d8b%2Fmagicblue-connect.gif)\n![Options Demo](https://cdn.glitch.com/00fa2c64-1159-440f-ad08-4b1ef2af9d8b%2Fmagicblue-options.gif)\n![Controller Demo](https://cdn.glitch.com/00fa2c64-1159-440f-ad08-4b1ef2af9d8b%2Fmagicblue-controller.gif)\n\n## Usage\nYou can view the demo [here](https://magicblue.glitch.me) or remix your own project with the button below.\n\n[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/remix/magicblue)\n\nInitialize click events for the Bluetooth Device Navigator. Can also be triggered manually using the magicblue.search() method.\n```js\nmagicblue.init('.connect-button, .connect-another button') \n```\nListens for when a new device is connected. Returns the device name.\n```js\nmagicblue.on('connected', (device) =\u003e {\n  console.log(device + ' is connected.');\n  someAction()\n  magicblue.request('status,schedule',device) \n});\n```\nListens for when a notification is received. Returns an object with the device name as well as type of notification (status/schedule).\n```js\nmagicblue.on('receiveNotif', function (e) {\n  let deviceName = e.device\n  let notifType = e.type\n  let notifObj = magicblue[notifType][deviceName]\n  console.log(notifObj);\n});\n```\nListens for when a device is disconnected. Returns the device name as well as the current state (disconnected/reconnected).\n```js\nmagicblue.on('disconnected', function (e) {\n  console.log(e.device+' is '+e.state+'.');\n});\n```\nPublic properties that will return info on all connected devices. Status and Schedules will need to be requested first.\n```js\nmagicblue.devices\nmagicblue.status\nmagicblue.schedule\n```\nSome example functions that can be used after connected. See API section for more detailed params and defaults. \n```js\nmagicblue.turnOn()\nmagicblue.turnOff()\nmagicblue.turnOnOff()\nmagicblue.setRGB('255,0,0')\nmagicblue.setWhite(255)\nmagicblue.setEffect('seven_color_stobe_flash')\nmagicblue.setSchedule(scheduleList)\nmagicBlue.request('status')\n```\n[![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/remix/magicblue)\n\n## API\n### Properties\n| Name          | Type          | Format        | Description   |\n| ------------- | ------------- | ------------- | ------------- |\n| DICT          | Object        | {name:\u003ccode\u003edecimal\u003c/code\u003e} | Returns an object containing Bluetooth Hexcodes for Magicblue Smart Bulbs as reference. |\n| devices       | Object        | {deviceName:\u003ccode\u003eBluetoothDevice\u003c/code\u003e} | Returns an object containing all connected devices |\n| chars         | Object        | {deviceName:\u003ccode\u003eBluetoothRemoteGATTCharacteristic\u003c/code\u003e }| Returns an object containing write characteristics from all connected devices |\n| status        | Object        | {deviceName:{\u003cbr\u003eon:\u003ccode\u003etrue\\|false\u003c/code\u003e,\u003cbr\u003emode:\u003ccode\u003e'white'\\|'rgb'\\|'effect'\\|'sunrise'\u003c/code\u003e,\u003cbr\u003ergb:\u003ccode\u003e[r,g,b]\u003c/code\u003e,\u003cbr\u003ewhite:\u003ccode\u003e0-\u003e255\u003c/code\u003e,\u003cbr\u003eeffect:\u003ccode\u003e'preset_effect'\u003c/code\u003e,\u003cbr\u003espeed:\u003ccode\u003e1-\u003e20\u003c/code\u003e}\u003cbr\u003e} | Returns an object containing the status from all connected devices |\n| schedule      | Object        | {deviceName:[\u003cbr\u003e{repeat:\u003ccode\u003etrue\\|false\u003c/code\u003e,\u003cbr\u003erepeatDays:\u003ccode\u003e['monday -\u003e sunday']\u003c/code\u003e,\u003cbr\u003eyear:\u003ccode\u003e20XX\u003c/code\u003e,\u003cbr\u003emonth:\u003ccode\u003e1-\u003e12\u003c/code\u003e,\u003cbr\u003eday:\u003ccode\u003e1-\u003e31\u003c/code\u003e,\u003cbr\u003emode:\u003ccode\u003e'white'\\|'rgb'\\|'effect'\u003c/code\u003e,\u003cbr\u003estart:\u003ccode\u003e0-\u003e255\u003c/code\u003e,\u003cbr\u003eend:\u003ccode\u003e0-\u003e255\u003c/code\u003e,\u003cbr\u003espeed:\u003ccode\u003e1-\u003e120(minutes) \\| 1-\u003e20(effect speed)\u003c/code\u003e,\u003cbr\u003ergb:\u003ccode\u003e[r,g,b]\u003c/code\u003e,\u003cbr\u003eeffect:\u003ccode\u003e'preset_effect'\u003c/code\u003e,}\u003cbr\u003e]} | Returns an object containing an array of schedules from all connected devices. Max 6 schedules set per device. |\n| reconnect     | Boolean       | Default:\u003ccode\u003efalse\u003c/code\u003e | Toggle ability to auto-reconnect disconnected devices|\n| DEBUG         | Boolean       | Default:\u003ccode\u003efalse\u003c/code\u003e | Toggle Console Logs|\n\n\n### Methods\n| Name          | Params        | Defaults      | Description   |\n| ------------- | ------------- | ------------- | ------------- |\n| on            | ('connecting'\\|'connected'\\|'disconnected'\\|'receiveNotif',callback)| N/A | Event listener for when device is connected, disconnected, or sends notification.|\n| init          | ('domElement1, domElement2')| N/A | Adds search() to all DOM elements provided as a string separated by ','. |\n| search        | N/A           | N/A           | Initiates navigator.requestDevice to search for devices. Must be fired on user interaction. |\n| request       | ('status, schedule', deviceNames)| (Status and Schedule, All Connected Devices)| Sends a request for device status, schedule, or both, provided by a string separated by ','. |\n| disconnect    | (deviceNames)| (All Connected Devices)   | Disconnect a bluetooth device. |\n| turnOn        | (deviceNames)| (All Connected Devices)   | Turns on selected devices. |\n| turnOff       | (deviceNames)| (All Connected Devices)   | Turns off selected devices. |\n| turnOnOff     | (deviceNames)| (All Connected Devices)   | Toggles ON/OFF based on state of first device in array.|\n| setRGB        | ('r,g,b', deviceNames)| (N/A, All Connected Devices) | Sets RGB color.|\n| setWhite  | (intensity, deviceNames)| (255, All Connected Devices) | Sets Warm White color with desired intensity (0-255).|\n| setEffect     | (effectName, speed, deviceNames)| ('seven_color_cross_fade', 1, All Connected Devices) | Set a preset pattern and speed (1-20).\n| setSchedule   | (newScheduleArray, deviceNames)| (oldScheduleArray, All Connected Devices) | Sets a timer schedule for each device. Can choose between single-use and repeating timers. Actions include adjusting brightness for Warm White color scheme, setting a particular RGB value, or a factory preset effect. |\n\n\n### Preset Effects\n```js\nseven_color_cross_fade\nred_gradual_change\ngreen_gradual_change\nblue_gradual_change\nyellow_gradual_change\ncyan_gradual_change\npurple_gradual_change\nwhite_gradual_change\nred_green_cross_fade\nred_blue_cross_fade\ngreen_blue_cross_fade\nseven_color_stobe_flash\nred_strobe_flash\ngreen_strobe_flash\nblue_strobe_flash\nyellow_strobe_flash\ncyan_strobe_flash\npurple_strobe_flash\nwhite_strobe_flash\nseven_color_jumping_change\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeemachine%2Fmagicblue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyeemachine%2Fmagicblue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyeemachine%2Fmagicblue/lists"}