Raspberry PiにDockerを導入したので、DockerでHomebridgeをインストールする方法を紹介します。
-
-
Raspberry PiにDockerとDocker Composeを導入する
続きを見る
Homebridge環境の構築
DockerでHomebridgeをインストールします。
ディレクトリ構成
docker-compose.yml
homebridge/
|_ config.json
|_ package.json
|_ package-lock.json
|_ .gitignore
.git
docker-compose.ymlを作成
version: '2'
services:
homebridge:
image: oznu/homebridge:2021-12-19
restart: always
network_mode: host
environment:
- PGID=1000
- PUID=1000
- HOMEBRIDGE_CONFIG_UI=1
- HOMEBRIDGE_CONFIG_UI_PORT=8581
- TZ=Asia/Tokyo
volumes:
- ./homebridge:/homebridge
config.jsonを作成
config.jsonにHomebridgeの設定を記述します。
{
"bridge": {
"name": "Homebridge",
"username": "AA:BB:CC:DD:EE:FF",
"port": 51826,
"pin": "031-45-154"
},
"description": "This is an example configuration file.",
"platforms": [
{
"name": "Config",
"port": 8581,
"platform": "config"
}
]
}
usernameはmacアドレスの形式になりますが、適当に記述して問題ないです。
コンテナを起動
$ docker-compose up -d
# Homebridgeのアクセサリーのプラグインをテスト用に追加
$ docker-compose exec homebridge sh
$ npm install homebridge-dummy
Homebridgeのアクセサリーをホームアプリに追加
導入したDockerイメージにはHomebridge Config UI Xが含まれているので、ブラウザからアクセサリの設定をすることができます。
設定可能な項目が定義されているので、config.jsonに設定可能な項目を調べなから記述するよりも簡単ですごく便利です。
管理画面を開く
ブラウザで、http://<Raspberry PiのIPアドレス>:8581
を開きます。

ログイン情報の初期値は、ユーザ名とパスワードともにadminです。
ホームアプリからアクセサリーを追加
iPhoneのホームアプリで「+」→ 「アクセサリを追加」を選択します。
QRコードを読み込めばアクセサリが追加されます。

アクセサリーの設定
ヘッダーから「プラグイン」を選択して、対象のアクセサリの「設定」を選択します。
チェックボックスやプルダウンから設定ができ、config.jsonの設定ファイルに記述するよりも簡単に設定ができます。

設定を変更した後は、homebridgeを再起動することで反映されます。
$ docker-compose restart
設定内容を保存
homebridgeをdockerで起動しているので、設定内容もgitで管理しておくと便利です。
$ git init
$ cd homebridge
$ sudo nano .gitignore
.gitignoreに以下を記載して、不要なものは管理対象から外しておきます。
# Logs
logs
*.log
# Dependency directories
node_modules/
# Local configuration
persist
accessories
backups
auth.json
.uix-dashboard.json
.uix-secrets
コミットした内容はgithubで管理しておきましょう。
// コミット
$ git add .
$ git commit -m "Initial commit"
// githubでリポジトリを作成したあとに以下を実行してリモートにプッシュ
$ git remote add origin git@github.com:<user_name>/homebridge.git
$ git branch -M main
$ git push -u origin main