Build a mobile app using the Home APIs on iOS

Google for DevelopersAbout 5 min readJul 1, 2025Watch original
THE SUMMARYAI-generated

Key Concepts

  • Google Home APIs
  • Device and Structure APIs
  • Commissioning APIs (Matter devices)
  • Automation APIs
  • OAuth 2.0
  • Home (SDK object)
  • Starters, Conditions, Actions (Automation components)
  • Google Home SDK
  • Google Home types

Setting Up the Development Environment

  • Prerequisites:
    • Latest Xcode version
    • iOS device (iOS 16.4+) with test account
    • Google Home Hub (Matter)
    • Compatible smart home device (light, outlet) or virtual devices (Google Home Playground for Cloud, Matter Virtual Device)
    • Apple ID enrolled in Apple Developer Program
  • Cloning the Sample App: Clone the sample app source code from GitHub (two branches: start and finished).
  • App Attest Capability: Enable the app attest capability, requiring a physical iOS device (no simulator support).
  • Apple Deployment Configuration Files: Create Apple deployment configuration files. Instructions are available via a QR code.
  • Opening the Project: Open the source code in Xcode and connect a physical iOS device.

Authentication and Authorization (OAuth 2.0)

  • OAuth Client ID: Obtain an OAuth client ID and enable Home APIs via Google Cloud.
  • Google Cloud Project: Create or select a Google Cloud project.
  • APIs and Services Page: Access the APIs and Services page.
  • Credentials: Navigate to the Credentials section.
  • Configure Consent Screen: Configure the OAuth Consent screen (Internal or External). Add test users if using an internal consent screen.
  • Create OAuth Client ID: Create an OAuth Client ID, selecting iOS as the application type. Enter the app's bundle ID and Apple developer team ID. Note the generated client ID or download the plist file.
  • Enable Home API: Enable the Home API in the APIs and Services tab.

SDK Integration and Configuration

  • Obtaining the SDK: Download the Home APIs SDK from the Developer Center (QR code provided).
  • Framework Libraries: Extract the downloaded content into the Frameworks folder within the Xcode project (Google Home SDK and Google Home types).
  • Adding Frameworks: Add the Google Home SDK and Google Home types framework files to the Xcode project.
  • Embed Settings:
    • Google Home SDK: Embed & Sign
    • Google Home types: Do Not Embed
    • SafariServices.framework: Do Not Embed
  • Target-Specific Settings: For the MatterAddDeviceExtension target, set the Google Home SDK framework's Embed column to Do Not Embed.
  • Developer and OAuth Client IDs: Populate the info.plist file with:
    • GID Client ID: OAuth client ID
    • Cloud Project Number: Cloud project number
    • GID Team ID: Apple Developer team ID
  • App Attest Capability: Add the App Attest capability to the Google Home API Sample iOS target.
  • App Groups Capability: Add the app groups capability to both the Google Home API Sample iOS and Matter Add Device Extension targets.
  • Bundle Identifier: Update the bundle identifier in the Signing and Capabilities tab for both targets.
  • Provisioning Profiles: Install the associated provisioning profiles with the required entitlements (two profiles needed, one for each target).
  • App Group ID: Update the registered app group identifier in the code by replacing HOME_API_TODO_ADD_APP_GROUP with your app group ID in the specified files.

Initializing the SDK and Handling Permissions

  • Initializing Home: Initialize the Home object in the AccountViewModel Swift file within the connect function.
  • Granting Permissions: Run the app to grant permissions to use the Home APIs. Select the Google Home structure and the account on the Google Cloud Projects Allow list.

Device and Structure APIs

  • StructureViewModel: Open the StructureViewModel Swift file and implement the getRoomsAndDevices to-do.
  • Process Function: The process function processes the room and device structure, ensuring devices are in the same room and allowing device interaction.
  • Device Control Factory: Devices not listed in the device control factory will be displayed as unsupported.
  • OnOffPluginUnitControl: Open the OnOffPluginUnitControl file and implement the primaryActionToDo to toggle the on/off state of a smart plug or similar device.
  • Adding a Room: Implement the addRoom function in the StructureViewModel file.
  • Moving a Device: Implement the moveDevice function in the StructureViewModel file.
  • Removing a Room: Implement the removeRoom function in the StructureViewModel file. Only empty rooms can be deleted.

Commissioning APIs (Matter Devices)

  • Prerequisites: Matter device, compatible Google Hub supporting Matter, and a developer project on the Google Home Developer console (if using Matter virtual device).
  • CommissioningManager: In the CommissioningManager Swift file, implement the addMatterDevice function.
  • MatterAddDevice Request: Use a matterAddDevice request to add the device to the room.

Automation APIs

  • Automations View: Access the Automations view in the app.
  • Automation Components:
    • Starters: Initial conditions that activate the automation.
    • Conditions: Additional constraints that must be true for actions to execute.
    • Actions: Commands or state updates performed when conditions are met.
  • Creating an Automation:
    • Implement the lightAutomation function in the AutomationsRepository file (example: turn off light2 after 5 seconds).
    • Select the automation in the app.
    • Save the automation.
  • Deleting an Automation: The deleteAutomation function is invoked when swiping left on an automation and tapping the Trash icon.

Conclusion

The codelab provides a step-by-step guide to building an iOS app using the Google Home APIs. It covers setting up the development environment, authentication, device and structure management, Matter device commissioning, and automation creation. The app allows users to access and control their smart home devices, add Matter devices, and create automations based on specific conditions. The use of sample code, to-do blocks, and QR codes for further information facilitates the development process.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.