iOS 向けのアプリ管理による自動化

アプリ管理の自動化は、パートナー アプリが Automation API を使用してプログラムで構築する自動化です。

このような自動化は、Google Home app (GHA) 自動化リストに表示されません。

アプリ管理の自動化がトリガーされたときに Google Home API のアクティビティ フィードに書き込まれる情報は、カスタマイズできます。たとえば、パートナーがアプリ管理の自動化を使用して実装された「Arctic」というブランド サービスを提供している場合、アプリ管理の自動化が実行されると、実際の自動化名の代わりに Arctic サービスがアクティビティ フィードで参照されるように指定できます。

アプリで管理される自動化を作成する

アプリ管理の自動化を作成する手順は次のとおりです。

  1. 自動化のロジックグラフを作成します。

  2. アクティビティ フィードに表示される自動化のアクティビティをカスタマイズするには、自動化名の代わりにフィードに表示するローカライズされたメッセージを AppManagedAutomationConfig インスタンスに入力します。これは、アプリやサービスのローカライズされた名前や、任意のメッセージにすることができます。ローカライズされた文字列を指定しない場合、自動化の実行は他の自動化と同様にログに記録されます。最適なユーザー エクスペリエンスを実現するために、これらのローカライズされた文字列を設定することをおすすめします。

    let automationConfig = AppManagedAutomationConfig(
        managingAppDisplayNames: [
          LocalizedText(text: "My Custom SmartApp", locale: "en-US"),
          LocalizedText(text: "Mi aplicación personalizada", locale: "es-MX")
        ]
    )
    
  3. Automation.Builder を使用して自動化インスタンスを作成します。

    1. 自動化の name を設定します。
    2. client_feature_group を "APP_MANAGED_EXECUTION_REPORTED" に設定して、自動化の実行履歴が GHA の [アクティビティ] タブに表示されるようにします。
    3. automationGraph を設定します。
    4. 省略可: 自動化の appManagedAutomationConfig を設定します(ステップ 2 を参照)。
  4. 最後に、build() を呼び出して Automation インスタンスをビルドします。

この例では、手順全体を示します。


import GoogleHomeSDK
import GoogleHomeTypes

let devices = try await home.devices().list()
let mySensor: HomeDevice = devices.first(where: {
    $0.types.contains(OccupancySensorDeviceType.self) &&
    $0.structureID == structure.id
})

let myLight: HomeDevice = devices.first(
  where: {
    $0.types.contains(OnOffLightDeviceType.self) &&
    $0.structureID == structure.id
  }
)

// 1. Create logic graph
let starterNode = StarterNode(
    device: mySensor,
    trait: Matter.OccupancySensingTrait.self
)

let actionNode = ActionNode(
    device: myLight,
    command: Matter.OnOffTrait.on()
)

// Bundle nodes into a sequential graph
let automationGraph = SequentialFlow(
    nodes: [starterNode, actionNode]
)

// 2. Build the AppManagedAutomationConfig with the localized app names
let automationConfig = AppManagedAutomationConfig(
    managingAppDisplayNames: [
      LocalizedText(text: "My Custom SmartApp", locale: "en-US"),
      LocalizedText(text: "Mi aplicación personalizada", locale: "es-MX")
    ]
)

// 3. Build the Automation with both configuration and the graph
let myFunctionalAutomation = try AutomationBuilder()
    .setName("Motion Activated Light")                         // a. Set the name
    .setClientFeatureGroup("APP_MANAGED_EXECUTION_REPORTED")   // b. set the clientFeatureGroup
    .setAutomationGraph(automationGraph)                       // c. Attach the logic graph
    .setAppManagedAutomationConfig(automationConfig)           // d. Set the automationConfig
    .build() // 4. build the automation