{"id":20368390,"url":"https://github.com/depau/consmart-ble-mqtt","last_synced_at":"2025-04-12T05:40:42.502Z","repository":{"id":72603469,"uuid":"234416859","full_name":"depau/consmart-ble-mqtt","owner":"depau","description":"Consmart/Triones/Flyidea BLE smart light to MQTT bridge","archived":false,"fork":false,"pushed_at":"2020-04-15T01:02:05.000Z","size":104,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T01:06:09.299Z","etag":null,"topics":["ble","bluetooth","bluez","china","china-all-the-way","consmart","flyidea","gatt","golang","iot","let-s-say-china","mqtt","mqtt-bridge","smart-lights","smarthome","spaghetti","spaghetti-code","triones"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/depau.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,"governance":null}},"created_at":"2020-01-16T21:37:50.000Z","updated_at":"2024-06-20T00:27:45.000Z","dependencies_parsed_at":"2023-05-24T15:45:07.990Z","dependency_job_id":null,"html_url":"https://github.com/depau/consmart-ble-mqtt","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/depau%2Fconsmart-ble-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depau%2Fconsmart-ble-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depau%2Fconsmart-ble-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/depau%2Fconsmart-ble-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/depau","download_url":"https://codeload.github.com/depau/consmart-ble-mqtt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248525162,"owners_count":21118617,"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":["ble","bluetooth","bluez","china","china-all-the-way","consmart","flyidea","gatt","golang","iot","let-s-say-china","mqtt","mqtt-bridge","smart-lights","smarthome","spaghetti","spaghetti-code","triones"],"created_at":"2024-11-15T00:40:52.245Z","updated_at":"2025-04-12T05:40:42.475Z","avatar_url":"https://github.com/depau.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Consmart/Triones/Flyidea BLE smart lights to MQTT bridge\n\n**Warning: crazy spaghetty code ahead**\n\nExposes Triones Bluetooth smart lights over MQTT.\n\nIt seems to work, reconnection does not however, due to a bug in go-bluetooth.\n\nAs a workaround it currently exits when one device disconnects, you can restart it.\nUse persistent messages when publishing control messages so changes are applied when\nit's back up.\n\n## Notes on Bluez\n\nBluez requires a small patch for some lights to work. In fact they do not comply with\nthe GATT protocol and send an error with a `0` error code, which bluez does not know\nhow to handle.\n\n[The patch](0001-Workaround-for-non-compliant-BLE-lights.patch) simply makes it ignore\nthe error, it should work just fine. The bluez team is still discussing how to handle\nsuch misbehaving devices.\n\n## Notes on Raspberry Pi\n\nBefore we start, I want you to be aware of this: Raspberry Pi is the worst thing humanity\never pulled off, the worst SBC on Earth, you should sell it or return it to Amazon ASAP\nand get a RockPro64 instead.\n\nLet that sink in.\n\nReally. If Broadcom makes something, you already know how stable it's going to be. But\nthe guys at Raspberry Pi didn't think it was unstable enough, so they decided it was a\ngood idea to use an SD card as the one and only storage device of the computer. That\nthing is a horrible nightmare and you should burn it.\n\nThat being said, I implemented a workaround in order to reset the Bluetooth chip when\nit goes woo-woo. It works on Arch Linux ARM with the mainline `aarch64` kernel, it\nmight need changes for other kernels.\n\n```\nmake raspi-mainline-reset-bt\nmake suid\n```\n\nThen add `reset_prog` as shown below to the configuration. The reset program will be\ncalled if needed right before the program exits after failure.\n\n## Configuration\n\n```yaml\n---\n#bluetooth:\n#  adapter: \"hci2\"                  # only needed if you don't want the default adapter\n#  reset_prog: \"path/to/executable\" # helper to reset Bluetooth in case it goes crazy\n\nmqtt:\n  mountpoint: \"kitchen/lights\"\n  servers:\n    - 'tcp://localhost:1883'\n    #- 'tcp://otherserver:1883'\n    #- 'ws://websocket:80'\n  client_id: 'blelight2mqtt'\n  #username: \"user\"\n  #password: \"password\"\n  #tls:  # do not add section if you don't want TLS\n  #  insecure_skip_verify: false\n\ndevices:\n  'DE:AD:BE:EF:D0:0D':\n    mountpoint: 'friendly_name/'\n```\n\n## Usage\n\n### Building\n\n```bash\ngo build\n```\n\n### Running\n\n```bash\n./consmart-ble-mqtt config.yml\n```\n\n## MQTT topics\n\n### Control\n\nThe light can be controlled by writing to topics under `{global_mountpoint}/{device_mountpoint}/control`.\nThere are 3 topics:\n\n#### `control/power`\n\n`on`/`off`\n\n#### `control/color`\n\nTakes an RGB color in the form `R,G,B`, for example `250,134,17` is a warm white.\n\nChannels can go up to 255, `255,255,255` is white.\n\nWhen saturation is zero (that is when all channels are set to the same value), the\nlight is set to use the dedicated white LEDs. White LEDs are brighter than the RGB ones.\n\nWhen the color is set to `0,0,0`, the light is turned off.\n\n#### `control/mode`\n\nTakes a value in the form `light_mode,speed`.\n\nAvailable modes are:\n\n- `smooth rainbow`\n- `pulsating red`\n- `pulsating green`\n- `pulsating blue`\n- `pulsating yellow`\n- `pulsating cyan`\n- `pulsating magenta`\n- `pulsating white`\n- `pulsating red/green`\n- `pulsating red/blue`\n- `pulsating green/blue`\n- `rainbow strobe`\n- `red strobe`\n- `green strobe`\n- `blue strobe`\n- `yellow strobe`\n- `cyan strobe`\n- `magenta strobe`\n- `white strobe`\n- `hard rainbow`\n\nBonus modes (not available in the app, but implemented by the lights):\n\n- `pulsating RGB`\n- `RGB strobe`\n- `hard RGB`\n\nSpeed can go from 1 to 31, and is **inversely proportional**. That is when it's\nset to 1 it's fast, when it's set to 31 you can barely see it changing.\n\nDon't ask me about it, ask the guys who made these shitty lights.\n\nExample: `smooth rainbow,3`\n\n\n### Status\n\nStatus is reported to `{global_mountpoint}/{device_mountpoint}/status`.\n\nFormat is the same as the control channels but with a few exceptions:\n\nMode may also report `white` and `rgb`, which are not settable with the control\ntopic. In order to set it to white mode, set the color to a color with no\nsaturation (such as white). In order to set it to RGB mode, simply set a color.\n\nWhen in `white` or `rgb` mode, the speed is not reported (it doesn't really make\nany sense).\n\nWhen a mode is enabled, the color changes are also reported as well roughly every\nsecond.\n\n## Unsupported features\n\nThere are some extra features that the lights support that have not been implemented:\n\n- Clock/date setting (for auto on/off)\n- Auto on/off\n- \"Passcode\"\n  - Yes, apparently if you reverse-engineer the app you can see that the SDK they\n    used supports setting a 4-digit passcode. It is unclear how it actually works,\n    it doesn't seem to be the Bluetooth pairing code, also it seems to me that it\n    might be resettable without even providing it.\n    It looks like if the passcode is set it tries to use one that's stored somewhere\n    on the phone, but if it fails it tries to reset it. 🤷\n    If this is not true it might actually be useful to make sure your neighbors\n    don't have fun with your lights, but luckily my neighbors are not that techy.\n\n## Troubleshooting\n\n### `unable to retrieve RGB characteristic for '...'`\n\nHave you rebuilt Bluez with my patch applied? See [Notes on Bluez](#notes-on-bluez)\n\n### `unable to check whether services were resolved for '...'`\n\nThat's usually not an issue, it sometimes takes up to 30 seconds to connect to a\nlightbulb.\n\nIf it doesn't connect after waiting a minute or so, try removing power to the\nlights for a few seconds and see if they come back to life.\n\n### `Input/output error`\n\nYour Bluetooth adapter is stuck. If you're using a Raspberry Pi, see\n[Notes on Raspberry Pi](#notes-on-raspberry-pi) for a workaround that doesn't\ninvolve rebooting it.\n\nOtherwise reboot or unplug-replug the adapter and restart the program.\n\n### Program exits after lights disconnect\n\nIf lights decide it's time for a break, or you remove power from the lights,\nthe program will try to handle it by exiting.\n\nThat is because the `go-bluetooth` library that's used under the hood never\nstops listening for notifications from the lights even after they disconnect,\ncausing a deadlock.\n\nIt will try to exit so you can have something else (i.e. a script or systemd)\nrestart it, and a new connection attempt will be performed.\n\n### Lights stop responding but they're still connected\n\nI haven't had many chances to debug this because it always happens after many\nhours. That usually goes away after power-cycling the lights externally and\nrestarting the program.\n\nI'm pretty sure this is the lights fault. I already regret buying these lights\nso if you want some reliable lights, get the IKEA ones. They're 4 times as\nexpensive but they work like a charm.\n\nI'm also working with some friends to build a modded dimmer and use it as a\ncheap `zigbee2mqtt`-compatible gateway. We're still at early stages but\ncheck that out: https://github.com/tradfree-mod\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepau%2Fconsmart-ble-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdepau%2Fconsmart-ble-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdepau%2Fconsmart-ble-mqtt/lists"}