---
name: "bindRule"
mode: "api"
versionRequirements:
  - { name: "基础库", version: "2.14.0" }
title: "device.bindRule - 绑定联动规则"
---

## bindRule

> [VERSION] 基础库 >= 2.14.0

### 描述

绑定联动规则

### 参数

`Params`

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `params` | `IBindRule` | 是 | 绑定参数 |

### 返回值

类型: `Promise<IBindRuleResponse>`

绑定结果

##### IBindRuleResponse

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `associativeEntityId` | `string` | 与面板/设备建立绑定关系,通常为设备ID、DP点、群组、规则，dpId#value等 |
| `associativeEntityValue` | `string` | 当associativeEntityId不足以区分情况下使用，通常可关联设备、DP值、群组、规则等 |
| `bizDomain` | `string` | 业务域 |
| `id` | `number` | 数据 ID |
| `ownerId` | `string` | 家庭 ID |
| `sourceEntityId` | `string` | 设备 ID |
| `triggerRuleId` | `string` | 规则 ID |
| `triggerRuleVO` | `any` | 执行动作设备信息 |

### 引用对象

##### `interface` IBindRule

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `devId` | `string` | 设备 ID |
| `sourceEntityId` | `string` | 与面板/设备建立绑定关系,通常为设备ID、DP点、群组、规则，dpId#value等 |
| `associativeEntityId` | `string` | 当associativeEntityId不足以区分情况下使用，通常可关联设备、DP值、群组、规则等 |
| `ruleId` | `string` | 关联场景 ID |
| `entitySubIds` | `string` | 关联 DP 点 |
| `expr` | `[string[]]` | 关联 DP 点、动作组合表达式 |
| `bizDomain` | `string` | 业务域 |
| `gid` | `string` | 家庭 ID |
| `property` | `Record<string, any>` | 拓展字段，非必传 |


### 示例代码

#### 绑定联动规则

```ts
ty.bindRule({
  devId: 'abc123',
  associativeEntityId: 'dp_1#true',
  ruleId: 'rule_001',
  entitySubIds: '1',
  expr: [['$dp1', '==', 'true']],
  bizDomain: 'switch',
  gid: '456789',
}).then((res) => {
  console.log('绑定成功', res);
});
```
