Installation of Home Assistant on Intel NUK ( NUK7i5BNK Ubuntu Server 18.04.2 LTS )

I want to share my successful installation of HA on Intel NUK using Ubuntu Server as OS

Installation of Ubuntu Server went without problems so leaving this out.

Then install all needed programs and libraries
Python3
Samba server to edit configuration files from Windows
MySQL server for Recorder
Mosquitto MQTT server

sudo apt-get install -y python3-pip python3-venv build-essential libssl-dev libffi-dev python3-dev default-libmysqlclient-dev libssl-dev
sudo apt-get install -y apparmor-utils apt-transport-https avahi-daemon ca-certificates curl dbus jq network-manager socat software-properties-common
sudo apt-get install -y mysql-server
sudo apt-get install -y mosquitto mosquitto-clients
sudo apt-get install -y libmariadbclient-dev libssl-dev
sudo apt install -y samba selinux-utils
sudo apt-get install -y system-config-samba

Create user for Home Assistant

sudo adduser ha

Create Python virtual environment and install Home Assistant in a virtual environment

sudo su - ha
python3 -m venv homeassistant
cd homeassistant
source bin/activate
python3 -m pip install wheel
python3 -m pip install homeassistant
python3 -m pip3 install mysqlclient

Configure Samba server:

sudo mv /etc/samba/smb.conf  /etc/samba/smb.conf.bkp
sudo bash -c 'grep -v -E "^#|^;" /etc/samba/smb.conf.bkp | grep . > /etc/samba/smb.conf'
sudo ufw allow 'Samba'
sudo smbpasswd -a alex
sudo smbpasswd -e alex

sudo nano /etc/samba/smb.conf

Add folowing to /etc/samba/smb.conf

[Public]
   path = /samba/public
   writable = yes
   guest ok = yes
   guest only = yes
   read only = no
   create mode = 0666
   directory mode = 0777
[alex]
    path = /home/ha
    browseable = yes
    read only = no
    create mode = 0660
    directory mode = 0770
    valid users = alex
	writable = yes
	force user = ha

Then execute:

sudo mkdir -p /samba/public
sudo chmod 777 /samba/public

So now we have public directory /samba/public accessible by everyone and Home Assistant directory accessible via alex user. This is because I use this user to access from Windows additional shares and Windows can have only one user for access to all shares.

Now configure Mosquitto MQTT server:

sudo mosquitto_passwd -c /etc/mosquitto/passwd mqttuser 

Set password for user mqttuser
After this:

sudo nano /etc/mosquitto/conf.d/mosquitto.conf

This will create new file. The content of the file:

store_clean_interval 180
password_file /etc/mosquitto/passwd
user mosquitto
message_size_limit 268435455
allow_zero_length_clientid true
auto_id_prefix true
persistent_client_expiration 30d
port 1883
max_connections 500
autosave_interval 300
persistence_file mosquitto.db

allow_anonymous false

log_type error
log_type warning
log_type notice
connection_messages true

max_queued_messages 100
queue_qos0_messages true

For some reason restart of service not working so:

sudo systemctl stop mosquitto
sudo systemctl start mosquitto
sudo ufw allow 1883

Now will configure MySQL server and create a database for HA

sudo ufw allow mysql
sudo mysql_secure_installation

Create password for root and remove test database and remote access if you want
After this:

sudo mysql -u root -p
CREATE DATABASE homeassistant CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'homeassistant'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON homeassistant.* TO 'homeassistant'@'localhost';

Exit from client.
Now run Home Assistant to create configuration files and other stuff:

sudo su - ha
cd homeassistant
source bin/activate
hass --open-ui

After this leave HA to work for 10-20 min
Meanwhile, we can create an autostart file for HA

sudo nano /etc/systemd/system/[email protected]

File content:

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

[Service]
Type=simple
User=%i
ExecStart=/home/ha/homeassistant/bin/hass -c "/home/ha/.homeassistant"

[Install]
WantedBy=multi-user.target

Execute:

sudo systemctl --system daemon-reload

After 10-20min exit running HA. Hopefully, the setup stage was completed as it is no a real indication of this.
Open /home/ha/.homeassistant/configuration.yaml and add configuration of mqtt and recorder

# MQTT  
mqtt:
  broker: 192.168.0.7
  port: 1883
  client_id: home_assistant_1
  keepalive: 60
  username:  mqttuser
  password:  your_password
  discovery: true
  discovery_prefix: homeassistant
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'
  protocol: 3.1.1

#Configure recorder to use MySQL server  
recorder:
  purge_keep_days: 30
  db_url: mysql://homeassistant:your_password@localhost/homeassistant?charset=utf8

Now will create HA service and start HA

sudo systemctl enable [email protected]
sudo systemctl start [email protected]

That is all.

Any comments welcomed!

1 Like