{"id":13537580,"url":"https://github.com/mjg59/python-broadlink","last_synced_at":"2025-05-13T18:10:59.018Z","repository":{"id":37458168,"uuid":"68303993","full_name":"mjg59/python-broadlink","owner":"mjg59","description":"Python module for controlling Broadlink RM2/3 (Pro) remote controls, A1 sensor platforms and SP2/3 smartplugs","archived":false,"fork":false,"pushed_at":"2024-08-04T18:25:33.000Z","size":408,"stargazers_count":1447,"open_issues_count":80,"forks_count":483,"subscribers_count":95,"default_branch":"master","last_synced_at":"2025-04-25T15:48:35.091Z","etag":null,"topics":[],"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/mjg59.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}},"created_at":"2016-09-15T15:00:33.000Z","updated_at":"2025-04-22T11:52:36.000Z","dependencies_parsed_at":"2022-07-12T14:03:40.219Z","dependency_job_id":"b89ea325-a10d-477e-a8a9-94c8b3b79404","html_url":"https://github.com/mjg59/python-broadlink","commit_stats":{"total_commits":266,"total_committers":79,"mean_commits":3.367088607594937,"dds":0.631578947368421,"last_synced_commit":"3c183eaaef6cbaf9c1154b232116bc130cd2113f"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjg59%2Fpython-broadlink","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjg59%2Fpython-broadlink/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjg59%2Fpython-broadlink/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mjg59%2Fpython-broadlink/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mjg59","download_url":"https://codeload.github.com/mjg59/python-broadlink/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000854,"owners_count":21997442,"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-08-01T09:01:00.666Z","updated_at":"2025-05-13T18:10:58.983Z","avatar_url":"https://github.com/mjg59.png","language":"Python","readme":"# python-broadlink\n\nA Python module and CLI for controlling Broadlink devices locally. The following devices are supported:\n\n- **Universal remotes**: RM home, RM mini 3, RM plus, RM pro, RM pro+, RM4 mini, RM4 pro, RM4C mini, RM4S, RM4 TV mate\n- **Smart plugs**: SP mini, SP mini 3, SP mini+, SP1, SP2, SP2-BR, SP2-CL, SP2-IN, SP2-UK, SP3, SP3-EU, SP3S-EU, SP3S-US, SP4L-AU, SP4L-EU, SP4L-UK, SP4M, SP4M-US, Ankuoo NEO, Ankuoo NEO PRO, Efergy Ego, BG AHC/U-01\n- **Switches**: MCB1, SC1, SCB1E, SCB2\n- **Outlets**: BG 800, BG 900\n- **Power strips**: MP1-1K3S2U, MP1-1K4S, MP2\n- **Environment sensors**: A1\n- **Alarm kits**: S1C, S2KIT\n- **Light bulbs**: LB1, LB26 R1, LB27 R1, SB800TD\n- **Curtain motors**: Dooya DT360E-45/20\n- **Thermostats**: Hysen HY02B05H\n- **Hubs**: S3\n\n## Installation\n\nUse pip3 to install the latest version of this module.\n\n```\npip3 install broadlink\n```\n\n## Basic functions\n\nFirst, open Python 3 and import this module.\n\n```\npython3\n```\n```python3\nimport broadlink\n```\n\nNow let's try some functions...\n\n### Setup\n\nIn order to control the device, you need to connect it to your local network. If you have already configured the device with the Broadlink app, this step is not necessary.\n\n1. Put the device into AP Mode.\n  - Long press the reset button until the blue LED is blinking quickly.\n  - Long press again until blue LED is blinking slowly.\n  - Manually connect to the WiFi SSID named BroadlinkProv.\n2. Connect the device to your local network with the setup function.\n```python3\nbroadlink.setup('myssid', 'mynetworkpass', 3)\n```\n\nSecurity mode options are (0 = none, 1 = WEP, 2 = WPA1, 3 = WPA2, 4 = WPA1/2)\n\n#### Advanced options\n\nYou may need to specify a broadcast address if setup is not working.\n```python3\nbroadlink.setup('myssid', 'mynetworkpass', 3, ip_address='192.168.0.255')\n```\n\n### Discovery\n\nUse this function to discover devices:\n\n```python3\ndevices = broadlink.discover()\n```\n\n#### Advanced options\nYou may need to specify `local_ip_address` or `discover_ip_address` if discovery does not return any devices.\n\nUsing the IP address of your local machine:\n```python3\ndevices = broadlink.discover(local_ip_address='192.168.0.100')\n```\n\nUsing the broadcast address of your subnet:\n```python3\ndevices = broadlink.discover(discover_ip_address='192.168.0.255')\n```\n\nIf the device is locked, it may not be discoverable with broadcast. In such cases, you can use the unicast version `broadlink.hello()` for direct discovery:\n```python3\ndevice = broadlink.hello('192.168.0.16')\n```\n\nIf you are a perfomance freak, use `broadlink.xdiscover()` to create devices instantly:\n```python3\nfor device in broadlink.xdiscover():\n    print(device)  # Example action. Do whatever you want here.\n```\n\n### Authentication\nAfter discovering the device, call the `auth()` method to obtain the authentication key required for further communication:\n```python3\ndevice.auth()\n```\n\nThe next steps depend on the type of device you want to control.\n\n## Universal remotes\n\n### Learning IR codes\n\nLearning IR codes takes place in three steps.\n\n1. Enter learning mode:\n```python3\ndevice.enter_learning()\n```\n2. When the LED blinks, point the remote at the Broadlink device and press the button you want to learn.\n3. Get the IR packet.\n```python3\npacket = device.check_data()\n```\n\n### Learning RF codes\n\nLearning RF codes takes place in six steps.\n\n1. Sweep the frequency:\n```python3\ndevice.sweep_frequency()\n```\n2. When the LED blinks, point the remote at the Broadlink device for the first time and long press the button you want to learn.\n3. Check if the frequency was successfully identified:\n```python3\nok = device.check_frequency()\nif ok:\n    print('Frequency found!')\n```\n4. Enter learning mode:\n```python3\ndevice.find_rf_packet()\n```\n5. When the LED blinks, point the remote at the Broadlink device for the second time and short press the button you want to learn.\n6. Get the RF packet:\n```python3\npacket = device.check_data()\n```\n\n#### Notes\n\nUniversal remotes with product id 0x2712 use the same method for learning IR and RF codes. They don't need to sweep frequency. Just call `device.enter_learning()` and `device.check_data()`.\n\n### Canceling learning\n\nYou can exit the learning mode in the middle of the process by calling this method:\n```python3\ndevice.cancel_sweep_frequency()\n```\n\n### Sending IR/RF packets\n```python3\ndevice.send_data(packet)\n```\n\n### Fetching sensor data\n```python3\ndata = device.check_sensors()\n```\n\n## Switches\n\n### Setting power state\n```python3\ndevice.set_power(True)\ndevice.set_power(False)\n```\n\n### Checking power state\n```python3\nstate = device.check_power()\n```\n\n### Checking energy consumption\n```python3\nstate = device.get_energy()\n```\n\n## Power strips\n\n### Setting power state\n```python3\ndevice.set_power(1, True)  # Example socket. It could be 2 or 3.\ndevice.set_power(1, False)\n```\n\n### Checking power state\n```python3\nstate = device.check_power()\n```\n\n## Light bulbs\n\n### Fetching data\n```python3\nstate = device.get_state()\n```\n\n### Setting state attributes\n```python3\ndevices[0].set_state(pwr=0)\ndevices[0].set_state(pwr=1)\ndevices[0].set_state(brightness=75)\ndevices[0].set_state(bulb_colormode=0)\ndevices[0].set_state(blue=255)\ndevices[0].set_state(red=0)\ndevices[0].set_state(green=128)\ndevices[0].set_state(bulb_colormode=1)\n```\n\n## Environment sensors\n\n### Fetching sensor data\n```python3\ndata = device.check_sensors()\n```\n\n## Hubs\n\n### Discovering subdevices\n```python3\ndevice.get_subdevices()\n```\n\n### Fetching data\nUse the DID obtained from get_subdevices() for the input parameter to query specific sub-device.\n\n```python3\ndevice.get_state(did=\"00000000000000000000a043b0d06963\")\n```\n\n### Setting state attributes\nThe parameters depend on the type of subdevice that is being controlled. In this example, we are controlling LC-1 switches:\n\n#### Turn on\n```python3\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr=1)\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr1=1)\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr2=1)\n```\n#### Turn off\n```python3\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr=0)\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr1=0)\ndevice.set_state(did=\"00000000000000000000a043b0d0783a\", pwr2=0)\n```\n","funding_links":[],"categories":["\u003ca id=\"9eee96404f868f372a6cbc6769ccb7f8\"\u003e\u003c/a\u003e新添加的","Python (1887)","Python","\u003ca id=\"9eee96404f868f372a6cbc6769ccb7f8\"\u003e\u003c/a\u003e工具"],"sub_categories":["\u003ca id=\"31185b925d5152c7469b963809ceb22d\"\u003e\u003c/a\u003e新添加的"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjg59%2Fpython-broadlink","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmjg59%2Fpython-broadlink","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmjg59%2Fpython-broadlink/lists"}