

终止支持通知：2026 年 5 月 20 日， Amazon 将终止对的支持。 Amazon IoT Events 2026 年 5 月 20 日之后，您将无法再访问 Amazon IoT Events 控制台或 Amazon IoT Events 资源。有关更多信息，请参阅[Amazon IoT Events 终止支持](https://docs.amazonaws.cn/iotevents/latest/developerguide/iotevents-end-of-support.html)。

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 中探测器模型的输入定义 Amazon IoT Events
<a name="iotevents-commented-example-inputs"></a>

我们想创建一个探测器模型，可用于监测和控制多个不同区域的温度。每个区域可以有多个温度报告传感器。我们假定每个区域均配备一台供暖装置和一台制冷装置，其可以打开或关闭以控制该区域的温度。每个区域都由探测器实例控制。

由于我们监视和控制的不同区域可能具有不同的特征，需要不同的控制参数，因此我们定义`'seedTemperatureInput'`，以便为每个区域提供这些参数。当我们将其中一条输入消息发送至 Amazon IoT Events时，将创建一个新的探测器模型实例，其中包含我们要在该区域使用的参数。以下是该输入的定义。

CLI 命令：

```
aws iotevents create-input --cli-input-json file://seedInput.json
```

`seedInput.json` 文件：

```
{
  "inputName": "seedTemperatureInput",
  "inputDescription": "Temperature seed values.",
  "inputDefinition": {
    "attributes": [
      { "jsonPath": "areaId" },
      { "jsonPath": "desiredTemperature" },
      { "jsonPath": "allowedError" },
      { "jsonPath": "rangeHigh" },
      { "jsonPath": "rangeLow" },
      { "jsonPath": "anomalousHigh" },
      { "jsonPath": "anomalousLow" },
      { "jsonPath": "sensorCount" },
      { "jsonPath": "noDelay" }
    ]
  }
}
```

响应：

```
{
    "inputConfiguration": {
        "status": "ACTIVE", 
        "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/seedTemperatureInput", 
        "lastUpdateTime": 1557519620.736, 
        "creationTime": 1557519620.736, 
        "inputName": "seedTemperatureInput", 
        "inputDescription": "Temperature seed values."
    }
}
```

**注意**
+ 为任何消息中收到的每个唯一`'areaId'`创建新探测器实例。请参见`'areaDetectorModel'`定义中的`'key'`字段。
+ 激活该区域的供暖或制冷装置前，平均温度可能与`'desiredTemperature'`不同，可能会相差`'allowedError'`。
+ 如果任何传感器报告的温度高于`'rangeHigh'`，则探测器会报告峰值并立即启动制冷装置。
+ 如果任何传感器报告的温度低于`'rangeLow'`，则探测器会报告峰值并立即启动供暖装置。
+ 如果任何传感器报告的温度高于 `'anomalousHigh'` 或低于 `'anomalousLow'`，则探测器会报告异常传感器读数，但会忽略报告的温度读数。
+ `'sensorCount'` 告知探测器该区域报告传感器的数量。探测器为其接收到的每个温度读数给出适当的权重系数，从而计算该区域的平均温度。因此，探测器不必追踪每个传感器报告的内容，并且可以根据需要动态更改传感器数量。但是，如果单个传感器离线，探测器将无法知道或考虑这一点。我们建议您创建另一个专门用于监视每个传感器连接状态的探测器模型。使用两个互补的探测器模型可简化两者的设计。
+ `'noDelay'` 值可能是 `true` 或 `false`。供暖或制冷装置开启后，应保持开启状态达到一定的最短时间，以保护设备的完整性并延长工作寿命。如果`'noDelay'`设置为 `false`，则探测器实例会在关闭制冷和供暖装置之前强制延迟，以确保它们的运行达到最短时间。延迟秒数已在探测器模型定义中硬编码，因为我们无法使用变量值来设置计时器。

`'temperatureInput'` 用于将传感器数据传输至探测器实例。

CLI 命令：

```
aws iotevents create-input --cli-input-json file://temperatureInput.json
```

`temperatureInput.json` 文件：

```
{
  "inputName": "temperatureInput",
  "inputDescription": "Temperature sensor unit data.",
  "inputDefinition": {
    "attributes": [
      { "jsonPath": "sensorId" },
      { "jsonPath": "areaId" },
      { "jsonPath": "sensorData.temperature" }
    ]
  }
}
```

响应：

```
{
    "inputConfiguration": {
        "status": "ACTIVE", 
        "inputArn": "arn:aws:iotevents:us-west-2:123456789012:input/temperatureInput", 
        "lastUpdateTime": 1557519707.399, 
        "creationTime": 1557519707.399, 
        "inputName": "temperatureInput", 
        "inputDescription": "Temperature sensor unit data."
    }
}
```

**注意**
+ 示例探测器实例不使用`'sensorId'`来直接控制或监视传感器。它会自动传递至探测器实例发送的通知中。从此处，它可用于识别出现故障的传感器（例如，定期发送异常读数的传感器可能即将失效）或已离线的传感器（当它被用作监视设备重要特征的额外探测器模型的输入时）。如果某个区域的读数经常与平均值不同，`'sensorId'`还可以帮助识别该区域的温暖或寒冷区域。
+ `'areaId'` 用于将传感器的数据路由至相应的探测器实例。为任何消息中收到的每个唯一`'areaId'`创建探测器实例。请参见`'areaDetectorModel'`定义中的`'key'`字段。