Home Assistant Fresh on Ubuntu 16.04 server

Hey guys, I just did a fresh install of Home Assistant on Ubuntu 16.04 server and so far I’m able to start the HA service according. If I issued the command " hass --open-ui", HA starts then died after a few seconds.

Try sudo systemctl status -l home-assistant@homeassistant. If it is not started already, you can start it using sudo systemctl start -l home-assistant@homeassistant

Import Error: No module named homeassistant

This implies that the environment in your homeassistant.service does not have access to the homeassistant modules being downloaded.

It looks like you have installed them user mistrovly, does your service file specify to run as that user?

1 Like

why not run it in a docker and use the HA docker image?

1 Like

I could do that, but i don’t really know much about docker

I just wiped my 14.04 server to install 16.04. I got everything re-installed but HASS which I’ll be doing when I get back from vacation on Sunday. I use a local virtual env and a simple script to start HASS in that environment as a service. If you can wait that long, I’ll post instructions then.

1 Like

I didn’t either but people on this thread convinced me it was the way to go… even though I did run on one on qnap, but now ubuntu.

Yes sir I could wait for when you get back.

I have a virtual environment setup on with proxmox; but lately things are failing every now and then. That is why I’m trying to setup another HA instance on a separate server.

Here are the steps I used to do a fresh install on an Ubuntu 16.04 server. Steps adapted from the HA links in the installation docs.

Install dependencies:

sudo apt update
sudo apt install python3-dev python3-pip
sudo pip3 install --upgrade virtualenv

Create a user and group. Give the user access to serial lines (zwave, insteon, etc)

sudo adduser --system homeassistant
sudo addgroup homeassistant
sudo adduser homeassistant dialout

Create a directory to install HA in and set it’s ownership and permissions.

sudo mkdir /opt/homeassistant
sudo chown homeassistant:homeassistant /opt/homeassistant

Change to the homeassistant user to do the installs.

sudo su -s /bin/bash homeassistant

Install a virtual env to sandbox the HA software and dependencies and activate it so further installs are done here.

cd /opt/homeassistant
python3 -m venv /opt/homeassistant
source bin/activate

Install HA from pip. I got some weird pip install errors when I did this but it didn’t seem to cause any actual problems.

pip3 install --upgrade homeassistant

I keep all the config files in the same directory (rather than having them in /home/homassistant) and I like to have the log file not in the config directory so I run it by calling:

mkdir config
./bin/hass -c /opt/homeassistant/config --log-file /opt/homeassistant/hass.log

Try that - HA should install a few things and make a default config file (let it run for a little while - it takes a bit on the first start up). Hit ctrl-c to stop it. The config directory now contains a bunch of sample config files for you to edit.

Assuming it works, now make a service to start hass automatically. Create the following systemd init file. The serivce name ‘hass’ can be ‘homeassistant’ or whatever you want.

nano hass.service

[Unit]
Description=Home Assistant
After=network.target

[Service]
Type=simple
User=homeassistant
ExecStart=/opt/homeassistant/bin/hass -c /opt/homeassistant/config --log-file /opt/homeassistant/hass.log

[Install]
WantedBy=multi-user.target

Exit the homeassistant user, copy the service file to the system, and update systemd to run the service.

exit
sudo cp hass.service /etc/systemd/system/

sudo systemctl --system daemon-reload
sudo systemctl enable hass
sudo systemctl start hass

If something goes wrong with the start command, check the logs:

sudo systemctl status hass

Finally, to make it easier to edit config files and try out code changes, I gave my regular user write permissions in the HA directory. (I’m running ACL’s on my drives which makes this simple)

sudo setfacl -R -m u:[USER]:rwx /opt/homeassistant
11 Likes

Thank you very much for this step by step. That is very helpful. Thx a lot

Thanks you TD22057,

I’ve used your instructions and it works perfectly.
I always got troubles whit the autostart when I followed the official docs.Result in reinstalling ubuntu. Your explanation is perfect!
Up to the next challenge: install homebridge!

It might be worth adding for future folks finding this; On Ubuntu 17.10 and perhaps 17.4, python 3.6 is the default. You will need to install python3.6-venv or the virtual environment line will fail.

1 Like

Your configuration worked perfectly on ubuntu 16.04 server! The only thing I had to change was to add a password to the homeassistant user and give that user sudo privileges.

Thank you for saving me hours of work!

Paul.

The reasoning behind the homeassistant user being a system user with no login privileges and no password is security. You would be better served to give your login user write access to the homeassistant files and directories.

I just installed HA using your AWESOME! procedure!

It was well written and easy to follow. Thanks!

Only one problem…

after I set up letsencrypt I get the following error every time I try to reach the server:

2018-02-24 01:13:00 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/aiohttp/web_protocol.py", line 272, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
  File "aiohttp/_http_parser.pyx", line 295, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: invalid HTTP method

as far as I know I’ve checked everything a few times and I think it looks good.

here is my config:

http:
  api_password: !secret http_password
  server_port: 8124
  base_url: xxxxx.duckdns.org:8124
  ssl_certificate: /etc/letsencrypt/live/xxxxx.duckdns.org/fullchain.pem
  ssl_key: /etc/letsencrypt/live/xxxxx.duckdns.org/privkey.pem

Does anyone see the issue?

Great step-by-step guide. -For those who may encounter python version problems:
I will mention that the /opt/homeassistant/hass did not start properly due to having python 3.5.2.
I had to install 3.5.5 from https://tecadmin.net/install-python-3-5-on-ubuntu/
and use the correct generated path /usr/local/lib in the hass-file.

Hi S77,
Can you elaborate more? I ran into the same issue.

@vfxer With no real references to “the same issue” You might be better served by fully presenting your issue.

For future reference in this thread, Ubuntu 16.04 does not natively support the required version for homeassistant. You will either need to move to a later version of Ubuntu or manually update to Python 3.5.3 or beyond.

Another (maybe simpler) way to installer newer versions of python is to use miniconda (conda package manager). You can use that to install arbitrary versions of python into a local env (conda is like virtualenv with extra features). Once I get around to updating HA, I’ll try and see how easy it is to set up a conda environment, install Python 3.6, and then the HA code into that env.