Home Assistant modifies the configuration file on the web page

Home Assistant modifies the configuration file on the web page

1. Introduction to hass-configurator plugin

HASS-Configurator is a small web application (you can access it through a web browser) that provides a file system browser and a text editor to modify files on the computer running the configurator. It was created to easily configure Home Assistant. It is supported by the Ace editor, which supports syntax highlighting in various code/markup languages. When editing, the YAML file (the default language of the Home Assistant configuration file) will be automatically checked for syntax errors.

2. Download and unzip hass-configurator

Download hass-configurator:

# 切换到homeassistant根目录
cd $HOME/.homeassistant
# 下载最新版插件
wget -O hass-configurator-master.zip https://github.com/danielperna84/hass-configurator/archive/master.zip

Insert picture description here
Unzip the hass-configurator:
it already exists when I create the directory here. Generally, there is no output. Just enter the ls command to check that there is a custom_components directory.

# 创建存放插件的目录(HA插件一般存放在这个目录下)
mkdir custom_components
# 解压插件
unzip hass-configurator-master.zip

Insert picture description here

3. Modify the configurator.py file

Enter the command: nano hass-configurator-master/configurator.pyand find the location in
the figure below. Copy the HA long-term access token ( token acquisition method ) to the following location, ctrl+x, enter y and press Enter
Insert picture description here
to copy the modified file to the HA plug-in directory:

# 将刚刚修改的文件复制到hass_configurator下,方便后面一次性复制到HA插件目录下
cp hass-configurator-master/configurator.py hass-configurator-master/hass_configurator/
# hass_configurator文件夹复制到custom_components下并重命名为configurator
cp -r hass-configurator-master/hass_configurator ./custom_components/configurator
# 给文件执行的权限
sudo chmod 755 ./custom_components/configurator/configurator.py
# 删除下载的文件(建议删除或者移动到其他文件夹下)
rm -rf hass-configurator-master*

Insert picture description here

4. Integrated into the Home Assistant page

Open the configuration file of Home Assistant: nano configuration.yaml
copy the following content into the configuration file, and replace the url with the IP address of your Raspberry Pi:

panel_iframe:
  configurator:
    title: Configurator
    icon: mdi:wrench
    url: http://192.168.100.10:3218

Insert picture description here
After saving and exiting and restarting Home Assistant, the Configurator appears on the web page, but the connection is refused after clicking it, as shown in the following figure:
Insert picture description here
This should be the hass-configurator plug-in is a service, you need to start it before you can return to the Raspberry Pi command line Input: ./custom_components/configurator/configurator.pyStart the configurator plug-in service.
Insert picture description here
Insert picture description here
At this point, the page is refreshed and the configurator is successfully integrated, but it is a bit troublesome to start this service every time you boot. The following describes how to set it as a self-start service at boot.

5. Set the configurator as a self-start service at boot

To determine whether the system is using systemd, you can use the following command to check: ps -p 1 -o comm=If the command returns the string systemd, you can use this method.

Create a service file sudo nano /etc/systemd/system/home-assistant@YOUR_USER.service, replace YOUR_USER with the login user name of the Raspberry Pi, and enter the following content:

[Unit]
Description=Home Assistant
After=network-online.target

[Service]
Type=simple
User=%i
WorkingDirectory=/home/%i/.homeassistant
ExecStart=/home/pi/.homeassistant/custom_components/configurator/configurator.py

[Install]
WantedBy=multi-user.target

Next step:
You need to reload systemd to make the daemon aware of the new configuration.

sudo systemctl --system daemon-reload

To make the configurator start automatically at startup, enable the service.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl enable home-assistant@YOUR_USER

To disable automatic startup, use this command.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl disable home-assistant@YOUR_USER

To start the configurator immediately, use this command.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl start home-assistant@YOUR_USER

To stop the configurator, use this command.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl stop home-assistant@YOUR_USER

To restart the configurator, use this command.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl restart home-assistant@YOUR_USER

To view the configurator status, use this command.

# YOUR_USER为树莓派的登陆用户名
sudo systemctl status home-assistant@YOUR_USER

Guess you like

Origin blog.csdn.net/qq_25886111/article/details/106260381