Installing AppDaemon on Ubuntu with virtualenv

I updated the old installation process to be valid for the most recent version of AppDaemon.

I installed AppDaemon v1.5.2 on my RaspberryPi 3 which also runs Home Assistant and tought, why not write it down along the way and share it.

PS: For AppDaemon v.2.0 please also look here for the updated systemd service config.

DISCLAIMER: This has not yet been verified by others. Use at your own risk.

Create an AppDaemon user & group

$ sudo adduser --system appdaemon
$ sudo addgroup appdaemon

Create a directory for AppDaemon

$ sudo mkdir /srv/appdaemon
$ sudo chown appdaemon:appdaemon /srv/appdaemon

Become the new user

$ sudo su -s /bin/bash appdaemon

Set up the virtualenv

$ python3 -m venv /srv/appdaemon

Activate the virtualenv

$ source /srv/appdaemon/bin/activate

Install AppDaemon

(appdaemon)$ pip install appdaemon

Copy and edit the AppDaemon config

$ mkdir ~/.appdaemon
$ mkdir ~/.appdaemon/conf
$ mkdir ~/.appdaemon/apps
$ vi ~/.appdaemon/conf/appdaemon.yaml

appdaemon.yaml

appdaemon:
  threads: 10
  plugins:
    HASS:
      type: hass
      ha_url: <some_url>
      token: <some_long_lived_access_token>

Check the docs for the full configuration documentation.

Add Systemd Service ([email protected])

$ sudo vi /etc/systemd/system/[email protected]

[email protected]

[Unit]
Description=AppDaemon
[email protected]
[email protected]

[Service]
Type=simple
User=%i
ExecStart=/srv/appdaemon/bin/appdaemon -c "/home/%i/.appdaemon/conf/"

[Install]
WantedBy=multi-user.target

Activate Systemd Service

$ sudo systemctl daemon-reload
$ sudo systemctl enable [email protected] --now

Now AppDaemon should be up and running and good to go.

11 Likes

Thanks for the write-up! Do you happen to use the AppDaemon Beta as well for HADashboard? I have mine setup in a virtual env as well although I’m using the hass virtual env that I already use for home assistant. I can run it fine from the command line but i’m still having trouble with the systemd service.

I haven’t tried HADashboard yet, but what is your problem with systemd?

Just a quick followup on how to upgrade AppDaemon inside the virtualenv.

Upgrading AppDaemon to v2.0

$ sudo su -s /bin/bash appdaemon 
$ source /srv/appdaemon/bin/activate
$ cd ~/appdaemon_src
$ git pull origin
$ pip3 uninstall appdaemon
$ pip3 install .
$ appdaemon -c ~/.appdaemon/conf/ --convertcfg
$ rm ~/.appdaemon/conf/appdaemon.cfg

Update Systemd Service ([email protected])

$ sudo vi /etc/systemd/system/[email protected]

``

[Unit]
Description=AppDaemon
[email protected]
[email protected]

[Service]
Type=simple
User=%i
ExecStart=/srv/appdaemon/bin/appdaemon -c "/home/%i/.appdaemon/conf/"

[Install]
WantedBy=multi-user.target

``

$ sudo systemctl daemon-reload
$ sudo systemctl systemctl restart [email protected]
2 Likes

Thanks for this (belatedly) - I hope you don;t mind that I am stealing the systemctl bit to add to the README as a lot if users have trouble with this :slight_smile:

2 Likes

Not at all. I’m glad if it’s of use.

1 Like

Hello @aimc and @cgtobi,

Please I am trying to get my appdaemon running, but for some reason I don’t get why its not.

