Build a Home Assistant smart home system - control your home devices anytime, anywhere "Intranet Penetration"

foreword

Home Assistant (hereinafter referred to as HA) is an open source smart home platform, also called home assistant, just like a software, such as our QQ software, WeChat software.

Home Assistant integrates the smart home devices at home into HA. It can access many devices, such as the famous Xiaomi, Bolian, Yiweilian, Philips, Tesla, etc., and can also access software. Devices across brands can be networked.

A device, before it is connected to HA, is a single device and can only be linked in its own ecology. Once connected to HA, it will be alive, and it can be linked in all connected platforms to realize various All kinds of automation.

The following introduces the Home Assistant panel + cpolar intranet penetration to achieve remote access anytime, anywhere.

1. Install Home Assistant

Here, the vmwhere virtual machine is used for installation, downloaded through the download link on the Home Assistant official website, and decompressed after downloading.

vmdk file: https://www.home-assistant.io/installation/linux#install-home-assistant-container

image-20230329140034810

Then create a virtual machine

image-20230329140523751

Choose a custom virtual machine

image-20230329140559237

direct next step

image-20230329140626938

Choose to install the operating system later

image-20230329140651521

Then select Linux, version selection4.x内核64位

image-20230329140916527

Set the name of the virtual machine, and then the location of the installation below can be chosen by yourself, or it can be defaulted

image-20230329141109224

You can choose one processor and two cores. The more the number of configurations here, the greater the consumption of computer performance. You can set it according to the local configuration.

image-20230329141558147

According to the requirements of the official website, more than 2G is required, here choose 3G

image-20230329141741615

Select NET network mode

image-20230329141838721

direct next step

image-20230329141927176

The disk type can be default, or SATA can be selected

image-20230329142125999

Here you need to select an existing disk

image-20230329142241934

Here select the .vmdk file downloaded from our official website above

image-20230329142336733

Then choose to keep the existing format

image-20230329142435852

Finally, click Finish

image-20230329142505378

After the installation is successful, start the virtual machine. After the startup is complete, we can see the LAN ip address and port information. 8123 is the port of the management panel.

image-20230329142908172

2. Configure Home Assistant

After starting the virtual machine, we enter the LAN ip address of Home Assistant plus the port number of 8123 on the browser, and we can see the management panel

image-20230329143213764

For the first visit and login, you need to create an account, fill in the relevant user name and password, and create an account

image-20230329143436938

Region selection, you can manually locate, or you can choose to automatically detect

image-20230329143740404

Next, click Next by default

image-20230329143904127

Then click Finish, here you will be prompted to add a smart device, you can click Finish first, and then set it yourself

image-20230329144017846

Then enter the control panel interface

image-20230329144126684

3. Install cpolar intranet penetration

After the browser access in the LAN is successful, we then use cpolar intranet penetration to map it to the public network, so that the HA at home can be accessed remotely in the public network environment, without the need for a public network IP or setting up a router .

cpolar official website: https://www.cpolar.com/

Visit the cpolar official website, register an account, and then download and install the client. For specific installation tutorials, please refer to the official website documentation tutorial.

3.1 windows system

After downloading the installation package from the cpolar official website, double-click the installation package and install it by default.

3.2 Linux system

cpolar supports one-click automatic installation script, please refer to the article tutorial for details

3.3 macOS system

It can be installed through homebrew, please refer to the article tutorial

20230130105715

4. Map the Home Assistant port

After cpolar is successfully installed, visit the local port 9200 on the browser, access the cpolar web UI management interface [ http://localhost:9200 ], and log in with the cpolar account.

20230130105810

Click Tunnel Management on the left dashboard - Create Tunnel, create an http tunnel, pointing to port 8123, which is the port of Home Assistant

  • 隧道名称: You can customize the name, be careful not to duplicate the name of the existing tunnel
  • 协议: select http
  • 本地地址: home assistant LAN ip+port
  • 域名类型: Choose a random domain name for free
  • 地区: Select China VIP

click创建

image-20230329151644131

After the tunnel is successfully created, click on the status on the left - online tunnel list, view the generated public network address, and then copy the address

image-20230329151724274

5. Access Home Assistant from the public network

Open the browser and use the public network address just obtained to connect and access. At this time, a 400 error will appear. If not, you can skip this step

image-20230330113646549

Let's check the log, see the prompt for specific errors, click on the configuration in the lower left corner, click on the system

image-20230330115658528

You can see the log, click on the log

image-20230330130245362

After opening the log, we can see such a problem, which roughly means: a request from the reverse proxy is received from 192.168.191.1, but the HTTP integration is not set for the reverse proxy, so we need to modify the configuration file

image-20230330130645997

Solution: Open the panel, find the configuration in the lower left corner, and click Add-ons

image-20230330113824049

Go to the store to download a file editor, we need to modify a configuration file

image-20230330113845841

Find the File editor file editor

image-20230330113950556

Click to install this File editor

image-20230330114133188

After the installation is successful, click Start

image-20230330114417659

Then, in order to facilitate the next use, you can check a display in the sidebar

image-20230330114525062

After opening, we can enter from the sidebar, and then click on the file directory in the upper left corner

image-20230330114704791

Find and click the configuration.yaml file, click it

image-20230330114807991

Add the following configuration to the file, the following ip address is the ip address we checked the log prompt above:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.191.1

image-20230330131216892

Then we turn on the virtual machine, restart the virtual machine, and then enter the public network address again to access, and it will be successful

image-20230330131548575

6. Fixed public network address

Since the above tunnel created by using cpolar uses a random public network address, it will change randomly within 24 hours, which is not conducive to long-term remote access. Therefore, we can configure a second-level subdomain name for it, which is a fixed address and will not change randomly.

Note that the cpolar package needs to be upgraded to the basic package or above, and the bandwidth corresponding to each package is different.

6.1 Reserve a fixed second-level subdomain

Log in to the cpolar official website, click Reserve on the left, choose to reserve the second-level subdomain name, set a second-level subdomain name, click Reserve, and copy the reserved second-level subdomain name after the reservation is successful

image-20230330132159756

After the reservation is successful, copy the reserved second-level subdomain address

image-20230330132218331

6.2 Configure a fixed second-level subdomain name

Visit http://127.0.0.1:9200/, log in to the cpolar web UI management interface, click Tunnel Management on the left dashboard - Tunnel List, find the Home Assistant tunnel to be configured, and click Edit on the right

image-20230330131957337

Modify the tunnel information, and configure the successfully reserved second-level subdomain name into the tunnel

  • 域名类型: Select a second-level subdomain
  • Sub Domain: Fill in the successfully reserved second-level subdomain name

click更新

image-20230330132252714

After the update is complete, open the online tunnel list. At this time, you can see that the public network address has changed, and the address name has also changed to the reserved second-level subdomain name. Copy it down

image-20230330132345392

Then use the fixed https address to open the browser access, and the access is also successful, and the domain name will not change.

image-20230330132444605

Reprinted from cpolar cloud article: [Smart Home] Home Assistant installation, and intranet penetration remote security control

Guess you like

Origin blog.csdn.net/m0_75215937/article/details/131757206