{"id":21300355,"url":"https://github.com/sblibs/pyswitchbot","last_synced_at":"2026-03-13T21:03:13.973Z","repository":{"id":37549294,"uuid":"147250077","full_name":"sblibs/pySwitchbot","owner":"sblibs","description":"Library to control Switchbot over Bluetooth","archived":false,"fork":false,"pushed_at":"2025-05-12T17:52:32.000Z","size":491,"stargazers_count":124,"open_issues_count":23,"forks_count":52,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-05-15T17:05:19.442Z","etag":null,"topics":["bleak","bluetooth","home-assistant","switchbot"],"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/sblibs.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"Danielhiversen","custom":"http://paypal.me/dahoiv"}},"created_at":"2018-09-03T20:21:57.000Z","updated_at":"2025-05-14T21:53:13.000Z","dependencies_parsed_at":"2024-01-11T09:20:35.138Z","dependency_job_id":"84e3cc26-71da-4296-9693-4bf1b1dc3a51","html_url":"https://github.com/sblibs/pySwitchbot","commit_stats":{"total_commits":338,"total_committers":28,"mean_commits":"12.071428571428571","dds":"0.31360946745562135","last_synced_commit":"93ecb3aabd00285b396899f1a3e065e0cd7186ba"},"previous_names":["sblibs/pyswitchbot"],"tags_count":162,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblibs%2FpySwitchbot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblibs%2FpySwitchbot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblibs%2FpySwitchbot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sblibs%2FpySwitchbot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sblibs","download_url":"https://codeload.github.com/sblibs/pySwitchbot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384988,"owners_count":22062422,"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":["bleak","bluetooth","home-assistant","switchbot"],"created_at":"2024-11-21T15:15:03.719Z","updated_at":"2026-03-13T21:03:13.961Z","avatar_url":"https://github.com/sblibs.png","language":"Python","funding_links":["https://github.com/sponsors/Danielhiversen","http://paypal.me/dahoiv"],"categories":[],"sub_categories":[],"readme":"# pySwitchbot [![codecov](https://codecov.io/gh/sblibs/pySwitchbot/graph/badge.svg?token=TI027U5ISQ)](https://codecov.io/gh/sblibs/pySwitchbot)\n\nLibrary to control Switchbot IoT devices https://www.switch-bot.com/bot\n\n## Obtaining encryption key for Switchbot Locks\n\nUsing the script `scripts/get_encryption_key.py` you can manually obtain locks encryption key.\n\nUsage:\n\n```shell\n$ python3 get_encryption_key.py MAC USERNAME\nKey ID: XX\nEncryption key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n```\n\nWhere `MAC` is MAC address of the lock and `USERNAME` is your SwitchBot account username, after that script will ask for your password.\nIf authentication succeeds then script should output your key id and encryption key.\n\n## Examples:\n\n#### WoLock (Lock-Pro)\n\nUnlock:\n\n```python\nimport asyncio\nfrom switchbot.discovery import GetSwitchbotDevices\nfrom switchbot.devices import lock\nfrom switchbot.const import SwitchbotModel\n\nBLE_MAC=\"XX:XX:XX:XX:XX:XX\" # The MAC of your lock\nKEY_ID=\"XX\" # The key-ID of your encryption-key for your lock\nENC_KEY=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\" # The encryption-key with key-ID \"XX\"\nLOCK_MODEL=SwitchbotModel.LOCK_PRO # Your lock model (here we use the Lock-Pro)\n\n\nasync def main():\n    wolock = await GetSwitchbotDevices().get_locks()\n    await lock.SwitchbotLock(\n        wolock[BLE_MAC].device, KEY_ID, ENCRYPTION_KEY, model=LOCK_MODEL\n    ).unlock()\n\n\nasyncio.run(main())\n```\n\nLock:\n\n```python\nimport asyncio\nfrom switchbot.discovery import GetSwitchbotDevices\nfrom switchbot.devices import lock\nfrom switchbot.const import SwitchbotModel\n\nBLE_MAC=\"XX:XX:XX:XX:XX:XX\" # The MAC of your lock\nKEY_ID=\"XX\" # The key-ID of your encryption-key for your lock\nENC_KEY=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\" # The encryption-key with key-ID \"XX\"\nLOCK_MODEL=SwitchbotModel.LOCK_PRO # Your lock model (here we use the Lock-Pro)\n\n\nasync def main():\n    wolock = await GetSwitchbotDevices().get_locks()\n    await lock.SwitchbotLock(\n        wolock[BLE_MAC].device, KEY_ID, ENCRYPTION_KEY, model=LOCK_MODEL\n    ).lock()\n\n\nasyncio.run(main())\n```\n\n#### WoCurtain (Curtain 3)\n\n```python\nimport asyncio\nfrom pprint import pprint\nfrom switchbot import GetSwitchbotDevices\nfrom switchbot.devices import curtain\n\n\nasync def main():\n    # get the BLE advertisement data of all switchbot devices in the vicinity\n    advertisement_data = await GetSwitchbotDevices().discover()\n\n    for i in advertisement_data.values():\n        pprint(i)\n        print()  # print newline so that devices' data is separated visually\n\n    # find your device's BLE address by inspecting the above printed debug logs, example below\n    ble_address = \"9915077C-C6FD-5FF6-27D3-45087898790B\"\n    # get the BLE device (via its address) and construct a curtain device\n    ble_device = advertisement_data[ble_address].device\n    curtain_device = curtain.SwitchbotCurtain(ble_device, reverse_mode=False)\n\n    pprint(await curtain_device.get_device_data())\n    pprint(await curtain_device.get_basic_info())\n    await curtain_device.set_position(100)\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsblibs%2Fpyswitchbot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsblibs%2Fpyswitchbot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsblibs%2Fpyswitchbot/lists"}