0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Home AssistantとCloudflare Tunnelを組合わせて使う

Posted at

前書き

引っ越しした際にSwitchBotの温度計やスマートロックを設置し、なんちゃってスマートホームを企んでいました。しかし、丸1年放置しようやくHome Assistantを使い環境を構築しました。その際、そこでリモートでアクセスさせるためのCloudflare Tunnelと組み合わせた際にハマったポイントがあったので備忘録と誰かの役に立てたばと記事にまとめます。

前提

  • Home Assistantを導入済み(Raspberry Pi環境)
  • 別サーバーにCloudflare Tunnelを導入済み

ハマった点

いつものようにCloudflare TunnelからHome Assistantにルート設定を行い、インターネット側からアクセスしようとすると次の様なエラーが出てしまいます。

エラーメッセージ
400: Bad Request

調べるとHome Assistant側で接続可能なIPアドレスを見ているらしく、Cloudflare TunnelのサーバーIPアドレスをホワイトリストに設定して解決していきます。

0. 手順の概要

Home Assistantイメージをラズパイに直接導入していたためssh等でサーバーログイン等も困難です。そのため設定を変えるのがちょっと面倒だったのでそこから説明します。

  1. ブラウザ上で設定変更するためのエディタを導入
  2. エディタを使いHome Assistantの設定変更

1. テキストエディアと設定反映の流れ

  1. サイドメニューの[設定] -> [アドオン] -> File editorを検索してインストール
  2. File editorを起動し/homeassistant/configuration.yamlを編集&保存
  3. サイドメニューの[開発者ツール]で[設定の確認]で念のためチェック後に再起動

具体的な設定内容については次の章で記載します。

2. Home Assistantの設定変更

/homeassistant/configuration.yamlに以下のIPアドレス許可を記入します。

IPアドレスの許可を追記
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.0.0/24
設定の全文
configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.0.0/24

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

ここでハマったのがいくつかのサイトでは許可すべきIPアドレスとして172.30.33.0/24と記載されています。これはHome Assistantと一緒にCloudflareのコンテナを同居させている場合の設定で何も考えずにやってたらハマりました…。私の環境の様に別サーバー等に立てている場合はそのIPアドレス(192.168.0.xx)を設定してあげる必要があります。

後書き

Home Assistantは凄く気に入っています。取得できるデータは少ないもののWindows PCからメトリクスも反映出来ました。他にも色々な連携が出来る様で奥深い!IMG_4297.JPG

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?