‘Invalid argument’ error when enabling auto boot service

Been following ‘Autostart using systemd’ and ‘Manual installation on a Raspberry Pi’ and got following error:

‘Failed to enable unit: File [email protected]: Invalid argument’

Same error in pi and homeassistant user accounts. File exists in both with template details entered. Changing ownership to homeassistant wasn’t possible.

The word after the @ in the file name is interpreted as %i in the .service file. For HA, this is normally set in the User= line, so unless you have a user named raspberry on your system, its likely to give an error.

You normally want to run HA as homeassistant user, so the correct name for the file is [email protected]. It should always be owned by root.

TBH, I don’t know why the instructions don’t just use the filename home-assistant.service and set User=homeassistant in the file, but that’s the way its has always been.

Still getting same error. Everything you say has been followed. I’ve used the Virtual Environment on homeassistant account, owner is root. Since homeassistant isn’t in sudoers group, I don’t know if executing commands without including ‘sudo’ at start as homeassistant user makes any difference.

If you paste the output of

cat /etc/systemd/system/[email protected]

someone might be able to spot the problem.

For user homeassistant:

[Unit]
Description=Home Assistant
After=Network-online.target

[Service]
Type=simple
User=homeassistant
ExecStart=/srv/homeassistant/binary/hass -c
“/home/homeassistant/.homeassistant”

[Install]
WantedBy=multi-user.target

Gave following error:
‘Failed to enable unit: The name org.freedesktop.Policykit1 was not provided by any .service files’

For user pi:

The only difference was User=pi

and gave following error:
‘Failed to enable unit: File [email protected]: Invalid argument’

when not in virtual Python environment, and:

‘Failed to enable unit: The name org.freedesktop.PolicyKit1 was not provided by any .service files’

when in virtual Python environment.

User Pi would not have access to /home/homeassistant/.homeassistant so attempting that is a waste of time.

I can’t reproduce the error you are getting, which suggests the problem is elsewhere, but /srv/homeassistant/binary/hass should be /srv/homeassistant/bin/hass, and make sure that there is no line break after the -c. Its probably just some word wrapping, but it will cause a problem if it isn’t. I took your file and made these changes, and everything started fine

[Unit]
Description=Home Assistant
After=Network-online.target

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

[Install]
WantedBy=multi-user.target

resulted in

$ sudo systemctl daemon-reload 
(homeassistant) homeassistant@graham-lubuntu17:~
$ sudo systemctl start home-assistant.service 
(homeassistant) homeassistant@graham-lubuntu17:~
$ sudo systemctl status home-assistant.service 
● home-assistant.service - Home Assistant
   Loaded: loaded (/etc/systemd/system/home-assistant.service; disabled; vendor preset: enabled)
   Active: active (running) since Wed 2018-02-14 18:16:20 GMT; 5s ago
 Main PID: 7747 (hass)
    Tasks: 12 (limit: 4915)
   CGroup: /system.slice/home-assistant.service
           ├─7747 /srv/homeassistant/bin/python3 /srv/homeassistant/bin/hass -c /home/homeassistant/.homeassistant
           ├─7773 ping -n -q -c 5 -W1 naos-pc.local
           └─7785 ping -n -q -c1 -W1 192.168.0.5

Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded frontend from homeassistant.components.frontend
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded api from homeassistant.components.api
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded http from homeassistant.components.http
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded websocket_api from homeassistant.components.websocket_api
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded system_log from homeassistant.components.system_log
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded history from homeassistant.components.history
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded recorder from homeassistant.components.recorder
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.loader] Loaded logger from homeassistant.components.logger
Feb 14 18:16:22 graham-lubuntu17 hass[7747]: 2018-02-14 18:16:22 INFO (MainThread) [homeassistant.setup] Setting up logger

If this doesn’t fix your error, can you run HA manually (as homeassistant user in the Virtual Environment)? If you can, the problem is something to do with systemd, which is beyond my experience. If sudo systemctl reload doesn’t fix it I’m stuck.

Taking out line break allowed a symbolic link to be created when auto start service was enabled, according to command line message.

Not sure how auto start is supposed to happen on boot, as the raspbian login prompt appears. I was expecting hass to start loading without such prompts.

That is a good sign :grinning:

That is normal. The HA service will start independently of logins. You should be able to access the web page without anyone logging in.

The HA log file will be in /home/homeassistant/.homeassistant/homeassistant.log and you can do

systemctl status home-assistant.service

to get the status of a the service.

Is this in docs? Cheers mate!

1 Like