【IoT】安装 Home Assistant Core

Posted by 西维蜀黍 on 2021-02-09, Last Modified on 2025-02-04

Install on Raspberry Pi

# Install Software Properties Common
sudo apt install -y software-properties-common

# Add the Deadsnakes PPA
sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update; sudo apt install -y python3.12

# Update Python 3 to Point to the New Version
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.x 1
sudo update-alternatives --config python3

# verify
python3 --version

# homeassistant 2024.2.4 needs python3.12
sudo apt-get install python3.12-distutils
python3 -m pip install wheel
pip3 install homeassistant==2024.2.4

# 我出现了找不到该版本错误,2024.2.1 Requires-Python >=3.11.0
# 这时候需要升级 Python版本

ref

Install on Ubuntu

Maintain

# ha home
$  cd /home/homeassistant/.homeassistant
# modify config
$ vim configuration.yaml

Potential Issue

requests 2.25.1 requires idna<3,>=2.5, but you'll have idna 3.1 which is incompatible.

My HA on Ubuntu2

# run
$ /srv/homeassistant/bin/python3.8 /srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant

# view logs
$ ccat /home/homeassistant/.homeassistant/home-assistant.log

Install on macOS

# Create the virtual Python environment
$ virtualenv homeassistant --python=python3
$ cd homeassistant

Set Python to the virtual environment:

$ source bin/activate

Install Home Assistant

$ pip3 install homeassistant
# 如果找不到源,可以用
$ pip install homeassistant -i https://pypi.python.org/simple

To start it after for example a server reboot, opening a new Terminal window first the virtual environment has to be activated before starting it.

$ source bin/activate
$ bin/hass

Access http://127.0.0.1:8123

Ref

Install Via Docker

Setup

Adjust the following command so that /PATH_TO_YOUR_CONFIG points at the folder where you want to store your configuration and run it.

$ docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=MY_TIME_ZONE \
  -v /PATH_TO_YOUR_CONFIG:/config \
  -v /run/dbus:/run/dbus:ro \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

# e.g.,
docker run -d \
  --name homeassistant \
  --privileged \
  --restart=unless-stopped \
  -e TZ=Asia/Singapore \
  -v /home/sw/ha_config:/config \
  -v /run/dbus:/run/dbus:ro \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

Check your container status:

$ docker ps
CONTAINER ID   IMAGE                                 COMMAND   CREATED              STATUS              PORTS     NAMES
d73e96d5ec37   homeassistant/home-assistant:stable   "/init"   About a minute ago   Up About a minute             homeassistant

Once the Home Assistant Container is running Home Assistant should be accessible using http://<host>:8123 (replace with the hostname or IP of the system). You can continue with onboarding.

Troubleshooting

s6-overlay-suexec: fatal: can only run as pid 1

$ docker logs homeassistant --follow
s6-overlay-suexec: fatal: can only run as pid 1

# how to solve
docker run --init -d -> docker run -d 

ref

从 Image 中安装并启动

$ scp /Volumes/SSDPool2/HA/ubuntu_my_ha_docker_image.tar sw@192.168.18.129:~
$ sudo docker load < ubuntu_my_ha_docker_image.tar

$ docker run --init -d \
  --name homeassistant \
  --restart=unless-stopped \
  -v /etc/localtime:/etc/localtime:ro \
  -v /PATH_TO_YOUR_CONFIG:/config \
  --network=host \
  homeassistant/home-assistant:stable

Manage

进入 container

$ docker ps -a
CONTAINER ID   IMAGE                                 COMMAND    CREATED          STATUS                     PORTS     NAMES
d73e96d5ec37   homeassistant/home-assistant:stable   "/init"    25 minutes ago   Up 25 minutes                        homeassistant

$ docker exec -it homeassistant bash
bash-5.0#

修改配置文件

$ vi /config/configuration.yaml

RESTART HOME ASSISTANT

If you change the configuration you have to restart the server. To do that you have 3 options.

  1. In your Home Assistant UI go to the Configuration panel -> Server management and click the “Restart” button.
  2. You can go to the Developer Tools -> Services, select the service homeassistant.restart and click “Call Service”.
  3. Restart it from a terminal.
$ docker restart homeassistant

Upgrade

docker ps
docker image ls
docker ps -a
# if this returns "Image is up to date" then you can stop here
docker pull ghcr.io/home-assistant/home-assistant:stable

# stop the running container
docker stop homeassistant
# remove it from Docker's list of containers
docker rm homeassistant
# https://www.home-assistant.io/blog/categories/core/
docker inspect homeassistant/home-assistant:latest | grep "io.hass.base.version"

# finally, start a new one
docker run -d \
  --name homeassistant \
  --restart=unless-stopped \
  --privileged \
  -e TZ=MY_TIME_ZONE \
  -v /PATH_TO_YOUR_CONFIG:/config \
  -v /run/dbus:/run/dbus:ro \
  --network=host \
  ghcr.io/home-assistant/home-assistant:stable

ref

Reference

Updating

To update to the latest version of Home Assistant Core follow these simple steps:

sudo -u homeassistant -H -s
source bin/activate
pip3 install --upgrade homeassistant

Install Other Stuff

HACS

https://hacs.xyz/docs/installation/installation

Stop your HA

Open a terminal

Change to the user that is running Home Assistant

sudo -u homeassistant -H -s

Run the HACS install script

wget -q -O - https://hacs.xyz/install | bash -

Then, follow https://hacs.xyz/docs/configuration/basic

Reference