Android 用のチャイム デバイスガイド

基本的なチャイム デバイスタイプは、標準の Matter ベースのトレイト com.google.home.matter.standard.Chime または Google 独自のカスタム バージョンのトレイト を使用して実装できます。 は、Matter 標準で指定された機能に加えて、外部チャイムもサポートします。com.google.home.google.Chimeチャイム デバイスは、Identify トレイトを実装することもできます。このトレイトは、チャイム デバイスを視覚または音声で識別する手段を提供します。

機能を使用したり、属性の更新を試みたりする前に、必ずデバイスの属性とコマンドのサポートを確認してください。詳しくは、Androidでデバイスを操作するをご覧ください。

Home API のデバイスタイプ トレイト Kotlin サンプルアプリ ユースケース

チャイム

ChimeDevice

home.matter.0000.types.0146

プリインストールされたさまざまな音を再生できるデバイスで、通常はドアホン、音声ドアホン、ビデオドアホンで使用されます。

必須のトレイト
     matter Chime

省略可能な特性
     matter 識別
ドアホン

デバイスに関する基本情報を取得する

   Android 用サンプルアプリで実装   

BasicInformation トレイトには、ベンダー名、ベンダー ID、プロダクト ID、プロダクト名(モデル情報を含む)、デバイスのソフトウェア バージョンなどの情報が含まれます。

// Get device basic information. All general information traits are on the RootNodeDevice type.
    device.type(RootNodeDevice).first().standardTraits.basicInformation?.let { basicInformation ->
        println("vendorName ${basicInformation.vendorName}")
        println("vendorId ${basicInformation.vendorId}")
        println("productId ${basicInformation.productId}")
        println("productName ${basicInformation.productName}")
        println("softwareVersion ${basicInformation.softwareVersion}")
    }

マルチパートのサポート

チャイムは、チャイムやスピーカー(オプション)など、複数のデバイスタイプで構成できます。また、一部のチャイムには Thread Border Router (TBR) が組み込まれています。幅広いサポートを確保するため、チャイムを制御する Home API アプリは、マルチパート チャイム デバイスに対応するように記述する必要があります。詳しくは、マルチパート デバイスをご覧ください。

マルチパート チャイム デバイスは、アプリ内で 1 つのタイルで表される必要があります。Chime デバイスはプライマリ デバイスで、子スピーカーは Chime の一部である必要があります。

スピーカーの音量は、チャイム デバイスのメイン設定として表示されます。

OnOff マッピング

Chime と Speaker の両方のデバイスタイプを持つチャイムの場合、制御アプリの OnOff ボタンは Chime の Enabled 属性にマッピングする必要があります。

Matter デバイス ライブラリの仕様に準拠して、チャイム トレイトの Enabled 属性を False に設定すると、チャイムが無効になるだけでなく、すべての音声と視覚のインジケーターを抑制するグローバル ミュート スイッチのように動作する場合があります。

自動化のサポート

前述のように、ChimeDevice には複数のパーツが含まれる可能性があるため、デベロッパーはすべてのチャイムをマルチパート デバイスとして扱うことが推奨されます。チャイムを使用する自動化の場合も同様です。

チャイムは、自動化の開始条件とアクションで使用できます。

自動化で使用される親チャイム デバイスのコンポーネント デバイスは、AutomationPartPath を使用して参照する必要があります。

次の自動化は、Chime トレイトとスピーカーを実装するマルチパート チャイムで自動化を作成する方法を示しています。玄関のドアが開くと、自動化がトリガーされます。

import com.google.home.automation.automation
import com.google.home.automation.greaterThan
import com.google.home.google.GoogleDoorDevice
import com.google.home.google.OpenClose
import com.google.home.matter.standard.ChimeDevice
import com.google.home.matter.standard.Chime
// ...

// Fetch devices
val devices = homeManager.devices()

// Fetch devices using the multipart device model.
val multipartDevices = homeManager.devices(enableMultipartDevices = true)

val doorDevice = devices.first() {
  it.has(GoogleDoorDevice) &&
  it.has(OpenClose)
}

// Obtain a reference to the chime device.
val chime = multipartDevices.first() {
  it.has(ChimeDevice) &&
  it.has(Chime)
}

// Extract the AutomationPartPath for the specific Chime part
val chimePartPath = chime.automationPart(chime.part(ChimeDevice).first())!!

// Build the automation
val chimeAutomation = automation {
  sequential {
    val doorOpenClose = stateReader<_>(doorDevice, GoogleDoorDevice, OpenClose)
    // Starter: When the door state changes
    val starterNode = starter<_>(doorDevice, GoogleDoorDevice, OpenClose)
    condition {
     expression = doorOpenClose.openPercent greaterThan(0)
    }
    // Action: Play a chime sound
    action(chimePartPath) {
      command(Chime.playChimeSound())
    }
  }
}

マルチパート デバイスを使用した自動化について詳しくは、マルチパート デバイスの自動化をご覧ください。

デバイスの接続を確認する

デバイスの接続は、実際にはデバイスタイプ レベルでチェックされます。一部のデバイスは複数のデバイスタイプをサポートしているためです。返される状態は、そのデバイスのすべてのトレイトの接続状態の組み合わせです。

   Android 用サンプルアプリで実装   
val lightConnectivity = dimmableLightDevice.metadata.sourceConnectivity.connectivityState

インターネット接続がない場合、デバイスの種類が混在していると PARTIALLY_ONLINE の状態になることがあります。Matter 標準特性はローカル ルーティングによりオンラインのままになる可能性がありますが、クラウドベースの特性はオフラインになります。

デバイスの IP アドレスを取得する

デバイスの IP アドレスを確認するには、GeneralDiagnostics トレイトの networkInterfaces 属性を使用します。アドレスはバイト配列として返されます。この配列は、標準の IPv4 または IPv6 文字列にフォーマットできます。

val ipAddresses =
  trait.networkInterfaces?.flatMap { networkInterface ->
    (networkInterface.ipv4Addresses + networkInterface.ipv6Addresses).mapNotNull { bytes ->
      try {
        java.net.InetAddress.getByAddress(bytes).hostAddress
      } catch (e: java.net.UnknownHostException) {
        null
      }
    }
  } ?: emptyList()