I get the following when I run sudo systemctl status [email protected]

 [email protected] - AppDaemon
   Loaded: loaded (/etc/systemd/system/[email protected]; enabled; ven
   Active: failed (Result: exit-code) since Mon 2017-12-11 06:37:36 UTC; 5s ago
  Process: 27315 ExecStart=/srv/appdaemon/bin/appdaemon -c /home/homeassistant/.
 Main PID: 27315 (code=exited, status=217/USER)

Dec 11 06:37:36 HAcontrolsystem systemd[1]: Started AppDaemon.
Dec 11 06:37:36 HAcontrolsystem systemd[1]: [email protected]: Main pr
Dec 11 06:37:36 HAcontrolsystem systemd[1]: [email protected]: Unit en
Dec 11 06:37:36 HAcontrolsystem systemd[1]: [email protected]: Failed

My service file is as thus


[Unit]
Description=AppDaemon
[email protected]
#[email protected]

[Service]
Type=simple
User=%i
ExecStart=/srv/appdaemon/bin/appdaemon -c "/home/homeassistant/.homeassistant/c$

[Install]
WantedBy=multi-user.target

I installed it under the user homeassistant.
Please any help will be very much appreciated. Kind regards

sorry don’t worry it was a silly mistake. I had installed using the homeassistant user as said, and I was using the wrong user in the service file. Changed that and I am up and running :smile:.

Will still leave this in here though, in case someone else makes the mistake.

Kind regards

Can a virtualenv created for home assistant also be used for appdaemon? Or do you need to create a separate virtualenv, user, group, etc?

They should be able to coexist, I’m not aware of any conflicts.

1 Like

I am doing this now. If there are any conflicts in the future (for instance, if I don’t want to upgrade one or the other) I will create a new virtualenv for appdaemon.

i always upgrade both when i like, and never had any conflicts.

1 Like

Thank your for this I am using it and it worked for me Appdaemon 3.0.0. I had a real mess due to python 3.4 and Debian stretch…
Thanks!!

1 Like

Thanks @cgtobi for the guide, however I’m hitting at problem. When I get to sudo vi /etc/systemd/system/[email protected] I get asked for the appdaemon user password which I dont have. So, I back out to the default pi user account and continue from there.

However, when I try run sudo systemctl systemctl restart [email protected] it fails with the following output:

Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /etc/systemd/system/[email protected].
Failed to start [email protected]: Unit [email protected] not found.

Any ideas what I’m doing wrong? My guess is that I need to enter a different service, although I’m just guessing. I’m running Home Assistant in a venv if that makes any difference?

Any help would be really appreciated.

Thanks.

I’m running homeassistant on a rPi in a virtual python environment. I followed this guide on how to get appdaemon setup but am unsure of where to go from here.

I have an appdaemon app that I’d like to get running with HA: Monitor App. Despite looking I’ve not been able to find any info on where exactly I should place app files inorder to use them, other than mention that it should be in a folder named apps.

I can see a ‘appdaemon’ folder located at ‘/srv/appdaemon/’ and I’ve manually created a sub folder within it named ‘apps’. Then I’ve created and added files ‘apps.yaml’ and ‘home_presence_app.py’ corresponding to the files in the Monitor App linked to above.

After restarting appdaemon and HA I’m not seeing any of the sensors that I was expecting the app to create. Nor, am I seeing any other signs of appdaemon apps running.

I can only assume that I’m looking in the wrong place and am now totally lost.

Any help on working this out would be greatly appreciated.

Thanks.

appdaemon expects a configuration folder.

that can be everywhere you like, as long as the filerights are right.

the configuration folder from appdaemon (lets call it config) must contain at least these 2 elements:

  1. appdaemon.yaml (the configuration file)
  2. a folder called apps containing all apps

if you want to run AD in a venv then normally you need to do these steps:

  1. make a new dir that contains the venv (not the config)
  2. create the venv (python3 -m venv /the/dir/you/created )
  3. activate the venv (source /the/dir/you/created/bin/activate )
  4. pip install appdaemon

then you can start appdaemon manually like:
appdaemon -c /the/config/dir/you/created/

or you can create a service which also points to that config dir.

the docs for appdaemon can be found here:
https://appdaemon.readthedocs.io/en/latest/index.html

edit:
i should have read the (old) first post before reacting, because its all explained there (including the appdaemon config and where to put the apps files

allthough this way of installing is also telling how to create a user called appdaemon, which isnt really neccesary.

Thanks for the response. I setup appdaemon exactly as described at the top of this thread.

Now, I see that I need to activate the venv for appdaemon and then go to ~/.appdaemon where I can now see conf and apps folders. I think I’m in the right place now.

Thanks.

dont forget that now that you have created appdaemon with a user called appdaemon, you will always need to create and edit files when you are logged on as the user appdaemon.

when you create/copy/edit files as the user pi, homeassistant or root, appdaemon will not be able to read the files!

1 Like

I just realised that. Good point!

Is there a way to see if an appdaemon app is actually running?

Thanks again.

you will always see everything that appdaemon does it its logs.
if you dont know where to look in system logs then set actual files in appdaemon.yaml (again make sure that appdaemon can write there)

https://appdaemon.readthedocs.io/en/latest/CONFIGURE.html

an example from appdaemon.yaml

secrets: /some/path
log:
  accessfile: /export/hass/appdaemon_test/logs/access.log
  errorfile: /export/hass/appdaemon_test/logs/error.log
  logfile: /export/hass/appdaemon_test/logs/appdaemon.log
  log_generations: 3
  log_size: 1000000
appdaemon:
  threads: 10
  plugins:
    HASS:
      type: hass
      ha_url: <some_url>
      token: <token>
      # cert_path: <path/to/root/CA/cert>
      # cert_verify: True
      namespace: default