

サポート終了通知: 2026 年 5 月 20 日、 AWS は のサポートを終了します AWS IoT Events。2026 年 5 月 20 日以降、 AWS IoT Events コンソールまたは AWS IoT Events リソースにアクセスできなくなります。詳細については、[AWS IoT Events 「サポート終了](https://docs.aws.amazon.com/iotevents/latest/developerguide/iotevents-end-of-support.html)」を参照してください。

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# AWS IoT Events ディテクターモデルの例
<a name="iotevents-examples"></a>

 このページでは、さまざまな AWS IoT Events 機能の設定方法を示すユースケースの例を一覧表示します。例としては、温度しきい値などの基本的な検出から、より高度な異常検出や機械学習シナリオまで多岐にわたります。各例には、 AWS IoT Events 検出、アクション、統合の設定に役立つ手順とコードスニペットが含まれています。これらの例は、 AWS IoT Events サービスの柔軟性と、さまざまな IoT アプリケーションやユースケースに合わせてカスタマイズする方法を示しています。 AWS IoT Events 機能を調べるとき、または特定の検出または自動化ワークフローを実装するガイダンスが必要な場合は、このページを参照してください。

**Topics**
+ [例: で HVAC 温度制御を使用する AWS IoT Events](iotevents-examples-hvac.md)
+ [例: を使用したクレーン検出条件 AWS IoT Events](iotevents-examples-cranes.md)
+ [で検出された条件に応じてコマンドを送信する AWS IoT Events](iotevents-examples-cranes-commands.md)
+ [クレーンモニタリング用の AWS IoT Events ディテクターモデル](iotevents-examples-cranes-detector-models.md)
+ [AWS IoT Events クレーンモニタリング用の 入力](iotevents-examples-cranes-inputs.md)
+ [でアラームと運用メッセージを送信する AWS IoT Events](iotevents-examples-cranes-messages.md)
+ [例: センサーとアプリケーションによる AWS IoT Events イベント検出](iotevents-examples-edwsaa.md)
+ [例: Device HeartBeat を使用してデバイス接続をモニタリングする AWS IoT Events](iotevents-examples-dhb.md)
+ [例: の ISA アラーム AWS IoT Events](iotevents-examples-bisaa.md)
+ [例: を使用してシンプルなアラームを構築する AWS IoT Events](iotevents-examples-bsa.md)

# 例: で HVAC 温度制御を使用する AWS IoT Events
<a name="iotevents-examples-hvac"></a>

## 背景
<a name="iotevents-examples-hvac-background"></a>

この例では、次の特徴を備えた温度制御モデル (サーモスタット) を実装します。
+ 複数の領域をモニタリングおよび制御できる、定義した 1 つのディテクターモデル。(ディテクーインスタンスはエリアごとに作成されます。)
+ 各ディテクーインスタンスは、各制御領域に配置された複数のセンサーから温度データを受信します。
+ 各エリアの希望温度 (設定温度) はいつでも変更できます。
+ 各エリアの操作パラメータを定義し、これらのパラメータをいつでも変更できます。
+ エリアにセンサーを追加したり、エリアからセンサーを削除したりすることはいつでもできます。
+ 単位を損傷から保護するために、時間加熱および冷却単位の最小実行を有効にすることができます。
+ ディテクターは、異常なセンサー読み取り値を拒否して報告します。
+ 緊急時の温度設定値を定義できます。いずれかのセンサーが定義した設定値より上または下の温度を報告すると、加熱または冷却単位がすぐに作動し、ディテクターがその温度スパイクを報告します。

この例は、次の機能を示しています。
+ イベントディテクターモデルを作成します。
+ 入力を作成します。
+ ディテクターモデルに入力を取り込みます。
+ トリガー条件を評価します。
+ 条件の状態可変を参照し、条件に応じて可変の値を設定します。
+ 条件内のタイマーを参照し、条件に応じてタイマーを設定します。
+ Amazon SNS および MQTT メッセージを送信するアクションを実行します。

# の HVAC システムの入力定義 AWS IoT Events
<a name="iotevents-examples-hvac-inputs"></a>

`seedTemperatureInput` は、エリアのディテクターインスタンスを作成し、その操作パラメータを定義するために使用されます。

で HVAC システムの入力を設定する AWS 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."
    }
}
```

`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."
    }
}
```

# を使用した HVAC システムのディテクターモデル定義 AWS IoT Events
<a name="iotevents-examples-hvac-detector-model"></a>

`areaDetectorModel` は、ディテクターインスタンスがどのように機能するかを定義します。各 `state machine` インスタンスは、温度センサーの読み取り値を取り込み、状態を変更して、これらの読み取り値に応じて制御メッセージを送信します。

使用した CLI コマンド:

```
aws iotevents create-detector-model --cli-input-json file://areaDetectorModel.json
```

ファイル: `areaDetectorModel.json`

```
{
  "detectorModelName": "areaDetectorModel",
  "detectorModelDefinition": {
    "states": [
      {
        "stateName": "start",
        "onEnter": {
          "events": [
            {
              "eventName": "prepare",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "sensorId",
                    "value": "0"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "reportedTemperature",
                    "value": "0.1"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "resetMe",
                    "value": "false"
                  }
                }
              ]
            }
          ]
        },
        "onInput": {
          "transitionEvents": [
            {
              "eventName": "initialize",
              "condition": "$input.seedTemperatureInput.sensorCount > 0",
              "actions": [
                { 
                  "setVariable": {
                    "variableName": "rangeHigh",
                    "value": "$input.seedTemperatureInput.rangeHigh"
                  }
                },
                { 
                  "setVariable": {
                    "variableName": "rangeLow",
                    "value": "$input.seedTemperatureInput.rangeLow"
                  }
                },
                { 
                  "setVariable": {
                    "variableName": "desiredTemperature",
                    "value": "$input.seedTemperatureInput.desiredTemperature"
                  }
                },
                { 
                  "setVariable": {
                    "variableName": "averageTemperature",
                    "value": "$input.seedTemperatureInput.desiredTemperature"
                  }
                },
                { 
                  "setVariable": {
                    "variableName": "allowedError",
                    "value": "$input.seedTemperatureInput.allowedError"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "anomalousHigh",
                    "value": "$input.seedTemperatureInput.anomalousHigh"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "anomalousLow",
                    "value": "$input.seedTemperatureInput.anomalousLow"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "sensorCount",
                    "value": "$input.seedTemperatureInput.sensorCount"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "noDelay",
                    "value": "$input.seedTemperatureInput.noDelay == true"
                  }
                }
              ],
              "nextState": "idle"
            },
            {
              "eventName": "reset",
              "condition": "($variable.resetMe == true) && ($input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow)",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "averageTemperature",
                    "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)"
                  }
                }
              ],
              "nextState": "idle"
            }
          ]
        },
        "onExit": {
          "events": [
            {
              "eventName": "resetHeatCool",
              "condition": "true",
              "actions": [
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/Off"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/Off"
                  }
                }
              ]
            }
          ]
        }
      },


      {
        "stateName": "idle",
        "onInput": {
          "events": [
            {
              "eventName": "whatWasInput",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "sensorId",
                    "value": "$input.temperatureInput.sensorId"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "reportedTemperature",
                    "value": "$input.temperatureInput.sensorData.temperature"
                  }
                }
              ]
            },
            {
              "eventName": "changeDesired",
              "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature",
              "actions": [
                { 
                  "setVariable": {
                    "variableName": "desiredTemperature",
                    "value": "$input.seedTemperatureInput.desiredTemperature"
                  }
                }
              ]
            },
            {
              "eventName": "calculateAverage",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "averageTemperature",
                    "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)"
                  }
                }
              ]
            }
          ],
          "transitionEvents": [
            {
              "eventName": "anomalousInputArrived",
              "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow",
              "actions": [
                { 
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/anomaly"
                  }
                }
              ],
              "nextState": "idle"
            },

            {
              "eventName": "highTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "cooling"
            },

            {
              "eventName": "lowTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "heating"
            },

            {
              "eventName": "highTemperatureThreshold",
              "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) > ($variable.desiredTemperature + $variable.allowedError))",
              "actions": [
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "cooling"
            },

            {
              "eventName": "lowTemperatureThreshold",
              "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) < ($variable.desiredTemperature - $variable.allowedError))",
              "actions": [
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "heating"
            }
          ]
        }
      },


      {
        "stateName": "cooling",
        "onEnter": {
          "events": [
            {
              "eventName": "delay",
              "condition": "!$variable.noDelay && $variable.enteringNewState",
              "actions": [
                {
                  "setTimer": {
                    "timerName": "coolingTimer",
                    "seconds": 180
                  }
                },
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "false"
                  }
                }
              ]
            },
            {
              "eventName": "dontDelay",
              "condition": "$variable.noDelay == true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "true"
                  }
                }
              ]
            },
            {
              "eventName": "beenHere",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "false"
                  }
                }
              ]
            }
          ]
        },

        "onInput": {
          "events": [
            {
              "eventName": "whatWasInput",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "sensorId",
                    "value": "$input.temperatureInput.sensorId"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "reportedTemperature",
                    "value": "$input.temperatureInput.sensorData.temperature"
                  }
                }
              ]
            },
            {
              "eventName": "changeDesired",
              "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature",
              "actions": [
                { 
                  "setVariable": {
                    "variableName": "desiredTemperature",
                    "value": "$input.seedTemperatureInput.desiredTemperature"
                  }
                }
              ]
            },
            {
              "eventName": "calculateAverage",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "averageTemperature",
                    "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)"
                  }
                }
              ]
            },
            {
              "eventName": "areWeThereYet",
              "condition": "(timeout(\"coolingTimer\"))",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "true"
                  }
                }
              ]
            }
          ],
          "transitionEvents": [
            {
              "eventName": "anomalousInputArrived",
              "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow",
              "actions": [
                { 
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/anomaly"
                  }
                }
              ],
              "nextState": "cooling"
            },

            {
              "eventName": "highTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                }
              ],
              "nextState": "cooling"
            },

            {
              "eventName": "lowTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/Off"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "heating"
            },

            {
              "eventName": "desiredTemperature",
              "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) <= ($variable.desiredTemperature - $variable.allowedError)) && $variable.goodToGo == true",
              "actions": [
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOff"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/Off"
                  }
                }
              ],
              "nextState": "idle"
            }
          ]
        }
      },


      {
        "stateName": "heating",
        "onEnter": {
          "events": [
            {
              "eventName": "delay",
              "condition": "!$variable.noDelay && $variable.enteringNewState",
              "actions": [
                {
                  "setTimer": {
                    "timerName": "heatingTimer",
                    "seconds": 120
                  }
                },
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "false"
                  }
                }
              ]
            },
            {
              "eventName": "dontDelay",
              "condition": "$variable.noDelay == true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "true"
                  }
                }
              ]
            },
            {
              "eventName": "beenHere",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "false"
                  }
                }
              ]
            }
          ]
        },

        "onInput": {
          "events": [
            {
              "eventName": "whatWasInput",
              "condition": "true",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "sensorId",
                    "value": "$input.temperatureInput.sensorId"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "reportedTemperature",
                    "value": "$input.temperatureInput.sensorData.temperature"
                  }
                }
              ]
            },
            {
              "eventName": "changeDesired",
              "condition": "$input.seedTemperatureInput.desiredTemperature != $variable.desiredTemperature",
              "actions": [
                { 
                  "setVariable": {
                    "variableName": "desiredTemperature",
                    "value": "$input.seedTemperatureInput.desiredTemperature"
                  }
                }
              ]
            },
            {
              "eventName": "calculateAverage",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.anomalousHigh && $input.temperatureInput.sensorData.temperature > $variable.anomalousLow",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "averageTemperature",
                    "value": "((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount)"
                  }
                }
              ]
            },
            {
              "eventName": "areWeThereYet",
              "condition": "(timeout(\"heatingTimer\"))",
              "actions": [
                {
                  "setVariable": {
                    "variableName": "goodToGo",
                    "value": "true"
                  }
                }
              ]
            }
          ],
          "transitionEvents": [
            {
              "eventName": "anomalousInputArrived",
              "condition": "$input.temperatureInput.sensorData.temperature >= $variable.anomalousHigh || $input.temperatureInput.sensorData.temperature <= $variable.anomalousLow",
              "actions": [
                { 
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/anomaly"
                  }
                }
              ],
              "nextState": "heating"
            },

            {
              "eventName": "highTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature > $variable.rangeHigh",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff"
                  }
                },
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:coolOn"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/Off"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Cooling/On"
                  }
                },
                {
                  "setVariable": {
                    "variableName": "enteringNewState",
                    "value": "true"
                  }
                }
              ],
              "nextState": "cooling"
            },

            {
              "eventName": "lowTemperatureSpike",
              "condition": "$input.temperatureInput.sensorData.temperature < $variable.rangeLow",
              "actions": [
                {
                  "iotTopicPublish": {
                    "mqttTopic": "temperatureSensor/spike"
                  }
                }
              ],
              "nextState": "heating"
            },

            {
              "eventName": "desiredTemperature",
              "condition": "(((($variable.averageTemperature * ($variable.sensorCount - 1)) + $input.temperatureInput.sensorData.temperature) / $variable.sensorCount) >= ($variable.desiredTemperature + $variable.allowedError)) && $variable.goodToGo == true",
              "actions": [
                {
                  "sns": {
                    "targetArn": "arn:aws:sns:us-west-2:123456789012:heatOff"
                  }
                },
                {
                  "iotTopicPublish": {
                    "mqttTopic": "hvac/Heating/Off"
                  }
                }
              ],
              "nextState": "idle"
            }
          ]
        }
      } 

    ],

    "initialStateName": "start"
  },
  "key": "areaId",
  "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole" 
}
```

レスポンス:

```
{
    "detectorModelConfiguration": {
        "status": "ACTIVATING", 
        "lastUpdateTime": 1557523491.168, 
        "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole", 
        "creationTime": 1557523491.168, 
        "detectorModelArn": "arn:aws:iotevents:us-west-2:123456789012:detectorModel/areaDetectorModel", 
        "key": "areaId", 
        "detectorModelName": "areaDetectorModel", 
        "detectorModelVersion": "1"
    }
}
```

# の HVAC システムの BatchPutMessage の例 AWS IoT Events
<a name="iotevents-examples-hvac-input-usage-examples"></a>

この例では、`BatchPutMessage` を使用して、エリアのディテクターインスタンスを作成し、初期動作パラメータを定義します。

使用した CLI コマンド:

```
aws iotevents-data batch-put-message --cli-input-json file://seedExample.json --cli-binary-format raw-in-base64-out
```

ファイル: `seedExample.json`

```
{
  "messages": [
    {
      "messageId": "00001",
      "inputName": "seedTemperatureInput",
      "payload": "{\"areaId\": \"Area51\", \"desiredTemperature\": 20.0, \"allowedError\": 0.7, \"rangeHigh\": 30.0, \"rangeLow\": 15.0, \"anomalousHigh\": 60.0, \"anomalousLow\": 0.0, \"sensorCount\": 10, \"noDelay\": false}"
    }
  ]
}
```

レスポンス:

```
{
    "BatchPutMessageErrorEntries": []
}
```

この例では、`BatchPutMessage` を使用して、エリア内の 1 つのセンサーの温度センサーの読み取り値を報告します。

使用した CLI コマンド:

```
aws iotevents-data batch-put-message --cli-input-json file://temperatureExample.json --cli-binary-format raw-in-base64-out
```

ファイル: `temperatureExample.json`

```
{
  "messages": [
    {
      "messageId": "00005",
      "inputName": "temperatureInput",
      "payload": "{\"sensorId\": \"05\", \"areaId\": \"Area51\", \"sensorData\": {\"temperature\": 23.12} }"
    }
  ]
}
```

レスポンス:

```
{
    "BatchPutMessageErrorEntries": []
}
```

この例では、`BatchPutMessage` を使用してエリアの目的の温度を変更します。

使用した CLI コマンド:

```
aws iotevents-data batch-put-message --cli-input-json file://seedSetDesiredTemp.json --cli-binary-format raw-in-base64-out
```

ファイル: `seedSetDesiredTemp.json`

```
{
  "messages": [
    {
      "messageId": "00001",
      "inputName": "seedTemperatureInput",
      "payload": "{\"areaId\": \"Area51\", \"desiredTemperature\": 23.0}"
    }
  ]
}
```

レスポンス:

```
{
    "BatchPutMessageErrorEntries": []
}
```

 

`Area51` ディテクターインスタンスによって生成された Amazon SNS メッセージの例:

```
Heating system off command> {
  "eventTime":1557520274729,
  "payload":{
    "actionExecutionId":"f3159081-bac3-38a4-96f7-74af0940d0a4",
    "detector":{
      "detectorModelName":"areaDetectorModel",
      "keyValue":"Area51",
      "detectorModelVersion":"1"
    },
    "eventTriggerDetails":{
      "inputName":"seedTemperatureInput",
      "messageId":"00001",
      "triggerType":"Message"
    },
    "state":{
      "stateName":"start",
      "variables":{
        "sensorCount":10,
        "rangeHigh":30.0,
        "resetMe":false,
        "enteringNewState":true,
        "averageTemperature":20.0,
        "rangeLow":15.0,
        "noDelay":false,
        "allowedError":0.7,
        "desiredTemperature":20.0,
        "anomalousHigh":60.0,
        "reportedTemperature":0.1,
        "anomalousLow":0.0,
        "sensorId":0
      },
      "timers":{}
    }
  },
  "eventName":"resetHeatCool"
}
```

```
Cooling system off command> {
  "eventTime":1557520274729,
  "payload":{
    "actionExecutionId":"98f6a1b5-8f40-3cdb-9256-93afd4d66192",
    "detector":{
      "detectorModelName":"areaDetectorModel",
      "keyValue":"Area51",
      "detectorModelVersion":"1"
    },
    "eventTriggerDetails":{
      "inputName":"seedTemperatureInput",
      "messageId":"00001",
      "triggerType":"Message"
    },
    "state":{
      "stateName":"start",
      "variables":{
        "sensorCount":10,
        "rangeHigh":30.0,
        "resetMe":false,
        "enteringNewState":true,
        "averageTemperature":20.0,
        "rangeLow":15.0,
        "noDelay":false,
        "allowedError":0.7,
        "desiredTemperature":20.0,
        "anomalousHigh":60.0,
        "reportedTemperature":0.1,
        "anomalousLow":0.0,
        "sensorId":0
      },
      "timers":{}
    }
  },
  "eventName":"resetHeatCool"
}
```

この例では、`DescribeDetector` API を使用して、ディテクターインスタンスの現在の状態に関する情報を取得します。

```
aws iotevents-data describe-detector --detector-model-name areaDetectorModel --key-value Area51
```

レスポンス:

```
{
    "detector": {
        "lastUpdateTime": 1557521572.216, 
        "creationTime": 1557520274.405, 
        "state": {
            "variables": [
                {
                    "name": "resetMe", 
                    "value": "false"
                }, 
                {
                    "name": "rangeLow", 
                    "value": "15.0"
                }, 
                {
                    "name": "noDelay", 
                    "value": "false"
                }, 
                {
                    "name": "desiredTemperature", 
                    "value": "20.0"
                }, 
                {
                    "name": "anomalousLow", 
                    "value": "0.0"
                }, 
                {
                    "name": "sensorId", 
                    "value": "\"01\""
                }, 
                {
                    "name": "sensorCount", 
                    "value": "10"
                }, 
                {
                    "name": "rangeHigh", 
                    "value": "30.0"
                }, 
                {
                    "name": "enteringNewState", 
                    "value": "false"
                }, 
                {
                    "name": "averageTemperature", 
                    "value": "19.572"
                }, 
                {
                    "name": "allowedError", 
                    "value": "0.7"
                }, 
                {
                    "name": "anomalousHigh", 
                    "value": "60.0"
                }, 
                {
                    "name": "reportedTemperature", 
                    "value": "15.72"
                }, 
                {
                    "name": "goodToGo", 
                    "value": "false"
                }
            ], 
            "stateName": "idle", 
            "timers": [
                {
                    "timestamp": 1557520454.0, 
                    "name": "idleTimer"
                }
            ]
        }, 
        "keyValue": "Area51", 
        "detectorModelName": "areaDetectorModel", 
        "detectorModelVersion": "1"
    }
}
```

# の HVAC システムの BatchUpdateDetector の例 AWS IoT Events
<a name="iotevents-examples-hvac-batch-update-detector"></a>

この例では、`BatchUpdateDetector` を使用して、動作中のディテクターインスタンスの操作パラメータを変更します。

効率的な HVAC システム管理では、多くの場合、複数のディテクターのバッチ更新が必要です。このセクションでは、ディテクターに AWS IoT Eventsのバッチ更新機能を使用する方法を示します。複数のコントロールパラメータを同時に変更し、しきい値を更新して、デバイスのフリート全体でレスポンスアクションを調整し、大規模なシステムを効果的に管理する機能を向上させる方法について説明します。

使用した CLI コマンド:

```
aws iotevents-data batch-update-detector --cli-input-json file://areaDM.BUD.json
```

ファイル: `areaDM.BUD.json`

```
{
  "detectors": [
    {
      "messageId": "0001",
      "detectorModelName": "areaDetectorModel",
      "keyValue": "Area51",
      "state": {
        "stateName": "start",
        "variables": [
          {
            "name": "desiredTemperature",
            "value": "22"
          },
          {
            "name": "averageTemperature",
            "value": "22"
          },
          {
            "name": "allowedError",
            "value": "1.0"
          },
          {
            "name": "rangeHigh",
            "value": "30.0"
          },
          {
            "name": "rangeLow",
            "value": "15.0"
          },
          {
            "name": "anomalousHigh",
            "value": "60.0"
          },
          {
            "name": "anomalousLow",
            "value": "0.0"
          },
          {
            "name": "sensorCount",
            "value": "12"
          },
          {
            "name": "noDelay",
            "value": "true"
          },
          {
            "name": "goodToGo",
            "value": "true"
          },
          {
            "name": "sensorId",
            "value": "0"
          },
          {
            "name": "reportedTemperature",
            "value": "0.1"
          },
          {
            "name": "resetMe",
            "value": "true"
          }
        ],
        "timers": [
        ]
      }
    }
  ]
}
```

レスポンス:

```
{
    An error occurred (InvalidRequestException) when calling the BatchUpdateDetector operation: Number of variables in the detector exceeds the limit 10
}
```

# AWS IoT Core ルールエンジンと AWS IoT Events
<a name="iotevents-examples-hvac-iot-rules-examples"></a>

次のルールは、 AWS IoT Events MQTT メッセージをシャドウ更新リクエストメッセージとして再発行します。 AWS IoT Core モノは、ディテクターモデルによって制御される各エリアの加熱ユニットと冷却ユニットに定義されていることを前提としています。

この例では、`Area51HeatingUnit` および `Area51CoolingUnit` という名前のものを定義しました。

使用した CLI コマンド:

```
aws iot create-topic-rule --cli-input-json file://ADMShadowCoolOffRule.json
```

ファイル: `ADMShadowCoolOffRule.json`

```
{
  "ruleName": "ADMShadowCoolOff",
  "topicRulePayload": {
    "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Cooling/Off'",
    "description": "areaDetectorModel mqtt topic publish to cooling unit shadow request",
    "ruleDisabled": false,
    "awsIotSqlVersion": "2016-03-23",
    "actions": [
      {
        "republish": {
          "topic": "$$aws/things/${payload.detector.keyValue}CoolingUnit/shadow/update",
          "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" 
        }
      }
    ]
  }
}
```

レスポンス: [空]

使用した CLI コマンド:

```
aws iot create-topic-rule --cli-input-json file://ADMShadowCoolOnRule.json
```

ファイル: `ADMShadowCoolOnRule.json`

```
{
  "ruleName": "ADMShadowCoolOn",
  "topicRulePayload": {
    "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Cooling/On'",
    "description": "areaDetectorModel mqtt topic publish to cooling unit shadow request",
    "ruleDisabled": false,
    "awsIotSqlVersion": "2016-03-23",
    "actions": [
      {
        "republish": {
          "topic": "$$aws/things/${payload.detector.keyValue}CoolingUnit/shadow/update",
          "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" 
        }
      }
    ]
  }
}
```

レスポンス: [空]

使用した CLI コマンド:

```
aws iot create-topic-rule --cli-input-json file://ADMShadowHeatOffRule.json
```

ファイル: `ADMShadowHeatOffRule.json`

```
{
  "ruleName": "ADMShadowHeatOff",
  "topicRulePayload": {
    "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Heating/Off'",
    "description": "areaDetectorModel mqtt topic publish to heating unit shadow request",
    "ruleDisabled": false,
    "awsIotSqlVersion": "2016-03-23",
    "actions": [
      {
        "republish": {
          "topic": "$$aws/things/${payload.detector.keyValue}HeatingUnit/shadow/update",
          "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" 
        }
      }
    ]
  }
}
```

レスポンス: [空]

使用した CLI コマンド:

```
aws iot create-topic-rule --cli-input-json file://ADMShadowHeatOnRule.json
```

ファイル: `ADMShadowHeatOnRule.json`

```
{
  "ruleName": "ADMShadowHeatOn",
  "topicRulePayload": {
    "sql": "SELECT topic(3) as state.desired.command FROM 'hvac/Heating/On'",
    "description": "areaDetectorModel mqtt topic publish to heating unit shadow request",
    "ruleDisabled": false,
    "awsIotSqlVersion": "2016-03-23",
    "actions": [
      {
        "republish": {
          "topic": "$$aws/things/${payload.detector.keyValue}HeatingUnit/shadow/update",
          "roleArn": "arn:aws:iam::123456789012:role/service-role/ADMShadowRole" 
        }
      }
    ]
  }
}
```

レスポンス: [空]

# 例: を使用したクレーン検出条件 AWS IoT Events
<a name="iotevents-examples-cranes"></a>

多くのクレーンのオペレーターは、機械のメンテナンスまたは交換が必要な時期を検出し、適切な通知をトリガーしたいと考えています。各クレーンにはモーターがあります。モーターは、圧力と温度に関する情報を含むメッセージ (入力) を送信します。オペレーターは、2 つのレベルのイベントディテクターを必要としています。
+ クレーンレベルのイベントディテクター
+ モーターレベルのイベントディテクター

モーターからのメッセージ (`craneId` と `motorid` の両方のメタデータを含む) を使用して、オペレーターは適切なルーティングを使用して両方のレベルのイベントディテクターを実行できます。イベント条件が満たされた場合、通知は適切な Amazon SNS トピックに送信される必要があります。オペレーターは、重複する通知が発生しないようにディテクターモデルを設定できます。

この例は、次の機能を示しています。
+ 入力の生成、読み取り、更新、削除 (CRUD)。
+ イベントディテクターモデルとさまざまなバージョンのイベントディテクターの作成、読み取り、更新、削除 (CRUD)。
+ 1 つの入力を複数のイベントディテクターにルーティングします。
+ ディテクターモデルへの入力の取り込み。
+ トリガー条件とライフサイクルイベントの評価。
+ 条件内の状態可変を参照し、条件に応じて可変の値を設定する機能。
+ 定義、状態、トリガーエバリュエーター、およびアクションエグゼキューターを使用したランタイムオーケストレーション。
+ SNSターゲットを使用した `ActionsExecutor` でのアクションの実行。

# で検出された条件に応じてコマンドを送信する AWS IoT Events
<a name="iotevents-examples-cranes-commands"></a>

このページでは、 AWS IoT Events コマンドを使用して入力の設定、ディテクターモデルの作成、シミュレートされたセンサーデータの送信を行う例を示します。この例では、 AWS IoT Events を活用してモーターやクレーンなどの産業機器を監視する方法を示しています。

```
#Create Pressure Input
aws iotevents create-input  --cli-input-json file://pressureInput.json
aws iotevents describe-input --input-name PressureInput 
aws iotevents update-input  --cli-input-json file://pressureInput.json
aws iotevents list-inputs
aws iotevents delete-input --input-name PressureInput

