AppDaemon 4.0.1. Installation in Python Virtual Environment on Raspberry Pi 4 [Instruction]

I wanted to share my installation-instructions since i struggled a lot getting AppDaemon to run on my RaspberryPi 4.
I’m running homeassistant in a python venv on raspberry pi 4.
The following steps will guide you through the process of installing AppDaemon, at time of writing version 4.0.1 in another python virtual environment.

#######-Parts need to be edited

Install packages:

sudo apt install python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev git

Create User appdaemon:

sudo useradd -rm appdaemon
sudo addgroup appdaemon
sudo mkdir /srv/appdaemon
sudo chown appdaemon:appdaemon /srv/appdaemon

Create virtual environment

sudo -u appdaemon -H -s
cd /srv/appdaemon
python3 -m venv .
source bin/activate

Install AppDaemon from git

cd /srv/appdaemon
git clone https://github.com/home-assistant/appdaemon.git
cd appdaemon
pip3 install .

If later you want to update AppDaemon:

sudo -u appdaemon -H -s
cd /srv/appdaemon
source bin/activate
cd /srv/appdaemon/appdaemon
git pull
pip3 install --upgrade .

Config AppDaemon:

mkdir -p /home/appdaemon/.appdaemon/conf/apps
mkdir /home/appdaemon/.appdaemon/log

cd /home/appdaemon/.appdaemon/conf
nano appdaemon.yaml

EDIT the ####### Parts in appdaemon.yaml:

logs:
  main_log:
    filename: /home/appdaemon/.appdaemon/log/appdaemon.log
  access_log:
    filename: /home/appdaemon/.appdaemon/log/access.log
  error_log:
    filename: /home/appdaemon/.appdaemon/log/error.log
  diag_log:
    filename: /home/appdaemon/.appdaemon/log/diag.log
    log_generations: 5
    log_size: 1024
    format: "{asctime} {levelname:<8} {appname:<10}: {message}"
appdaemon:
  time_zone: Europe/Berlin ####### your timezone #######
  latitude: ####### your latitude in form of xx.xxxxxx ########
  longitude: ####### your longitude in form of xx.xxxxxx ########
  elevation: 100 ####### your elevation in meters #######
  plugins:
    HASS:
      type: hass
      ha_url: http://127.0.0.1:8123
      token: ####### your long-lived access token #######
http:
    url: http://127.0.0.1:5050
admin:

Save File with ctrl+o
Exit nano with ctrl+x

Tell AppDaemon the apps it should start by creating an apps.yaml in your conf/apps folder:

cd /home/appdaemon/.appdaemon/conf/apps
nano apps.yaml

apps.yaml:

helloworld:
  module: hello
  class: helloworld

Save File with ctrl+o
Exit nano with ctrl+x

Meaning of apps.yaml:
AppDaemon will initialize helloworld from module hello.py with class helloworld

create the hello.py file:

cd /home/appdaemon/.appdaemon/conf/apps
nano hello.py

hello.py:

import adbase as ad
#
# Hello World App
#
#Args:
#

class helloworld(ad.ADBase):

    def initialize(self):
        self.adbase = self.get_ad_api()
        self.hass = self.get_plugin_api("hass")
        self.adbase.log("Hello from AppDaemon!")

Save File with ctrl+o
Exit nano with ctrl+x

Option 1: run AppDaemon from Commandline:

/srv/appdaemon/bin/appdaemon -c home/appdaemon/.appdaemon/conf/appdaemon.yaml

Option 2: run AppDaemon as Service
execute the following commands as your normal user with sudo permission, not in the venv

sudo nano /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/appdaemon/.appdaemon/conf/

[Install]
WantedBy=multi-user.target

Save File with ctrl+o
Exit nano with ctrl+x

Make the service autostart and start now:

sudo systemctl enable [email protected] --now

Check the /home/appdaemon/.appdaemon/log/appdaemon.log
eg. by

cat /home/appdaemon/.appdaemon/log/appdaemon.log

It should show the “Hello from AppDaemon!” String

I hope this will help others when installing AppDaemon 4.0.1

6 Likes

Thank you very much for this excellent tutorial.
I am running HA on RPi3b, Debian Buster, venv. python 3.8 separatelly installed.
I expirienced a problem installing cryptography dependency, caosed by missing rust compiler.
Resolved by following:
#Upgrade pip:
pip3.8 install --upgrade pip
#Set variable following recomendation on https://cryptography.io/en/latest/installation.html#rust
export CRYPTOGRAPHY_DONT_BUILD_RUST=1
Resumed installation and worked as charm.
Best regards, and thanks again.

Thanks for the very useful, concise AppDaemon installation guide :slight_smile: It works perfectly on my R.Pi4 running Raspbian.