アプリケーション開発
オートメーション機能の利用方法
ステップ3:レシピの応用
本チュートリアルで使用しているソースコードの詳細を記載します。パラメータを変更するなどして、是非新たなレシピを生み出してみてください。
サンプル
温度が閾値以上の場合にエアコンを起動するとともにSlackに通知する
{ "description": "温度が閾値以上の場合にエアコンを起動するとともにSlackに通知する", "recipeVersion": "0.1", "parameters": { "getTemperatureThingId": { "type": "string", "description": "温度取得APIを実行するデバイスのthingId", "required": true }, "putAirConditionerThingId": { "type": "string", "description": "エアコン起動APIを実行するデバイスのthingId", "required": true }, "thresholdValue": { "type": "string", "description": "トリガーを実行する閾値となる温度の値", "required": true }, "slackWebhookUrl": { "type": "string", "description": "SlackのWebhook のURL", "required": true }, "slackMessage": { "type": "string", "description": "Slackに通知するメッセージ", "default": "部屋の温度が閾値以上となったため、エアコンを起動しました。", "required": true } }, "dataSourceSteps": [ { "id": "12345678901", "name": "温度取得APIを実行", "description": "", "action": "symphony:runDeviceApiGet", "inputs": { "path": "/temperature", "thingId": "{{ getTemperatureThingId }}", "queryParameters": [] } } ], "triggerSteps": { "switchTrigger": { "id": "12345678902", "name": "温度の確認", "description": "", "action": "symphony:switchDeviceApiResponse", "inputs": { "parameterName": "temperature", "type": "integer", "format": "int32", "targetDataSourceId": "12345678901", "conditionals": [ { "value": "{{ thresholdValue }}", "conditional": "GreaterThanOrEqualTo", "targetActionIds": ["12345678903", "12345678904"] } ] } } }, "actionSteps": [ { "id": "12345678903", "name": "エアコンの起動APIを実行", "description": "", "action": "symphony:runDeviceApiPut", "inputs": { "path": "/airConditioner", "thingId": "{{ putAirConditionerThingId }}", "bodyParameters": [] } }, { "id": "12345678904", "name": "Slackに通知", "description": "", "action": "symphony:notifySlack", "inputs": { "message": "{{ slackMessage }}", "slackWebhookUrl": "{{ slackWebhookUrl }}" } } ] }
9時から17時の間、指定の鍵の状態がunlocked であればSlackに通知する
{ "description": "9時から17時の間、指定の鍵の状態がunlocked であればSlackに通知する", "recipeVersion": "0.1", "parameters": { "putLockThingId": { "type": "string", "description": "ロック状態のイベント開始APIを実行するデバイスのthingId", "required": true }, "slackWebhookUrl": { "type": "string", "description": "SlackのWebhook のURL", "required": true }, "slackMessage": { "type": "string", "description": "Slackに通知するメッセージ", "default": "自宅の玄関の鍵が開きました", "required": true } }, "dataSourceSteps": [ { "id": "12345678901", "name": "ロック状態のイベントAPIを実行", "description": "", "action": "symphony:runDeviceApiPut", "inputs": { "path": "/lock", "thingId": "{{ putLockThingId }}", "bodyParameters": [ { "interval": 30000 } ] } } ], "triggerSteps": { "compareTriggers": [ { "id": "12345678902", "name": "ロック状態のイベントメッセージの確認", "description": "", "action": "symphony:compareEventMessage", "inputs": { "parameterName": "smartlock", "type": "string", "value": "unlocked", "conditional": "Equal", "targetDataSourceId": "12345678901" }, "andor": "and" }, { "id": "12345678903", "name": "現在日時の確認", "description": "", "action": "symphony:compareTimestamp", "inputs": { "parameterName": "hour", "type": "string", "format": "time", "value": "09:00", "conditional": "GreaterThanOrEqualTo", }, "andor": "and" }, { "id": "12345678904", "name": "現在日時の確認", "description": "", "action": "symphony:compareTimestamp", "inputs": { "parameterName": "time", "type": "integer", "format": "time", "value": "17:00", "conditional": "LessThanOrEqualTo", }, "andor": "and" } ], "compareMatchTargetActionIds": ["12345678905"] }, "actionSteps": [ { "id": "12345678905", "name": "Slackに通知", "description": "", "action": "symphony:notifySlack", "inputs": { "message": "{{ slackMessage }}", "slackWebhookUrl": "{{ slackWebhookUrl }}" } } ] }
レシピ・フォーマット
プロパティ名 | 型 | 必須 | 説明 |
---|---|---|---|
description | string | 説明文。Symphony上で見えるものはレシピ登録時に別途管理する。 | |
recipeFormatVersion | string | 〇 | レシピのフォーマットのバージョン。1.0 固定。 |
recipeVersion | string | レシピ作成者が区別するためのバージョン。Symphony上では管理されない。 | |
parameters | object | インプットパラメータのオブジェクト | |
{key} | string | 〇 | レシピ内で使われるパラメータ名 |
type | string | 〇 | パラメータの型 |
description | string | パラメータの説明 | |
required | boolean | このパラメータが必須かどうか。存在しない場合trueとして扱う。 | |
default | string | このパラメータのデフォルト値 | |
dataSourceSteps | objectList | 〇 | データソースのステップ。空を許容する。 |
id | string | 〇 | このステップのid。レシピ内で一意の文字列とする。 |
name | string | 〇 | このステップの任意の名前 |
description | string | このステップの説明 | |
action | string | 〇 | ステップの動作を一意に決める文字列。別途定義される。 |
inputs | object | このステップのインプットパラメータの定義。action によって異なる。 | |
triggerSteps | object | 〇 | トリガー(条件の確認)のステップ。空を許容しない。 |
switchTrigger | object | 任意の値に対して、条件とアクションを設定する。 | |
id | string | 〇 | このステップのid。レシピ内で一意の文字列とする。 |
name | string | 〇 | このステップの任意の名前 |
description | string | このステップの説明 | |
action | string | 〇 | ステップの動作を一意に決める文字列。別途定義される。 |
inputs | object | このステップのインプットパラメータの定義。action によって異なる。 | |
compareTriggers | objectList | 複数の任意の値に対して、条件を設定する | |
id | string | 〇 | このステップのid。レシピ内で一意の文字列とする。 |
name | string | 〇 | このステップの任意の名前 |
description | string | このステップの説明 | |
action | string | 〇 | ステップの動作を一意に決める文字列。別途定義される。 |
inputs | object | このステップのインプットパラメータの定義。action によって異なる。 | |
andor | string | andまたはorを指定。この条件をANDとして処理するか、ORとして処理するか。未指定の場合and として処理する。 | |
compareMatchTargetActionIds | stringList | compareTriggers で指定した条件を満たした場合に実行するアクション(満たさない状態から満たす状態への変更時) | |
compareUnMatchTargetActionIds | stringList | compareTriggers で指定した条件を満たさなくなった場合に実行するアクション(満たす状態から満たさない状態への変更時) | |
actionSteps | objectList | 条件を満たした際のアクションのステップ。空を許容しない。 | |
id | string | 〇 | このステップのid。レシピ内で一意の文字列とする。 |
name | string | 〇 | このステップの任意の名前 |
description | string | このステップの説明 | |
action | string | 〇 | ステップの動作を一意に決める文字列。別途定義される。 |
inputs | object | このステップのインプットパラメータの定義。action によって異なる。 |
各ステップのアクション(action)の定義
データソースステップ
action | 内容 |
---|---|
symphony:runDeviceApiGet | GET のデバイスAPI を実行する |
symphony:runDeviceApiPost | POST のデバイスAPI を実行する |
symphony:runDeviceApiPut | PUT のデバイスAPI を実行する |
symphony:runDeviceApiDelete | DELETE のデバイスAPI を実行する |
トリガーステップ
action | 内容 |
---|---|
symphony:switchDeviceApiResponse | one-shot のレスポンスのプロパティに対して複数の条件を設定可能で、いずれかの条件を満たすかどうかを判定し、満たした条件のアクションを呼び出す |
symphony:switchEventMessage | イベントメッセージのプロパティに対して複数の条件を設定可能で、いずれかの条件を満たすかどうかを判定し、満たした条件のアクションを呼び出す。レシピカテゴリがモニタリングの場合のみ利用可能。 |
symphony:compareDeviceApiResponse | one-shot のレスポンスのプロパティが条件を満たすかどうか判定する。複数の条件をand、orで連結可能。 |
symphony:compareEventMessage | イベントメッセージのプロパティが条件を満たすかどうか判定する。複数の条件をand、orで連結可能。レシピカテゴリがモニタリングの場合のみ利用可能。 |
symphony:changeDeviceApiResponse | one-shot のレスポンスのプロパティに変化があったかどうかを判定する。複数の条件をand、orで連結可能。レシピカテゴリがモニタリングの場合のみ利用可能。 |
symphony:changeEventMessage | イベントメッセージのプロパティに変化があったかどうかを判定する。複数の条件をand、orで連結可能。レシピカテゴリがモニタリングの場合のみ利用可能。 |
symphony:compareTimestamp | 現在日時(JST)が指定の日時条件を満たすか判定する。複数の条件をand、orで連結可能。 |
symphony:alwaysTrue | 常に条件を満たしたものとする。 |
アクションステップ
action | 内容 |
---|---|
symphony:runDeviceApiGet | GET のデバイスAPI を実行する |
symphony:runDeviceApiPost | POST のデバイスAPI を実行する |
symphony:runDeviceApiPut | PUT のデバイスAPI を実行する |
symphony:runDeviceApiDelete | DELETE のデバイスAPI を実行する |
symphony:notifyHttpPost | 指定のURL にHTTP(S) POST リクエストを実行する |
symphony:notifySlack | Slack にリクエストを実行する |