Installing Home Assistant (Hass.io) on Cent OS

Installing Home Assistant (Hass.io) on Cent OS

In this piece we’ll be installing Home Assistant in Docker on Cent OS. The reasons why I chose Cent OS and how to set it up are described in the following posts:

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 Cent OS’s default repos, so we need to integrate the Extra Packages for Enterprise Linux 7 repo maintained be 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:

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 administration 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 Cent OS. 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 = XR-APP01
        server string = XR-APP01
        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’ve my other containers managed through docker-compose and I would’ve liked to do the same with Home Assistant. In a future post I’ll write on how to convert this current set up of Home Assistant to docker-compose, because it then also allows for distributed functionality 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!

9 thoughts on “Installing Home Assistant (Hass.io) on Cent OS

  1. Thanks for this guide, I’m having issues though and wondering if you can help. Fresh CentOS VM, the only thing that shows up with docker ps is the supervisor, no other containers exist.

    1. Actually, after further digging, it seems that the homeassistant container exits with code 127 as soon as it’s started.

      1. Ah, thats interesting. The supervisor is the one that handles the actual hass container, and should auto restart the container if you (or any other process) shuts the container down.
        For containermanagement with a gui, take a look at https://hub.docker.com/r/portainer/portainer/

        On your error, I’m not sure where you found the error code. If in Docker, this could refer to a path not found or being invalid.

        1. The error code is displayed when I run ‘docker ps -a’

          CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
          bdf0e7e45487 homeassistant/qemux86-64-homeassistant “/usr/bin/entry.sh” 50 seconds ago Exited (127) 48 seconds ago homeassistant
          72d03f51bd91 homeassistant/amd64-hassio-supervisor “/usr/bin/entry.sh…” 58 seconds ago Up 56 seconds hassio_supervisor

          1. Turns out I was using the wrong version of docker, I needed Docker-ce, not what is in the CentOS repos.

  2. Hi Axel,

    Thanks for the guide. I got hassio working on a CentOS 7 VM, however I can’t get Win 10 (for instance in VsCode) to modify existing files under /usr/share/hassio/homeassistant However if I create the file manually from windows then I can save it.

    It seems like a user permission in the existing file, but I changed for instance configuration.yaml to have the same permissions as a new one and I still get the write access denied error.

    Thanks
    Claudio

    1. Hello Claudio,

      That indeed sounds like a permission error.
      By default the /usr/share/hassio directory is rather locked down. Are you sure you have added the force user en force mode in the samba config? This overwrites the file permissions when accessing through Samba.

  3. Yes, I did as you suggested above.
    However I finally fixed by just adding the Hassio Samba addon and enabling it (besides the samba firewall rule). Indeed I don’t need to install Samba on CentOS in order for it to work

    Thanks!

  4. Hello, thank you for this guide.

    I would be very interested if you did an article about this :

    “In a future post I’ll write on how to convert this current set up of Home Assistant to docker-compose, because it then also allows for distributed functionality which in turn should help in the case of outages.”

    😉

Leave a Reply