In this piece we’ll be installing Home Assistant in Docker on CentOS. The reasons why I chose CentOS and how to set it up are described in the following posts:
- Set up a secure home server with CentOS - Part 1
- Set up a secure home server with CentOS - Part 2: Samba
Because of scalability and administratability, I’ve decided go to with Docker containers this time. My Pi already runs Hass.io and I like the ability to enhance Home Assistant by simply adding add-ons, which are essentially other Docker containers. That’s why, in this write-up, I’ll be using the Hass.io install for non-pi systems.
Pre-requisites
First of, we need to install a few software packages as prerequisites, but these are not in CentOS’s default repos, so we need to integrate the Extra Packages for Enterprise Linux 7 repo maintained by Fedora. For Ubuntu or Debian users, this is not a relevant step.
sudo yum -y install epel-release
Update and check:
yum repolist
Now, we can install the prerequisites:
Hass prerequisites:
- docker
- bash
- socat
- jq
- curl
- avahi-daemon
- dbus-daemon Of this list, we still need to add jq, socat and avahi-daemon (which is basically bonjour or mDNS):
yum install jq socat
Ubuntu or Debian users should replace yum with sudo apt-get.
Installing Hass.io containers
Because the code on the Github page of Hass.io wants to create a directory where it does not have the permissions to, we need to set up the directory in advance ourselves.
sudo mkdir /usr/share/hassio
Then we want to run the code in superuser mode, otherwise the script won’t work due to a lack of administrative rights. Before running this code, review the script that you’re about to kick off. Running scripts through bash is a serious security risk and should always be proceeded with caution!
sudo -s
curl -sL https://raw.githubusercontent.com/home-assistant/hassio-build/master/install/hassio_install | bash -s
exit
Allow access through the firewall
Let’s add the home-assistant port to our firewall (not relevant on default Ubuntu or Debian).
sudo firewall-cmd --permanent --zone=public --add-port=8123/tcp
sudo firewall-cmd --reload
Mapping SAMBA share
Then we want to map the new Hass.io folder to SAMBA so we can remotely access it and upload our config. In the previous tutorial, you can read how to set up SAMBA on CentOS. Here however, we’re going to edit the SAMBA file we currently have.
sudo vi /etc/samba/smb.conf
Most important is the hassio path (in its separate section).
# See smb.conf.example for a more detailed config file or
# read the smb.conf manpage.
# Run 'testparm' to verify the config is correct after
# you modified it.
[global]
netbios name = <COMPUTER NAME>
server string = <COMPUTER NAME>
workgroup = <WORKGROUP>
hosts allow =
remote announce =
remote browse sync =
security = user
map to guest = bad user
dns proxy = no
passdb backend = tdbsam
printing = cups
printcap name = cups
load printers = yes
cups options = raw
#===================== SHARES ======================
[Docker]
path = /opt/Docker
browsable = yes
read only = no
valid users = @linux
writable = yes
guest ok = no
[Hassio]
path = /usr/share/hassio
browsable = yes
read only = no
valid users = @linux
writable = yes
create mask = 0777
directory mask = 0777
force user = root
force create mode = 0777
force directory mode = 0777
[homes]
comment = Home Directories
valid users = %S, %D%w%S
browseable = No
read only = No
inherit acls = Yes
[printers]
comment = All Printers
path = /var/tmp
printable = Yes
create mask = 0600
browseable = No
[print$]
comment = Printer Drivers
path = /var/lib/samba/drivers
write list = root
create mask = 0664
In this case I’ve forced a privileges mask in this directory when using SAMBA, otherwise the files cannot be edited because of the lack of privileges. This does not apply when accessing the directory over, for example, SSH.
Management
Hass.io is now set up with two Docker containers. One is the hypervisor the manage the Home Assistant container and any additional add-on containers. The other, obviously, is then the Home Assistant container itself. If you need to reset Home Assistant, it’s no longer necessary to restart the whole server. All that is needed is restarting the particular Docker container:
docker restart homeassistant
Otherwise, find the container id:
docker ps
This should give you something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
344d37021ecf hassioaddons/homebridge-amd64 "/init" 16 hours ago Up 16 hours addon_a0d7b954_homebridge
035e35e922d7 homeassistant/qemux86-64-homeassistant "/usr/bin/entry.sh p…" 16 hours ago Up 12 hours homeassistant
f5bff8363e3d homeassistant/amd64-hassio-supervisor "/usr/bin/entry.sh p…" 2 days ago Up 16 hours hassio_supervisor
Then use the first few characters of that container:
docker restart 035e5
To see the status, query Docker:
docker ps
Conclusion
To conclude this short article: yes, it works and everything is set up automagically including add-on Hass.io containers. However, I dislike the lack of control and documentation on this. I manage my other containers through docker-compose and I would’ve liked to do the same with Home Assistant. I’ll try to dissect the script and create a decent compose file in a future post, because it allows for distributed functionality (think swarm) which in turn should help in the case of outages.
Perhaps you and I can try to help the project by further improving it’s documentation and make posts like this unnecessary in the future. =)
Cheers!