Installing AppDaemon on Ubuntu with virtualenv

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

Depending on how you’ve set up home assistant your systemd script might go by a different name or you don’t use one at all. Just comment the line After: ... and try again.

You have to change user and activate the venv:

$ sudo su -s /bin/bash appdaemon 
$ source /srv/appdaemon/bin/activate
$ cd ~/. appdaemon
1 Like

To view the logs run sudo journalctl -f -u [email protected] as your administrative pi user.

All i see is the following:

appDaemon: Unexpected error refreshing default state - retrying in 10 minutes
Jan 09 09:12:40 HA-SERVER appdaemon[28169]: 2020-01-09 09:12:40.891678 WARNING A                                                                             ppDaemon: Unexpected error refreshing default state - retrying in 10 minutes
Jan 09 09:12:41 HA-SERVER appdaemon[28169]: 2020-01-09 09:12:41.935917 WARNING A                                                                             ppDaemon: Unexpected error refreshing default state - retrying in 10 minutes
Jan 09 09:12:42 HA-SERVER appdaemon[28169]: 2020-01-09 09:12:42.974844 WARNING A                                                                             ppDaemon: Unexpected error refreshing default state - retrying in 10 minutes
Jan 09 09:12:44 HA-SERVER appdaemon[28169]: 2020-01-09 09:12:44.014636 WARNING A                                                                             ppDaemon: Unexpected error refreshing default state - retrying in 10 minutes
Jan 09 10:12:51 HA-SERVER appdaemon[28169]: 2020-01-09 10:12:51.204275 WARNING A                                                                             ppDaemon: Excessive time spent in utility loop: 1385.0ms

Any ideas what this means?

thats no normal appdaemon logging, but it shows that AD is in an errorstate.

i suggest that you set actual logs, so you know how to find it.

Sorry, but I don’t get what you mean…

Not sure what your systemd script looks like but it should be similar to this:

/etc/systemd/system/[email protected]

[Unit]
Description=AppDaemon

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

[Install]
WantedBy=multi-user.target

@cgtobi It’s actually the same as the on in your first post. Should I be removing the ‘requires’ and ‘after’ lines?

I’ve now commented out the “requires” and “after” line and am getting a bit nearer. The logs now read as follows:

Jan 09 14:50:04 HA-SERVER appdaemon[543]: 2020-01-09 14:50:04.885266 WARNING config_dir: /home exists, but is not writeable, owner: root
Jan 09 14:50:04 HA-SERVER appdaemon[543]: 2020-01-09 14:50:04.886563 WARNING appdir: /home/appdaemon/.appdaemon/conf/apps does not exist exist
Jan 09 14:50:04 HA-SERVER appdaemon[543]: 2020-01-09 14:50:04.891268 INFO AppDaemon: Loading Plugin HASS using class HassPlugin from module hassp                                            lugin
Jan 09 14:50:05 HA-SERVER appdaemon[543]: 2020-01-09 14:50:05.010272 INFO AppDaemon: HASS: HASS Plugin Initializing
Jan 09 14:50:05 HA-SERVER appdaemon[543]: 2020-01-09 14:50:05.010910 INFO AppDaemon: HASS: HASS Plugin initialization complete
Jan 09 14:50:05 HA-SERVER appdaemon[543]: 2020-01-09 14:50:05.011331 INFO Dashboards are disabled
Jan 09 14:50:05 HA-SERVER appdaemon[543]: 2020-01-09 14:50:05.011494 INFO API is disabled
Jan 09 14:50:07 HA-SERVER appdaemon[543]: 2020-01-09 14:50:07.353332 INFO AppDaemon: HASS: Connected to Home Assistant 0.103.6
Jan 09 14:50:07 HA-SERVER appdaemon[543]: 2020-01-09 14:50:07.609147 INFO AppDaemon: Got initial state from namespace default
Jan 09 14:50:09 HA-SERVER appdaemon[543]: 2020-01-09 14:50:09.445247 INFO AppDaemon: App initialization complete