So, I’m trying to get my pi to autostart hass. I used the manual raspberry pi installation and then went to the auto start directions. Using the directions here "Autostart Instructions, I try to add that whole part at the beginning in, and after I type in the final EOF’, it asks for a password. I’m not sure what password I’m suppose to use and everything I use comes back as su: Authentication Failure. Any help?
You should use a password of user from which you execute this command.
That user should be able to use sudo.
What would the password be though? The user I use is pi and raspberry doesn’t seem to work.
can you try the following:
sudo echo '[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=%i
ExecStart=/usr/bin/hass
[Install]
WantedBy=multi-user.target’ > /etc/systemd/system/[email protected]
Okay I’ll get it.
You should use sudo su -c 'cat bla bla bla...'
instead just su.
And password for user ‘pi’ should work.
Alright, so I’m trying again, starting fresh because I’m not sure if I messed something up earlier. Here is the code I’m using: Autostart Options
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=hass
ExecStartPre=source /srv/hass/bin/activate
ExecStart=/srv/hass/bin/hass -c “/home/hass/.homeassistant”
[Install]
WantedBy=multi-user.target
This was in the second box on that page (I’m sorry, I’m really just learning on the fly here). Couple of questions about this code:
-
I used the Raspberry Pi manual setup. My config file is located at /home/homeassistant/.homeassistant. Should this be used somewhere in this code above?
-
Do I need to include all the spaces in this code when writing it?
-
Do I need to end this with the EOF’ from the box above on the autostart page? (Also what does EOF stand for?)
Thanks!
Did you install HA with VirtualEnv support?
Can you post the path where HA was installed?
Yes, instead of /srv/hass you should be using /home/homeassistant. You should let us know whether you’ve used the virtualenv install, but I presume not.
In most cases - yes. I presume your HA doesn’t start because your path is wrong.
Yes, you need EOF, it tells the ‘cat’ command what is the last thing to write to a file. Note at the beginning there’s also EOF? This is where ‘cat’ is instructed to put all lines into the file until the text ‘EOF’ appears.
EOF stands for “End of file”.
According to the directions I followed for manual installation on a raspberry pi, it says it will install it in a virtualenv:
Is this something I should have avoided? Does it matter? I’m assuming that whenever I want to work within the virtualenv, all I need to do is activate it with:
$ source /srv/homeassistant/homeassistant_venv/bin/activate
O and when I asked about the spaces, I was mostly talking about the extra blank line between parts like the [service] section and the [install] section.
Virtualenv is preferred. It will isolate your hass installation from the main Raspbian system so a raspbian update won’t break it.
Indeed you should use
$ source /srv/homeassistant/homeassistant_venv/bin/activate
to activate the virtual environment and start/upgrade home assistant.
Blank lines don’t matter in the service file, however, you should name this file:
/etc/systemd/system/[email protected]
So the first line that creates the autostart service file should be changed from:
sudo su -c 'cat <> /etc/systemd/system/home-assistant@[your user].service
to:
sudo su -c 'cat <> /etc/systemd/system/[email protected]
I’m trying to learn this as I go, so sorry about the questions. You said the user should be switched to Homeassistant, but according to the website giving directions for automatically starting home assistant, the user is pi. On my terminal, when I start home assistant, I first activate the virtualenv, then type hass. It is coming from
(homeassistant_venv) pi@raspberry: $
Doesn’t this mean the username is pi? Which would mean:
This:
sudo su -c 'cat <> /etc/systemd/system/[email protected]
should be:
sudo su -c 'cat <> /etc/systemd/system/[email protected]
Again, sorry if this is a simple question, just trying to learn.
The path to my HA is /home/homeassistant/.homeassistant
Hi,
I have exactly the same problem like dbroersma.
I installed Home Assistant on a Raspberry Pi with a manual installation in a virtualenv.
That works without a problem.
But I don’t get the autostart with systemd (in virtualenv) running.
The first problem is the command
su -c 'cat <<EOF >> /etc/systemd/system/home-assistant@[your user].service
This didn’t work in my installation. I used
sudo su -c 'cat <<EOF >> /etc/systemd/system/home-assistant@[your user].service
With this change i could create the systemd file but i don’t work.
I don’t understand the following parts:
[your user]
Is this my normal Raspberry user “pi” or is it the created user “homeassistant” or …?
user=hass
Is this correct, or do I have to enter “pi” or “homeassistant” here?
ExecStartPre=source /srv/hass/bin/activate
This is not the correct path in a virtualenv installation.
Is /srv/homeassistant/homeassistant_venv/bin/activate
right?
ExecStart=/srv/hass/bin/hass -c “/home/hass/.homeassistant”
This is not the correct path in a virtualenv installation.
Is ExecStart=/srv/homeassistant/homeassistant_venv -c "/home/hass/.homeassistant"
the right one?
Thanks.
I am also wrestling with this. I have some programming experience, but am new to python.
I installed Home Assistant on a Raspberry Pi using the manual instructions.
I attempted to adapt the autostart instructions and ended up with the following Service section in the systemd file
[Service]
Type=simple
User=homeassistant
ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate
ExecStart=/srv/homeassistant/bin/hass -c “/home/homeassistant/.homeassistant”
This fails with the message
[/etc/systemd/system/[email protected]:8] Executable path is not absolute, ignoring: source /srv/homeassistant/homeassistant_venv/bin/activate
For what it is worth, “/srv/homeassistant/homeassistant_venv/bin/activate” does exist.
If you’ve followed this tutorial:
It instructs you to create a new user named homeassistant and install the virtual environment as that user. For that reason you should be running Home Assistant as the user homeassistant and not homeassistant
@dbroersma you are incorrectly activating the virtualenvironment as user pi, which might lead to permission problems later on. You should closely follow the tutorial without logging in/out:
Note the following lines:
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
…
source /srv/homeassistant/homeassistant_venv/bin/activate
Whenever you are starting/stopping Home Assistant you should always first execute those commands to avoid potential problems with user permissions!
Note the line in the tutorial:
(homeassistant_venv) homeassistant@raspberrypi:/srv/homeassistant $ pip3 install homeassistant
The part in bold implies that installation and subsequent execution should happen as the homeassistant user, and not the default user pi!
@OlBe the [your user] part should be replaced with the user that is supposed to run Home Assistant, in the tutorial this user is named homeassistant, so the file should be named /etc/systemd/system/[email protected]
@jcroed I think it’s safe to remove the line ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate. Just to be safe comment out by prepending a # at the beginning of the line:
ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate
To the best of my knowledge /src/homeassistant/bin/hass is virtualized so you shouldn’t need to activate the venv beforehand.
Generally speaking I think you should all be using the All-in-one installer. When doing the manual install you’re supposed to have some knowledge of Linux/Unix permissions, systemd, and python venv.
It does quite a lot of optional components but should work out of the box.
Thanks! Didn’t realize I was doing the wrong user.
As for the all in one, can’t get it to work on the pi3. Hangs or says there is an error and quits in the middle.
So final adoption of this file before moving fowards, I have this:
su -c 'cat <> /etc/systemd/system/[email protected]
[Unit]
Description=Home Assistant
After=network.target
[Service]
Type=simple
User=homeassistant (I changed this from hass)
ExecStartPre=source /srv/homeassistant/homeassistant_venv/bin/activate I changed this from source /srv/hass/bin/activate – So this line should be removed???
ExecStart=/srv/homeassistant/homeassistant_venv/bin/hass -c “/home/homeassistant/.homeassistant” I changed this from /srv/hass/bin/hass -c “/home/hass/.homeassistant”
[Install]
WantedBy=multi-user.target
EOF’
I also make sure I correctly switch to the homeassistant username using this commands:
sudo su -s /bin/bash homeassistant
cd /srv/homeassistant
source /srv/homeassistant/homeassistant_venv/bin/activate
If this is all correct, it all makes sense to me. Can anyone quick look over this to make sure it seems to make sense?
Thanks!
Following the advice of kirichkov, I commented out the ExecStartPre line to get it to work.
Who should we notify to get the instructions on th eautostart page corrected?
You can open an issue at the github bugtracker
I believe the appropriate repo would be: