

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

# コンポーネントタイプの例
<a name="twinmaker-component-types-examples"></a>

このトピックでは、コンポーネントタイプの主要な概念を実装する方法を示す例を示します。

## アラーム（要約）
<a name="twinmaker-component-types-examples-alarm"></a>

次の例は、コンソールに表示される抽象アラームコンポーネントタイプです。 AWS IoT TwinMaker `implementedBy`値を持たない`dataReader`からなる`functions`リストが含まれています。

```
{
  "componentTypeId": "com.example.alarm.basic:1",
  "workspaceId": "{{MyWorkspace}}",
  "description": "Abstract alarm component type",
  "functions": {
    "dataReader": {
         "isInherited": false
    }
  },
  "isSingleton": false,
  "propertyDefinitions": {
    "alarm_key": {
      "dataType": { "type": "STRING" },
      "isExternalId": true,
      "isRequiredInEntity": true,
      "isStoredExternally": false,
      "isTimeSeries": false
    },
    "alarm_status": {
      "dataType": {
        "allowedValues": [
          {
            "stringValue": "ACTIVE"
          },
          {
            "stringValue": "SNOOZE_DISABLED"
          },
          {
            "stringValue": "ACKNOWLEDGED"
          },
          {
            "stringValue": "NORMAL"
          }
        ],
        "type": "STRING"
      },
      "isRequiredInEntity": false,
      "isStoredExternally": true,
      "isTimeSeries": true
    }
  }
}
```

注記：

`componentTypeId`と`workspaceID`の値は必須です。`componentTypeId`の値はワークスペースに固有である必要があります。`alarm_key`の値は、関数が外部ソースからアラームデータを取得するために使用できる一意の識別子です。キーの値は必須で、 AWS IoT TwinMakerに格納されています。`alarm_status`時系列値は外部ソースに保存されます。

その他の例は[AWS IoT TwinMaker サンプル](https://github.com/aws-samples/aws-iot-twinmaker-samples)にあります。

## タイムストリームテレメトリ
<a name="twinmaker-component-types-examples-telemetry"></a>

次の例は、特定のタイプのコンポーネント (アラームや Cookie ミキサーなど) に関するテレメトリデータを外部ソースから取得する単純なコンポーネントタイプです。コンポーネントタイプが継承するLambda関数を指定します。

```
{
    "componentTypeId": "com.example.timestream-telemetry",
    "workspaceId": "{{MyWorkspace}}",
    "functions": {
        "dataReader": {
            "implementedBy": {
                "lambda": {
                    "arn": "{{lambdaArn}}"
                }
            }
        }
    },
    "propertyDefinitions": {
        "telemetryType": {
            "dataType": { "type": "STRING" },
            "isExternalId": false,
            "isStoredExternally": false,
            "isTimeSeries": false,
            "isRequiredInEntity": true
        },
        "telemetryId": {
            "dataType": { "type": "STRING" },
            "isExternalId": false,
            "isStoredExternally": false,
            "isTimeSeries": false,
            "isRequiredInEntity": true
        }
    }
}
```

## アラーム（抽象アラームから継承）
<a name="twinmaker-component-types-examples-alarm-implementation"></a>

次の例は、抽象アラームコンポーネントタイプとタイムストリームテレメトリコンポーネントタイプの両方を継承しています。アラームデータを取得する独自のLambda関数を指定します。

```
{
    "componentTypeId": "com.example.cookiefactory.alarm",
    "workspaceId": "{{MyWorkspace}}",
    "extendsFrom": [
        "com.example.timestream-telemetry",
        "com.amazon.iottwinmaker.alarm.basic"
    ],
    "propertyDefinitions": {
        "telemetryType": {
            "defaultValue": {
                "stringValue": "Alarm"
            }
        }
    },
    "functions": {
        "dataReader": {
            "implementedBy": {
                "lambda": {
                    "arn": "{{lambdaArn}}"
                }
            }
        }
    }
}
```

**注記**  
アラームコネクタは抽象アラームコンポーネントタイプを継承するため、Lambda関数は`alarm_key`値を返す必要があります。この値を返さないと、Grafanaはそれをアラームとして認識しません。これはアラームを返すすべてのコンポーネントに必要です。

## 機器の例
<a name="twinmaker-component-types-examples-equipment"></a>

このセクションの例では、潜在的な機器のモデリング方法を示します。これらの例を参考にして、独自のプロセスで機器をモデル化する方法についていくつかのアイデアを得ることができます。

### クッキーミキサー
<a name="twinmaker-component-types-examples-mixer"></a>

次の例は、タイムストリームテレメトリコンポーネントタイプを継承しています。クッキーミキサーの回転速度と温度に関する追加の時系列プロパティを指定します。

```
{
    "componentTypeId": "com.example.cookiefactory.mixer",
    "workspaceId": "{{MyWorkspace}}",
    "extendsFrom": [
        "com.example.timestream-telemetry"
    ],
    "propertyDefinitions": {
        "telemetryType": {
            "defaultValue" : { "stringValue": "Mixer" }
        },
        "RPM": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        },
        "Temperature": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        }
    }
}
```

### 水タンク
<a name="twinmaker-component-types-examples-watertank"></a>

次の例は、タイムストリームテレメトリコンポーネントタイプを継承しています。水タンクの容積と流量に関する追加の時系列プロパティを指定します。

```
{
    "componentTypeId": "com.example.cookiefactory.watertank",
    "workspaceId": "{{MyWorkspace}}",
    "extendsFrom": [
        "com.example.timestream-telemetry"
    ],
    "propertyDefinitions": {
        "telemetryType": {
            "defaultValue" : { "stringValue": "WaterTank" }
        },
        "tankVolume1": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        },
        "tankVolume2": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        },
        "flowRate1": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        },
        "flowrate2": {
            "dataType": { "type": "DOUBLE" },
            "isTimeSeries": true,
            "isStoredExternally": true
        }
    }
}
```

### スペースロケーション
<a name="twinmaker-component-types-examples-space"></a>

次の例にはプロパティが含まれており、その値はに格納されています。 AWS IoT TwinMaker値はユーザーによって指定され、内部に保存されるため、値を取得するための関数は必要ありません。また、この例では、`RELATIONSHIP`データタイプを使用して別のコンポーネントタイプとの関係を指定します。

このコンポーネントは、デジタルツインにコンテキストを追加するための軽量なメカニズムを提供します。これを使用して、どこにあるかを示すメタデータを追加できます。この情報は、どのカメラが機器や空間を認識できるかを判断したり、特定の場所に人を派遣する方法を知ったりするためのロジックにも使用できます。

```
{
    "componentTypeId": "com.example.cookiefactory.space",
    "workspaceId": "{{MyWorkspace}}",
    "propertyDefinitions": {
        "position":  {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}},
        "rotation":  {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}},
        "bounds":  {"dataType": {"nestedType": {"type": "DOUBLE"},"type": "LIST"}},
        "parent_space" : { "dataType": {"type": "RELATIONSHIP"}}
    }
}
```