AppDaemon Q&A

You had it right in the first screen - AppDaemon is connecting to hass and all is well - you just haven;t told it where the app dir is:

Set this to the full path of the apps subdirectory that has hello.py in it and you should get the welcome message and be good to go.

Also, the way you are starting it is with a relative path for the config file which assumes you are in the actual AppDaemon directory which probably wasn’t the case after that reboot - just use the full path or cd to the AppDir directory again.

Thanks! For completness it was indeed adding the full path (in my case: /home/pi/appdaemon/conf/apps) and HA_Key = [HASS API PASSWORD]

So this generates the correct output when executing: appdaemon -c conf/appdaemon.cfg (within the appdeamon dir, in my case /home/pi/appdaemon

Now I’m stuck with adding it to auto start. I’m following the below instructions:

#!/bin/bash
# APPDAEMON Service
# Add this file to /etc/init.d/
# $ sudo cp appdaemon /etc/init.d/
# Update variables PATH to suit your installation
# $ sudo nano /etc/init.d/appdaemon
# Make executable
# $ sudo chmod 755 /etc/init.d/appdaemon
# Update rc.d
# $ sudo update-rc.d appdaemon defaults
# APPDAEMON will start at boot. Check out the boot log for trouble shooting "/var/log/boot.log"
# USAGE: start|stop|status|logs

What I did:

  • I copied the appdeamon file (the one without the .service extension) to /etc/init.d/ with winSCP
  • sudo cp appdaemon /etc/init.d/ then generates an error (I guess this command copies the file to the correct directory but as it already exists due to step 1 it generates and error)
  • sudo nano /etc/init.d/appdaemon : this opens an editor. Not sure what to do here
  • $ sudo chmod 755 /etc/init.d/appdaemon
  • $ sudo update-rc.d appdaemon defaults

Then I do a sudo reboot.

I want to check what boot.log mentioned but the file does not exist.

So it could be that it’s now running but not sure how to check

Hi,
I want to test temperature sensor form a temperature sensor and to compare it with with the setpoint set using an input_slider. How can I address the temperature sensor and input_slider? I see only references to binary sensors in all the examples. thanks.

this command:

$ ps -ef | grep appdaemon

Will show you if it is running or not. When running with the init script you will want to set up logfiles for the log and error log or you won;t see what it is doing - this will also help you see if it is running or not.

The step you skipped with the editor: you need to edit the file to reflect your environment or it will almost certainly not work,

just use the appropriate entity ids they should all work. For instance, your temperature sensor should be something like sensor.temperature or some other name, When you know that you can use get_state() or listen_state() as with the other examples.

For the input slider, the same applies - you just need to know the full entity id.

Thanks. Service is not running (after reboot) but as such not a surprise.

Your referring to logging but how do you set this up? (or are you refering to HASS logging?)

Then the step with the editor; You mention it need to reflect my environment. Does this refer to the part below (the APPDAEMON_DIR and DAEMON part)?

# Must be a valid filename
NAME=appdaemon
APPDAEMON_DIR=/etc/appdaemon
DAEMON=/usr/local/bin/appdaemon
PIDFILE="$APPDAEMON_DIR/$NAME.pid"
CFGFILE="$APPDAEMON_DIR/conf/$NAME.cfg"
DAEMON_OPTS="-d -p $PIDFILE -c $CFGFILE"

The logging for AppDaemon is set up in the appdaemon.cfg file, the lines that aree like this:

logfile = /etc/appdaemon/logs/appdaemon.log
errorfile = /etc/appdaemon/logs/error.log

It doesn’t matter where the files are as long as the directory exists.

In the init (appdaemon) file, since I can’t forsee where you will install it you need, at a minimum to set the APPDAEMON_DIR to point to where you did the clone to so that it can find the executable.

Thanks, I’ve manage to do it.

1 Like

Ok, think (…) the basics are in order.

Below is output of ps -ef | grep appdaemon after a full reboot. Can you pls confirm that this confirms its running? The log file only mentions “2016-09-17 20:40:15.331272 INFO AppDaemon Version 1.3.3 starting” but nothing else.

Yes its running - buit I am guessing you still haven’t filled in the “app_dir” path in the appdaemon.cfg file. Add it in, then you should be able to restart AppDaemon with:

$ sudo /etc/init.d/appdaemon restart

It’s in the config:

[AppDaemon]
ha_url = http://192.168.1.196:8123
ha_key = xxxxxx
logfile = /home/pi/appdaemon/logs/appdaemon.log
errorfile = /home/pi/appdaemon/logs/error.log
app_dir = /home/pi/appdaemon/conf/apps
threads = 10
latitude = xxxxxxxx
longitude = xxxxxx
elevation = 9
time_zone = Europe/Amsterdam
# Apps
[hello_world]
module = hello
class = HelloWorld

When I issue: sudo /etc/init.d/appdaemon restart

I get below (which seems correct)

Before you also had a meddage aying “got initial state” - do you still see this? Can you confirm that hello.py is in the app directory?

Yes hello.py is in the Apps directory. It’s also on the log. The only thing I don’t understand that it does not show the ‘hello’ part at the bottom of the log. See below (I only removed a few " 2016-09-17 21:25:13.460325 WARNING Not connected to Home Assistant, retrying in 5 seconds" messages (guess they get there when I restarts HASS)

2016-09-17 20:38:18.425304 INFO AppDaemon Version 1.3.3 starting
2016-09-17 20:38:18.563654 INFO Got initial state
2016-09-17 20:38:18.564742 INFO Loading Module: /home/pi/appdaemon/conf/apps/hello.py
2016-09-17 20:38:18.567802 INFO Loading Object hello_world using class HelloWorld from module hello
2016-09-17 20:38:18.568927 INFO hello_world: Hello from AppDaemon
2016-09-17 20:38:18.569321 INFO Loading Module: /home/pi/appdaemon/conf/apps/occusim.py
2016-09-17 20:38:18.569642 INFO hello_world: You are now ready to run Apps!
2016-09-17 20:39:54.514429 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 20:40:15.331272 INFO AppDaemon Version 1.3.3 starting
2016-09-17 21:01:59.754202 INFO AppDaemon Version 1.3.3 starting
2016-09-17 21:02:00.757243 INFO Got initial state
2016-09-17 21:02:00.758770 INFO Loading Module: /home/pi/appdaemon/conf/apps/hello.py
2016-09-17 21:02:00.762961 INFO Loading Object hello_world using class HelloWorld from module hello
2016-09-17 21:02:00.765798 INFO hello_world: Hello from AppDaemon
2016-09-17 21:02:00.766340 INFO Loading Module: /home/pi/appdaemon/conf/apps/occusim.py
2016-09-17 21:02:00.766851 INFO hello_world: You are now ready to run Apps!
2016-09-17 21:19:42.150937 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:19:47.163978 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:20:12.235121 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:20:17.565805 INFO Got initial state
2016-09-17 21:20:17.567137 INFO Reloading Module: /home/pi/appdaemon/conf/apps/hello.py
2016-09-17 21:20:17.569402 INFO Loading Object hello_world using class HelloWorld from module hello
2016-09-17 21:20:17.571210 INFO Reloading Module: /home/pi/appdaemon/conf/apps/occusim.py
2016-09-17 21:20:17.580413 INFO hello_world: Hello from AppDaemon
2016-09-17 21:20:17.581129 INFO hello_world: You are now ready to run Apps!
2016-09-17 21:25:18.473213 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:25:23.485527 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:25:28.506359 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:25:33.525116 WARNING Not connected to Home Assistant, retrying in 5 seconds
2016-09-17 21:28:08.121257 INFO AppDaemon Version 1.3.3 starting

You are pretty much there - occasionally AppDaemon gets stuck when Hass restarts althoug most times it handles it fine. You got the hello world message the previous time before you restarted hass. Restart AppDaemon one more time and you should be good to go.

I think there is still something not ok. Just rebooted again and the only entry added to the log is: 2016-09-17 22:46:20.220475 INFO AppDaemon Version 1.3.3 starting

Nothing after that (eg not starting the hello messages after the starting point.

If I then do a sudo /etc/init.d/appdaemon restart then all goes fine (eg the hello app starts).

So it seems something is starting at startup but still not as it should… Any ideas?

p.s. could it be something with permissions? The files in /etc/init.d all have ‘root’ permissions while the ones in AppDaemon and subfolder have ‘pi’ as owner & group.

Anything in the error log?

Nope, nothing in the error log. Also if I restart HASS (just hass, not a reboot) the daemon also picks up again without any specific action from em (eg I get reloading module & the Hello message). Can’t it be the order of how things are started?

The order shouldn’t matter - if AppDaemon starts before HA it will just keep retrying until HA is up.

What isn’t clear from the discussion so far is whether or not the init script is firing on startup, it seems to be working from the command line. Can you do the following:

  1. Remove both of the existing logs.
    2, Run the reboot
  2. Post the contents of both logfiles

Can you also post the modified version of your init script.

So deleted both log files. Then issues sudo reboot

Content log:
2016-09-18 17:44:59.406231 INFO AppDaemon Version 1.3.3 starting

And the script present in /etc/init.d

#!/bin/bash
# APPDAEMON Service
# Add this file to /etc/init.d/
# $ sudo cp appdaemon /etc/init.d/
# Update variables PATH to suit your installation
# $ sudo nano /etc/init.d/appdaemon
# Make executable
# $ sudo chmod 755 /etc/init.d/appdaemon
# Update rc.d
# $ sudo update-rc.d appdaemon defaults
# APPDAEMON will start at boot. Check out the boot log for trouble shooting "/var/log/boot.log"
# USAGE: start|stop|status|logs

### BEGIN INIT INFO
# Provides:          appdaemon
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

set -e

# Must be a valid filename
NAME=appdaemon
APPDAEMON_DIR=/home/pi/appdaemon
DAEMON=/usr/local/bin/appdaemon
PIDFILE="$APPDAEMON_DIR/$NAME.pid"
CFGFILE="$APPDAEMON_DIR/conf/$NAME.cfg"
DAEMON_OPTS="-d -p $PIDFILE -c $CFGFILE"

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

case "$1" in
  start)
    echo -n "Starting daemon: "$NAME
    start-stop-daemon --start --quiet --chdir $APPDAEMON_DIR --exec $DAEMON -- $DAEMON_OPTS
    echo "."
  ;;
  stop)
    echo -n "Stopping daemon: "$NAME
    start-stop-daemon --stop --quiet --signal 9 --oknodo --pidfile $PIDFILE
    echo "."
  ;;
  restart)
    echo -n "Restarting daemon: "$NAME
    start-stop-daemon --stop --quiet --signal 9 --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --chdir $APPDAEMON_DIR --exec $DAEMON -- $DAEMON_OPTS
    echo "."
  ;;
  logs)
    echo "See the logs of the Dashing."
    tail -f $APPDAEMON_DIR'log/thin.log'
  ;;

  *)
  echo "Usage: "$1" {start|stop|restart}"
  exit 1
esac

exit 0