---
name: "SmartAlarmAbility.setCustomAlarmStatus"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.8.0" }
title: "setCustomAlarmStatus - 启用或禁用自定义的告警规则。"
summary: "根据绑定 ID 启用或禁用自定义的告警规则。"
---

## SmartAlarmAbility.setCustomAlarmStatus

> [VERSION] @ray-js/panel-sdk >= 1.8.0

> 💡 仅支持单设备，不支持群组环境。
> 注意，返回示例仅供参考，其包含字段大于返回参数定义范围，请勿使用除本文返回参数定义以外的返回数据，否则可能会导致程序异常。

### 描述

启用或禁用自定义的告警规则

### 参数

`Params`

| 参数 | 类型 | 必填 | 描述 |
| --- | --- | --- | --- |
| `options` | `SetCustomAlarmStatusParams` | 是 | 操作参数 |

### 返回值

类型: `Promise<SetCustomAlarmStatusResult>`

元组 [是否操作成功, 更新后的完整规则列表]

### 引用对象

##### `type` SetCustomAlarmStatusParams

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `bindId` | `number` | 要操作的告警规则绑定 ID |
| `enable` | `boolean` | true 为启用，false 为禁用 |

##### `type` SetCustomAlarmStatusResult

```typescript
[boolean, CustomAlarmList]
```

##### `type` CustomAlarmList

```typescript
export type CustomAlarmList = CustomAlarmRule[];
```

##### `type` CustomAlarmRule

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `triggerRuleId` | `string` | 告警执行的规则 id |
| `triggerRuleVO` | `AlarmTriggerRuleVO` | 触发告警规则的详细信息，详见 AlarmTriggerRuleVO 定义 |
| `bizDomain` | `string` | 业务域标识，在告警 SDK 下固定为 miniAppPanelSDKAlarm |
| `associativeEntityValue` | `string` | 当 associativeEntityId 不足以区分情况下使用，比如使用的是同一个功能点时又要区分告警类型的情况下，可以使用 DpValue，一般情况下用不到 |
| `sourceEntityId` | `string` | 和当前告警相关联的设备 ID |
| `name` | `string` | 名称或备注 |
| `icon` | `string` | 图标 |
| `bindId` | `number` | 绑定 ID |
| `associativeEntityId` | `string` | 和当前告警相关联的功能点 DP ID |
| `enable` | `boolean` | 是否启用 |

##### `type` AlarmTriggerRuleVO

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `ownerId` | `string` | 家庭 id |
| `enabled` | `boolean` | 告警规则是否启用 |
| `id` | `string` | 执行规则 id |
| `name` | `string` | 告警名称或备注 |
| `preConditions` | `AlarmPreCondition[] \| unknown[]` | 执行动作的前置条件，详见 AlarmPreCondition 定义 |
| `conditions` | `CustomAlarmCondition[] \| unknown[]` | 执行动作的条件，详见 CustomAlarmCondition 定义 |
| `actions` | `CustomAlarmSceneAction[] \| unknown[]` | 执行的动作，详见 CustomAlarmSceneAction 定义 |

##### `type` DpValue

功能点值类型，可能为 boolean、number、string

```typescript
export type DpValue = boolean | number | string;
```

##### `type` AlarmPreCondition

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `expr` | `CustomAlarmPreConditionExpr` | 条件表达式 |
| `condType` | `"timeCheck"` | 条件类型，告警 SDK 固定为 timeCheck |
| `id` | `string` | 条件 ID |

##### `type` CustomAlarmCondition

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `id` | `string` | 条件 ID |
| `ruleId` | `string` | 规则 ID |
| `entityId` | `string` | 数据 ID |
| `entitySubIds` | `string` | 抽象子数据 ID |
| `expr` | `string` | 条件的表达式 |

##### `type` CustomAlarmSceneAction

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `id` | `string` | 条件 id |
| `ruleId` | `string` | 场景 id |
| `actionExecutor` | `string` | 动作类型，在告警 SDK 下固定为 appPushTrigger |

##### `type` CustomAlarmPreConditionExpr

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `timeZoneId` | `string` | 时区 id，如 Asia/Shanghai |
| `start` | `string` | 开始时间，格式为 HH:mm，如 00:00 |
| `timeInterval` | `string` | 时间间隔，固定为 'custom' |
| `loops` | `string` | 循环日期，'1111111' 说明为一周七天均开启，其中起始时间为周日 |
| `end` | `string` | 结束时间，格式为 HH:mm，如 23:59 |


### 示例代码

#### 示例

```typescript
const [success, updatedRules] = await sdm.alarm.setCustomAlarmStatus({
  bindId: 12345,
  enable: false,
});
console.log('禁用结果:', success);
```