#Create Temperature Input
aws iotevents create-input  --cli-input-json file://temperatureInput.json
aws iotevents describe-input --input-name TemperatureInput 
aws iotevents update-input  --cli-input-json file://temperatureInput.json
aws iotevents list-inputs
aws iotevents delete-input --input-name TemperatureInput

#Create Motor Event Detector using pressure and temperature input
aws iotevents create-detector-model  --cli-input-json file://motorDetectorModel.json
aws iotevents describe-detector-model --detector-model-name motorDetectorModel 
aws iotevents update-detector-model  --cli-input-json file://updateMotorDetectorModel.json
aws iotevents list-detector-models
aws iotevents list-detector-model-versions --detector-model-name motorDetectorModel 
aws iotevents delete-detector-model --detector-model-name motorDetectorModel

#Create Crane Event Detector using temperature input
aws iotevents create-detector-model  --cli-input-json file://craneDetectorModel.json
aws iotevents describe-detector-model --detector-model-name craneDetectorModel 
aws iotevents update-detector-model  --cli-input-json file://updateCraneDetectorModel.json
aws iotevents list-detector-models
aws iotevents list-detector-model-versions --detector-model-name craneDetectorModel 
aws iotevents delete-detector-model --detector-model-name craneDetectorModel

#Replace craneIds
sed -i '' "s/100008/100009/g" messages/* 

#Replace motorIds
sed -i '' "s/200008/200009/g" messages/* 

#Send HighPressure message
aws iotevents-data batch-put-message --cli-input-json file://messages/highPressureMessage.json --cli-binary-format raw-in-base64-out

#Send HighTemperature message
aws iotevents-data batch-put-message --cli-input-json file://messages/highTemperatureMessage.json --cli-binary-format raw-in-base64-out

#Send LowPressure message
aws iotevents-data batch-put-message --cli-input-json file://messages/lowPressureMessage.json --cli-binary-format raw-in-base64-out

#Send LowTemperature message
aws iotevents-data batch-put-message --cli-input-json file://messages/lowTemperatureMessage.json --cli-binary-format raw-in-base64-out
```

# クレーンモニタリング用の AWS IoT Events ディテクターモデル
<a name="iotevents-examples-cranes-detector-models"></a>

機器またはデバイスフリートのオペレーションの障害や変更をモニタリングし、そのようなイベントが発生したときにアクションをトリガーします。状態、ルール、アクションを指定するディテクターモデルを JSON で定義します。これにより、温度や圧力などの入力のモニタリング、しきい値違反の追跡、アラートの送信を行うことができます。この例では、クレーンとモーターのディテクターモデルを示し、過熱の問題を検出し、しきい値を超えたときに Amazon SNS から通知します。モデルを更新して、モニタリングを中断することなく動作を絞り込むことができます。

ファイル: `craneDetectorModel.json`

```
{
    "detectorModelName": "craneDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Running",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overheated",
                            "condition": "$input.TemperatureInput.temperature > 35",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "$variable.craneThresholdBreached + 1"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Crane Threshold Breached",
                            "condition": "$variable.craneThresholdBreached > 5",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:CraneSNSTopic"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Underheated",
                            "condition": "$input.TemperatureInput.temperature < 25",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Running"
    },
    "key": "craneid",
    "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole"
}
```

既存のディテクターモデルを更新する。ファイル: `updateCraneDetectorModel.json`

```
{
    "detectorModelName": "craneDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Running",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "0"
                                    }
                                },
                                {
                                    "setVariable": {
                                        "variableName": "alarmRaised",
                                        "value": "'false'"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overheated",
                            "condition": "$input.TemperatureInput.temperature > 30",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "$variable.craneThresholdBreached + 1"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Crane Threshold Breached",
                            "condition": "$variable.craneThresholdBreached > 5 && $variable.alarmRaised == 'false'",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:CraneSNSTopic"
                                    }
                                },
                                {
                                    "setVariable": {
                                        "variableName": "alarmRaised",
                                        "value": "'true'"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Underheated",
                            "condition": "$input.TemperatureInput.temperature < 10",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "craneThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Running"
    },
    "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole"
}
```

ファイル: `motorDetectorModel.json`

```
{
    "detectorModelName": "motorDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Running",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "motorThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overheated And Overpressurized",
                            "condition": "$input.PressureInput.pressure > 70 && $input.TemperatureInput.temperature > 30",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "motorThresholdBreached",
                                        "value": "$variable.motorThresholdBreached + 1"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Motor Threshold Breached",
                            "condition": "$variable.motorThresholdBreached > 5",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:MotorSNSTopic"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Running"
    },
    "key": "motorId",
    "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole"
}
```

既存のディテクターモデルを更新する。ファイル: `updateMotorDetectorModel.json`

```
{
    "detectorModelName": "motorDetectorModel",
    "detectorModelDefinition": {
        "states": [
            {
                "stateName": "Running",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "init",
                            "condition": "true",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "motorThresholdBreached",
                                        "value": "0"
                                    }
                                }
                            ]
                        }
                    ]
                },
                "onInput": {
                    "events": [
                        {
                            "eventName": "Overheated And Overpressurized",
                            "condition": "$input.PressureInput.pressure > 70 && $input.TemperatureInput.temperature > 30",
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "motorThresholdBreached",
                                        "value": "$variable.motorThresholdBreached + 1"
                                    }
                                }
                            ]
                        },
                        {
                            "eventName": "Motor Threshold Breached",
                            "condition": "$variable.motorThresholdBreached > 5",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-east-1:123456789012:MotorSNSTopic"
                                    }
                                }
                            ]
                        }
                    ]
                }
            }
        ],
        "initialStateName": "Running"
    },
    "roleArn": "arn:aws:iam::123456789012:role/columboSNSRole"
}
```

# AWS IoT Events クレーンモニタリング用の 入力
<a name="iotevents-examples-cranes-inputs"></a>

この例では、 を使用してクレーンモニタリングシステムの入力を設定する方法を示します AWS IoT Events。圧力と温度の入力をキャプチャして、複雑な産業機器モニタリングの入力を構築する方法を示します。

ファイル: `pressureInput.json`

```
{
    "inputName": "PressureInput",
    "inputDescription": "this is a pressure input description",
    "inputDefinition": {
        "attributes": [
          {"jsonPath": "pressure"}
        ]
    }
}
```

ファイル: `temperatureInput.json`

```
{
    "inputName": "TemperatureInput",
    "inputDescription": "this is temperature input description",
    "inputDefinition": {
        "attributes": [
            {"jsonPath": "temperature"}
        ]
    }
}
```

# でアラームと運用メッセージを送信する AWS IoT Events
<a name="iotevents-examples-cranes-messages"></a>

効果的なメッセージ処理は、クレーンモニタリングシステムでは重要です。このセクションでは、クレーンセンサーからのさまざまなメッセージタイプを処理して応答 AWS IoT Events するように を設定する方法について説明します。特定のメッセージに基づいてアラームを設定すると、ステータスの更新を解析、フィルタリング、ルーティングして適切なアクションをトリガーするのに役立ちます。

ファイル: `highPressureMessage.json`

```
{
   "messages": [
        {
           "messageId": "1",
           "inputName": "PressureInput",
           "payload": "{\"craneid\": \"100009\", \"pressure\": 80, \"motorid\": \"200009\"}"

        }
    ]
}
```

ファイル: `highTemperatureMessage.json` 

```
{
   "messages": [
        {
           "messageId": "2",
           "inputName": "TemperatureInput",
           "payload": "{\"craneid\": \"100009\", \"temperature\": 40, \"motorid\": \"200009\"}"
        }
    ]
}
```

ファイル: `lowPressureMessage.json` 

```
{
   "messages": [
        {
           "messageId": "1",
           "inputName": "PressureInput",
           "payload": "{\"craneid\": \"100009\", \"pressure\": 20, \"motorid\": \"200009\"}"
        }
    ]
}
```

ファイル: `lowTemperatureMessage.json` 

```
{
   "messages": [
        {
           "messageId": "2",
           "inputName": "TemperatureInput",
           "payload": "{\"craneid\": \"100009\", \"temperature\": 20, \"motorid\": \"200009\"}"
        }
    ]
}
```

# 例: センサーとアプリケーションによる AWS IoT Events イベント検出
<a name="iotevents-examples-edwsaa"></a>

このディテクターモデルは、 AWS IoT Events コンソールから利用可能なテンプレートの 1 つです。便宜上、ここに再掲します。

この例では AWS IoT Events、センサーデータを使用したアプリケーションイベント検出を示します。これは、適切なアクションをトリガーできるように、指定されたイベントをモニタリングするディテクターモデルを作成する方法を示しています。複数のセンサー入力を作成し、複雑なイベント条件を定義して、段階的な応答メカニズムを設定できます。

```
{
    "detectorModelName": "EventDetectionSensorsAndApplications", 
    "detectorModelDefinition": {
        "states": [
            {
                "onInput": {
                    "transitionEvents": [], 
                    "events": []
                }, 
                "stateName": "Device_exception", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Send_mqtt", 
                            "actions": [
                                {
                                    "iotTopicPublish": {
                                        "mqttTopic": "Device_stolen"
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "To_in_use", 
                            "actions": [], 
                            "condition": "$variable.position != $input.AWS_IoTEvents_Blueprints_Tracking_DeviceInput.gps_position", 
                            "nextState": "Device_in_use"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Device_idle", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Set_position", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "position", 
                                        "value": "$input.AWS_IoTEvents_Blueprints_Tracking_DeviceInput.gps_position"
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "To_exception", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Tracking_UserInput.device_id != $input.AWS_IoTEvents_Blueprints_Tracking_DeviceInput.device_id", 
                            "nextState": "Device_exception"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Device_in_use", 
                "onEnter": {
                    "events": []
                }, 
                "onExit": {
                    "events": []
                }
            }
        ], 
        "initialStateName": "Device_idle"
    }
}
```

# 例: Device HeartBeat を使用してデバイス接続をモニタリングする AWS IoT Events
<a name="iotevents-examples-dhb"></a>

このディテクターモデルは、 AWS IoT Events コンソールから利用可能なテンプレートの 1 つです。便宜上、ここに再掲します。

Defective Heart Beat (DHB) の例は、 AWS IoT Events を医療モニタリングで使用する方法を示しています。この例では、心拍数データを分析し、不規則なパターンを検出し、適切なレスポンスをトリガーするディテクターモデルを作成する方法を示します。入力の設定、しきい値の定義、潜在的な心因性問題のアラートの設定について学び、関連するヘルスケアアプリケーションの AWS IoT Events汎用性を示します。

```
{
    "detectorModelDefinition": {
        "states": [
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "To_normal",
                            "actions": [],
                            "condition": "currentInput(\"AWS_IoTEvents_Blueprints_Heartbeat_Input\")",
                            "nextState": "Normal"
                        }
                    ],
                    "events": []
                },
                "stateName": "Offline",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Send_notification",
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "sns-topic-arn"
                                    }
                                }
                            ],
                            "condition": "true"
                        }
                    ]
                },
                "onExit": {
                    "events": []
                }
            },
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "Go_offline",
                            "actions": [],
                            "condition": "timeout(\"awake\")",
                            "nextState": "Offline"
                        }
                    ],
                    "events": [
                        {
                            "eventName": "Reset_timer",
                            "actions": [
                                {
                                    "resetTimer": {
                                        "timerName": "awake"
                                    }
                                }
                            ],
                            "condition": "currentInput(\"AWS_IoTEvents_Blueprints_Heartbeat_Input\")"
                        }
                    ]
                },
                "stateName": "Normal",
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Create_timer",
                            "actions": [
                                {
                                    "setTimer": {
                                        "seconds": 300,
                                        "timerName": "awake"
                                    }
                                }
                            ],
                            "condition": "$input.AWS_IoTEvents_Blueprints_Heartbeat_Input.value > 0"
                        }
                    ]
                },
                "onExit": {
                    "events": []
                }
            }
        ],
        "initialStateName": "Normal"
    }
}
```

# 例: の ISA アラーム AWS IoT Events
<a name="iotevents-examples-bisaa"></a>

このディテクターモデルは、 AWS IoT Events コンソールから利用可能なテンプレートの 1 つです。便宜上、ここに再掲します。

```
{
    "detectorModelName": "AWS_IoTEvents_Blueprints_ISA_Alarm", 
    "detectorModelDefinition": {
        "states": [
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "unshelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unshelve\" && $variable.state == \"rtnunack\"", 
                            "nextState": "RTN_Unacknowledged"
                        }, 
                        {
                            "eventName": "unshelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unshelve\" && $variable.state == \"ack\"", 
                            "nextState": "Acknowledged"
                        }, 
                        {
                            "eventName": "unshelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unshelve\" && $variable.state == \"unack\"", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "unshelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unshelve\" && $variable.state == \"normal\"", 
                            "nextState": "Normal"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Shelved", 
                "onEnter": {
                    "events": []
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "abnormal_condition", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value > $variable.higher_threshold || $input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value < $variable.lower_threshold", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "acknowledge", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"acknowledge\"", 
                            "nextState": "Normal"
                        }, 
                        {
                            "eventName": "shelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"shelve\"", 
                            "nextState": "Shelved"
                        }, 
                        {
                            "eventName": "remove_from_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"remove\"", 
                            "nextState": "Out_of_service"
                        }, 
                        {
                            "eventName": "suppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"suppressed\"", 
                            "nextState": "Suppressed_by_design"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "RTN_Unacknowledged", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "State Save", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "state", 
                                        "value": "\"rtnunack\""
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "abnormal_condition", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value > $variable.higher_threshold || $input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value < $variable.lower_threshold", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "shelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"shelve\"", 
                            "nextState": "Shelved"
                        }, 
                        {
                            "eventName": "remove_from_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"remove\"", 
                            "nextState": "Out_of_service"
                        }, 
                        {
                            "eventName": "suppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"suppressed\"", 
                            "nextState": "Suppressed_by_design"
                        }
                    ], 
                    "events": [
                        {
                            "eventName": "Create Config variables", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "lower_threshold", 
                                        "value": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.lower_threshold"
                                    }
                                }, 
                                {
                                    "setVariable": {
                                        "variableName": "higher_threshold", 
                                        "value": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.higher_threshold"
                                    }
                                }
                            ], 
                            "condition": "$variable.lower_threshold != $variable.lower_threshold"
                        }
                    ]
                }, 
                "stateName": "Normal", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "State Save", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "state", 
                                        "value": "\"normal\""
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "acknowledge", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"acknowledge\"", 
                            "nextState": "Acknowledged"
                        }, 
                        {
                            "eventName": "return_to_normal", 
                            "actions": [], 
                            "condition": "($input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value <= $variable.higher_threshold && $input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.value >= $variable.lower_threshold)", 
                            "nextState": "RTN_Unacknowledged"
                        }, 
                        {
                            "eventName": "shelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"shelve\"", 
                            "nextState": "Shelved"
                        }, 
                        {
                            "eventName": "remove_from_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"remove\"", 
                            "nextState": "Out_of_service"
                        }, 
                        {
                            "eventName": "suppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"suppressed\"", 
                            "nextState": "Suppressed_by_design"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Unacknowledged", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "State Save", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "state", 
                                        "value": "\"unack\""
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "unsuppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unsuppressed\" && $variable.state == \"normal\"", 
                            "nextState": "Normal"
                        }, 
                        {
                            "eventName": "unsuppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unsuppressed\" && $variable.state == \"unack\"", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "unsuppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unsuppressed\" && $variable.state == \"ack\"", 
                            "nextState": "Acknowledged"
                        }, 
                        {
                            "eventName": "unsuppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"unsuppressed\" && $variable.state == \"rtnunack\"", 
                            "nextState": "RTN_Unacknowledged"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Suppressed_by_design", 
                "onEnter": {
                    "events": []
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "return_to_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"add\" && $variable.state == \"rtnunack\"", 
                            "nextState": "RTN_Unacknowledged"
                        }, 
                        {
                            "eventName": "return_to_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"add\" && $variable.state == \"unack\"", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "return_to_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"add\" && $variable.state == \"ack\"", 
                            "nextState": "Acknowledged"
                        }, 
                        {
                            "eventName": "return_to_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"add\" && $variable.state == \"normal\"", 
                            "nextState": "Normal"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Out_of_service", 
                "onEnter": {
                    "events": []
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "re-alarm", 
                            "actions": [], 
                            "condition": "timeout(\"snooze\")", 
                            "nextState": "Unacknowledged"
                        }, 
                        {
                            "eventName": "return_to_normal", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"reset\"", 
                            "nextState": "Normal"
                        }, 
                        {
                            "eventName": "shelve", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"shelve\"", 
                            "nextState": "Shelved"
                        }, 
                        {
                            "eventName": "remove_from_service", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"remove\"", 
                            "nextState": "Out_of_service"
                        }, 
                        {
                            "eventName": "suppression", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_ISA_Alarm_Input.command == \"suppressed\"", 
                            "nextState": "Suppressed_by_design"
                        }
                    ], 
                    "events": []
                }, 
                "stateName": "Acknowledged", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Create Timer", 
                            "actions": [
                                {
                                    "setTimer": {
                                        "seconds": 60, 
                                        "timerName": "snooze"
                                    }
                                }
                            ], 
                            "condition": "true"
                        }, 
                        {
                            "eventName": "State Save", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "state", 
                                        "value": "\"ack\""
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }
        ], 
        "initialStateName": "Normal"
    },
    "detectorModelDescription": "This detector model is used to detect if a monitored device is in an Alarming State in accordance to the ISA 18.2.", 
    "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole", 
    "key": "alarmId" 
}
```

# 例: を使用してシンプルなアラームを構築する AWS IoT Events
<a name="iotevents-examples-bsa"></a>

このディテクターモデルは、 AWS IoT Events コンソールから利用可能なテンプレートの 1 つです。便宜上、ここに再掲します。

```
{
    "detectorModelDefinition": {
        "states": [
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "not_fixed", 
                            "actions": [], 
                            "condition": "timeout(\"snoozeTime\")", 
                            "nextState": "Alarming"
                        }, 
                        {
                            "eventName": "reset", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.command == \"reset\"", 
                            "nextState": "Normal"
                        }
                    ], 
                    "events": [
                        {
                            "eventName": "DND", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "dnd_active", 
                                        "value": "1"
                                    }
                                }
                            ], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.command == \"dnd\""
                        }
                    ]
                }, 
                "stateName": "Snooze", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Create Timer", 
                            "actions": [
                                {
                                    "setTimer": {
                                        "seconds": 120, 
                                        "timerName": "snoozeTime"
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "out_of_range", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.value > $variable.threshold", 
                            "nextState": "Alarming"
                        }
                    ], 
                    "events": [
                        {
                            "eventName": "Create Config variables", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "threshold", 
                                        "value": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.threshold"
                                    }
                                }
                            ], 
                            "condition": "$variable.threshold != $variable.threshold"
                        }
                    ]
                }, 
                "stateName": "Normal", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Init", 
                            "actions": [
                                {
                                    "setVariable": {
                                        "variableName": "dnd_active", 
                                        "value": "0"
                                    }
                                }
                            ], 
                            "condition": "true"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }, 
            {
                "onInput": {
                    "transitionEvents": [
                        {
                            "eventName": "reset", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.command == \"reset\"", 
                            "nextState": "Normal"
                        }, 
                        {
                            "eventName": "acknowledge", 
                            "actions": [], 
                            "condition": "$input.AWS_IoTEvents_Blueprints_Simple_Alarm_Input.command == \"acknowledge\"", 
                            "nextState": "Snooze"
                        }
                    ], 
                    "events": [
                        {
                            "eventName": "Escalated Alarm Notification", 
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-west-2:123456789012:escalatedAlarmNotification"
                                    }
                                }
                            ], 
                            "condition": "timeout(\"unacknowledgeTIme\")"
                        }
                    ]
                }, 
                "stateName": "Alarming", 
                "onEnter": {
                    "events": [
                        {
                            "eventName": "Alarm Notification", 
                            "actions": [
                                {
                                    "sns": {
                                        "targetArn": "arn:aws:sns:us-west-2:123456789012:alarmNotification"
                                    }
                                }, 
                                {
                                    "setTimer": {
                                        "seconds": 300, 
                                        "timerName": "unacknowledgeTIme"
                                    }
                                }
                            ], 
                            "condition": "$variable.dnd_active != 1"
                        }
                    ]
                }, 
                "onExit": {
                    "events": []
                }
            }
        ], 
        "initialStateName": "Normal"
    }, 
    "detectorModelDescription": "This detector model is used to detect if a monitored device is in an Alarming State.", 
    "roleArn": "arn:aws:iam::123456789012:role/IoTEventsRole", 
    "key": "alarmId" 
}
```