AppDaemon autostart with systemd

yeah it seems like you have appdaemon in your homassistant directory.

i rather view my files like this:

you can see a lot faster where the files are actually located.

Is it a problem if they are in homeassistant? It works if I am in the homeassistant folder when I start it so I wouldn’t think it would matter. I just can’t figure out how to get it to autostart

no its no problem at all.
to get it to autostart you need to make sure these things:

  1. you need to be in the appdaemon dir where appdaemon.py is installed (so with cd go there also in your automation)
  2. you need to do it as a user that has rights to read and write to the files and dirs from appdaemon
  3. you need to know and give the right path to the configfile.

for instance it could be that all files in the homeassistant dir are automaticly owned by the user homeassistant.
then you can only run appdaemon as the user homeassistant. or you need to make sure that the user that you want to use also has rights to that dirs and files.

This is failing miserably for me. I am unsure what you were trying to get me to do. So I tried reinstalling with the following commands:

$ git clone https://github.com/acockburn/appdaemon.git

$ cd appdaemon

$ sudo pip3 install .

Here is what my config file with some stuff omitted:

[AppDaemon]
ha_url = ***
ha_key = ***
logfile = log/appdaemon_log.log
errorfile = log/appdaemon_err.log
app_dir = apps/
threads = 10

When I run:

appdaemon -c conf/appdaemon.cfg

it seems to work however my troubles come when I do the autostart.

Here are the commands I used:

sudo cp /home/mgranger/appdaemon/scripts/appdaemon.service /etc/systemd/system
sudo systemctl --system daemon-reload
sudo systemctl enable appdaemon
sudo systemctl start appdaemon
sudo systemctl status appdaemon

When I do this my error is as follows:

● appdaemon.service - AppDaemon service for Home Assistant
   Loaded: loaded (/etc/systemd/system/appdaemon.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2017-04-09 16:50:24 EDT; 5s ago
  Process: 2957 ExecStart=/usr/local/bin/appdaemon (code=exited, status=1/FAILURE)
 Main PID: 2957 (code=exited, status=1/FAILURE)

Apr 09 16:50:23 Finalizer appdaemon[2957]:   File "/usr/local/bin/appdaemon", line 11, in <module>
Apr 09 16:50:23 Finalizer appdaemon[2957]:     load_entry_point('appdaemon==1.5.2', 'console_scripts', 'appdaemon'
Apr 09 16:50:23 Finalizer appdaemon[2957]:   File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py",
Apr 09 16:50:23 Finalizer appdaemon[2957]:     config_file = find_path("appdaemon.cfg")
Apr 09 16:50:23 Finalizer appdaemon[2957]:   File "/usr/local/lib/python3.5/dist-packages/appdaemon/appdaemon.py",
Apr 09 16:50:23 Finalizer appdaemon[2957]:     "{} not specified and not found in default locations".format(name)
Apr 09 16:50:23 Finalizer appdaemon[2957]: ValueError: appdaemon.cfg not specified and not found in default locati
Apr 09 16:50:24 Finalizer systemd[1]: appdaemon.service: Main process exited, code=exited, status=1/FAILURE
Apr 09 16:50:24 Finalizer systemd[1]: appdaemon.service: Unit entered failed state.
Apr 09 16:50:24 Finalizer systemd[1]: appdaemon.service: Failed with result 'exit-code'.

In the startup file you will need to specify a full path not a relative path, looks like that might be your problem.

i dont work with this way of autostart but as i see it you need to edit the file:
/home/mgranger/appdaemon/scripts/appdaemon.service

and as i see it it should be
ExecStart=/usr/local/bin/appdaemon -c /home/mgranger/appdaemon/conf/appdaemon.cfg

Ok I got if solved. Thanks for all the help. The following are the lines I changed to get it working for me.

In the config file it looks like this:

logfile = home/mgranger/appdaemon/log/appdaemon_log.log
errorfile = home/mgranger/appdaemon/log/appdaemon_err.log
app_dir = home/mgranger/appdaemon/conf/apps/

In the appdaemon.service file it looks like this:

ExecStart=/usr/local/bin/appdaemon -c /home/mgranger/appdaemon/conf/appdaemon.cfg

2 Likes

hi @grangemd

what did you put for user?

I do not have a user called hass and I have installed appdaemon as root.

Then use root as no other user will have the correct permissions.

how about the ExecStart=

That depends where you installed everything.

I am confused totally !!!

so I do not have any users as such on my pi when I log in via ssh the user is always pi i.e. (pi@raspberry)

I installed HA via hassbian method but to access my HA configuration I just go to cd /home/homeassistant/.homeassistant and this is where I installed appdaemon i.e. pip3 install appdaemon

Also how do I verify if I have successfully configured appdaemon to run on reboot?

All sorted !!

Used appdaemon.service instead of [email protected]

1 Like