App-managed automations are automations that are constructed programmatically
by a partner app using the Automation API.

Such automations are suppressed from appearing in the Google Home app (GHA)
automations list.

The information written to the Home APIs activity feed when an app-managed
automation is triggered can be customized. For example,
if a partner offers a branded service called "Arctic" that's implemented using
app-managed automations, the partner could specify that when their app-managed
automations run, the Arctic service is referenced in the activity feed instead
of the actual automation name.

## Create an app-managed automation

To create an app-managed automation, use the following procedure.

1. Build the automation's logic graph.

2. To customize how your automation's activity appears in the
   activity feed, populate an `AppManagedAutomationConfig` instance with the
   localized message that you want to appear in the feed in place of the
   automation name. This can be the localized names of an app or service, or
   any other message you want. If you don't provide any localized strings, the
   automation executions are logged like those of any other automation. Google
   recommends you set these localized strings to ensure the best user
   experience.

   ```kotlin
   val myAutomationConfig = AppManagedAutomationConfig(
       managingAppDisplayNames = listOf(
           LocalizedText(text = "My custom SmartApp", locale = "en-US"),
           LocalizedText(text = "Mi aplicación personalizada", locale = "es-MX")
       )
   )
   ```
3. Create the automation instance using `Automation.Builder`.

   1. Set the `name` of the automation.
   2. Set the `client_feature_group` to `"APP_MANAGED_EXECUTION_REPORTED"` so that the automation's execution history appears in the Activity tab in GHA.
   3. Set the `automationGraph`.
   4. *Optional* Set the automation's `appManagedAutomationConfig` (see Step 2).
4. Finally, call `build()` to build the `Automation` instance.

> [!IMPORTANT]
> **Important:** Setting the `clientFeatureGroup` is what indicates to the Home APIs that the automation is managed by your app, so it's important not to skip this step.

This example shows the entire procedure:

```kotlin
import com.google.home.automation.Automation
import com.google.home.automation.SequentialNode
import com.google.home.automation.StarterNode
import com.google.home.automation.ActionNode
import com.google.home.HomeDevice
import com.google.home.matter.standard.OnOff
import com.google.home.matter.standard.OnOffLightDevice
import com.google.home.matter.standard.MotionDetection
import com.google.home.matter.standard.OccupancySensorDevice

 HomeDevice mySensor = home.devices().list().first { device -> device.has(OccupancySensorDevice) }
 HomeDevice myLight = home.devices().list().first { device -> device.has(OnOffLightDevice) }

// 1. Create logic graph
val starterNode = StarterNode(
    device = mySensor,
    trait = OccupancySensing
)

val actionNode = ActionNode(
    device = myLight,
    command = OnOff.on()
)

// Bundle nodes into a sequential graph
val automationGraph = SequentialNode(
    nodes = listOf(starterNode, actionNode)
)

 // 2. Build the AppManagedAutomationConfig with the localized app names
val AppManagedAutomationConfig myAutomationConfig = 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
val myAutomation = Automation.Builder()
    .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(myCustomConfig)             // d. Set the automationConfig
    .build() // 4. build the automation
```