This is a guide to install "Home Assistant Core" on a linux machine running Ubuntu 20.04
This is classified by Home Assistant as an alternative method for experienced users. There are two main installation methods ("Home Assistant Operating System" and Home Assistant Container") that are recommended by Home Assistant and are easier to implement. However to my personal taste I still prefer the "Core" version as I keep full control of the PC running Home Assistant. In any case check the official documentation for the pros and cons of each installation method: www.home-assistant.io/installation/
Enable SSH
Install openssh:
sudo apt-get update
sudo apt-get install openssh-server
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
sudo chmod a-w /etc/ssh/sshd_config.factory-defaults
sudo systemctl restart ssh
Generate password:
mkdir ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t rsa
The computer can now be accessed from a LAN using putty in windows for example.
Install virtualenv
sudo apt install python3-virtualenv
Install Home Assistant
sudo apt-get update
sudo apt-get upgrade -y
Install Home Assistant (do not use sudo!):
virtualenv -p /usr/bin/python3 homeassistant
cd homeassistant
source bin/activate
python3 -m pip install homeassistant
Run Home Assistant manually:
hass --open-ui
Upgraing Home Assistant
Stop Home Assistant
Open the directory where the virtual environment is located:
cd homeassistant
Activate the virtual environment:
source bin/activate
Upgrade Home Assistant:
python3 -m pip install --upgrade homeassistant
Start Home Assistant
Configure AutoStart
In this section we consider that the system username is "pi". Modify with your own username if necessary.
Create the file /opt/hass/start_hass.sh with the following content:
#!/bin/bash
. /home/pi/homeassistant/bin/activate
/home/pi/homeassistant/bin/hass
Then specify user rights:
sudo chown -R pi /opt/hass/start_hass.sh
sudo chmod -R 755 /opt/hass/start_hass.sh
Now create a new systemd service: /etc/systemd/system/home-assistant.service
with the following content:
[Unit]
Description=Home Assistant Autostart
After=network-online.target
[Service]
Type=simple
User=pi
ExecStart=/opt/hass/start_hass.sh
[Install]
WantedBy=multi-user.target
Then specify user rights:
sudo chown -R pi /etc/systemd/system/home-assistant.service
sudo chmod -R 755 /etc/systemd/system/home-assistant.service
Then reload systemd: sudo systemctl --system daemon-reload
Enable the service: sudo systemctl enable home-assistant
Then you can start, stop, show status of the service:
sudo systemctl start home-assistant
sudo systemctl stop home-assistant
sudo systemctl status home-assistant
Reboot to test: sudo reboot
The following section can be very useful to keep a backup of the configuration files and for Arduino DIY projects using platformio and esphome.
Using GIT
Keep git up to date
Basic use:
git add *
git commit -m "commit message..."
git push -u origin master
Create a new git repo in my own server
Create a project directory for Git. You can use the desired path for the repo:
mkdir -p /home/user/hass_backup.git
Then change to this directory:
cd /home/user/hass_backup.git
Then create an empty repo:
git init --bare
Initialized empty Git repository in /home/user/hass_backup.git
That's it! Now we can clone this repo in a local machine:
git clone user@servermachine:/home/user/hass_backup.git
And we can add, edit files, write commit change messages and then push them to the server:
git add *
git commit -m "commit message..."
git push -u origin master
Using platformio
This is a great alternative to the Arduino IDE and to administrate all the libraries that you will need in your project. Complete documentation in: docs.platformio.org/en/latest/core/index.html
To enter the virtual environment do:
source /home/user/.platformio/penv/bin/activate
To initialize a projet:
platformio project init --board megaatmega2560
Use `nanoatmega328` for the Arduino nano and `uno` for the Arduino Uno.
Create a .cpp file in the scr folder and put the arduino code in it.
Include needed libraries in the platformio.ini file.
This file may look like this then:
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
upload_speed = 57600
monitor_speed = 57600
lib_deps =
Keypad
SPI
Ethernet
PubSubClient
To compile the project:
platformio run
To upload the project to the target board:
platformio run --target upload
For serial monitor debug use:
platformio device monitor
Using esphome
ESPHOME is a great project to build electronics based on the ESP32 WiFi chip and easily (automatic) integration with Home Assistant. Check their webpage with lots of examples and integrations: esphome.io/
Install
pip3 install esphome
To use the wizard:
esphome example.yaml wizard
To upload:
esphome example.yaml run
For reading the logs:
esphome example.yaml logs