# python-broadlink
A Python module and CLI for controlling Broadlink devices locally. The following devices are supported:
- **Universal remotes**: RM home, RM mini 3, RM plus, RM pro, RM pro+, RM4 mini, RM4 pro, RM4C mini, RM4S, RM4 TV mate
- **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
- **Switches**: MCB1, SC1, SCB1E, SCB2
- **Outlets**: BG 800, BG 900
- **Power strips**: MP1-1K3S2U, MP1-1K4S, MP2
- **Environment sensors**: A1
- **Alarm kits**: S1C, S2KIT
- **Light bulbs**: LB1, LB26 R1, LB27 R1, SB800TD
- **Curtain motors**: Dooya DT360E-45/20
- **Thermostats**: Hysen HY02B05H
- **Hubs**: S3
## Installation
Use pip3 to install the latest version of this module.
```
pip3 install broadlink
```
## Basic functions
First, open Python 3 and import this module.
```
python3
```
```python3
import broadlink
```
Now let's try some functions...
### Setup
In 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.
1. Put the device into AP Mode.
- Long press the reset button until the blue LED is blinking quickly.
- Long press again until blue LED is blinking slowly.
- Manually connect to the WiFi SSID named BroadlinkProv.
2. Connect the device to your local network with the setup function.
```python3
broadlink.setup('myssid', 'mynetworkpass', 3)
```
Security mode options are (0 = none, 1 = WEP, 2 = WPA1, 3 = WPA2, 4 = WPA1/2)
### Discovery
Use this function to discover devices:
```python3
devices = broadlink.discover()
```
#### Advanced options
You may need to specify `local_ip_address` or `discover_ip_address` if discovery does not return any devices.
```python3
devices = broadlink.discover(local_ip_address='192.168.0.100') # IP address of your local machine.
```
```python3
devices = broadlink.discover(discover_ip_address='192.168.0.255') # Broadcast address of your subnet.
```
If 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:
```python3
device = broadlink.hello('192.168.0.16') # IP address of your Broadlink device.
```
If you are a perfomance freak, use `broadlink.xdiscover()` to create devices instantly:
```python3
for device in broadlink.xdiscover():
print(device) # Example action. Do whatever you want here.
```
### Authentication
After discovering the device, call the `auth()` method to obtain the authentication key required for further communication:
```python3
device.auth()
```
The next steps depend on the type of device you want to control.
## Universal remotes
### Learning IR codes
Learning IR codes takes place in three steps.
1. Enter learning mode:
```python3
device.enter_learning()
```
2. When the LED blinks, point the remote at the Broadlink device and press the button you want to learn.
3. Get the IR packet.
```python3
packet = device.check_data()
```
### Learning RF codes
Learning IR codes takes place in five steps.
1. Sweep the frequency:
```python3
device.sweep_frequency()
```
2. When the LED blinks, point the remote at the Broadlink device for the first time and long press the button you want to learn.
3. Enter learning mode:
```python3
device.find_rf_packet()
```
4. When the LED blinks, point the remote at the Broadlink device for the second time and short press the button you want to learn.
5. Get the RF packet:
```python3
packet = device.check_data()
```
### Canceling learning
You can exit the learning mode in the middle of the process by calling this method:
```python3
device.cancel_sweep_frequency()
```
### Sending IR/RF packets
```python3
device.send_data(packet)
```
### Fetching sensor data
```python3
data = device.check_sensors()
```
## Switches
### Setting power state
```python3
device.set_power(True)
device.set_power(False)
```
### Checking power state
```python3
state = device.check_power()
```
### Checking energy consumption
```python3
state = device.get_energy()
```
## Power strips
### Setting power state
```python3
device.set_power(1, True) # Example socket. It could be 2 or 3.
device.set_power(1, False)
```
### Checking power state
```python3
state = device.check_power()
```
## Light bulbs
### Fetching data
```python3
state = device.get_state()
```
### Setting state attributes
```python3
devices[0].set_state(pwr=0)
devices[0].set_state(pwr=1)
devices[0].set_state(brightness=75)
devices[0].set_state(bulb_colormode=0)
devices[0].set_state(blue=255)
devices[0].set_state(red=0)
devices[0].set_state(green=128)
devices[0].set_state(bulb_colormode=1)
```
## Environment sensors
### Fetching sensor data
```python3
data = device.check_sensors()
```
## Hubs
### Discovering subdevices
```python3
device.get_subdevices()
```
### Fetching data
Use the DID obtained from get_subdevices() for the input parameter to query specific sub-device.
```python3
device.get_state(did="00000000000000000000a043b0d06963")
```
### Setting state attributes
The parameters depend on the type of subdevice that is being controlled. In this example, we are controlling LC-1 switches:
#### Turn on
```python3
device.set_state(did="00000000000000000000a043b0d0783a", pwr=1)
device.set_state(did="00000000000000000000a043b0d0783a", pwr1=1)
device.set_state(did="00000000000000000000a043b0d0783a", pwr2=1)
```
#### Turn off
```python3
device.set_state(did="00000000000000000000a043b0d0783a", pwr=0)
device.set_state(did="00000000000000000000a043b0d0783a", pwr1=0)
device.set_state(did="00000000000000000000a043b0d0783a", pwr2=0)
```
没有合适的资源?快使用搜索试试~ 我知道了~
用于控制 Broadlink RM2/3 (Pro) 遥控器、A1传感器平台和 SP2/3 智能插头 的 Python 模块
共26个文件
py:15个
md:5个
broadlink_cli:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 191 浏览量
2022-07-14
01:05:25
上传
评论
收藏 33KB ZIP 举报
温馨提示
用于在本地控制 Broadlink 设备的 Python 模块和 CLI。支持以下设备: 通用遥控器:RM home、RM mini 3、RM plus、RM pro、RM pro+、RM4 mini、RM4 pro、RM4C mini、RM4S、RM4 TV mate 智能插头: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 开关:MCB1、SC1、SCB1E、SCB2 奥特莱斯: BG 800, BG 900 电源板:MP1-1K3S2U、MP1-1K4S、MP2 环境传感器:A1 报警套件:S1C、S2KIT 灯泡:LB1、LB26 R1、LB27 R1、SB800TD 窗帘电机:Dooya DT360E-45/20 更多详情、使用方法,请下载后细读READM
资源推荐
资源详情
资源评论
收起资源包目录
python-broadlink-master.zip (26个子文件)
python-broadlink-master
broadlink
const.py 119B
light.py 7KB
cover.py 2KB
sensor.py 1KB
helpers.py 1KB
__init__.py 9KB
hub.py 2KB
switch.py 11KB
alarm.py 1KB
device.py 11KB
protocol.py 2KB
climate.py 8KB
exceptions.py 4KB
remote.py 3KB
.github
PULL_REQUEST_TEMPLATE.md 1KB
workflows
flake8.yaml 1KB
LICENSE 1KB
TROUBLESHOOTING.md 448B
protocol.md 7KB
requirements.txt 18B
setup.py 741B
.gitignore 6B
README.md 6KB
cli
broadlink_discovery 1KB
README.md 3KB
broadlink_cli 8KB
共 26 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功