AppDaemon Q&A

Just a quick check: to use apps nothing needs to be added to any yaml configuration file in the home assistant dir? Its just copying the app into the correct directory (apps) and configuring them in the configuration file. Correct?

That is correct yes.

Hi Sorry me again

I am trying to set a sunset delay off 15 mins but i keep getting errors.

self.run_at_sunset(self.sunset_cb, "sunset + 00:15:00")

self.run_at_sunset(self.sunset_cb, “sunset + 00:15:00”)
TypeError: run_at_sunset() takes 2 positional arguments but 3 were given

Thanks.

That call doesn’t take a positional parameter for the offset, you need something like:

self.run_at_sunset(self.sunset_cb, offset = 15 * 60)

It is correct in the API doc - let me know if you found it somewhere else that I need to correct.

Thanks that worked great i can go to bed now…

So, I updated to the latest version and I am seeing a weird situation. When I start appdaemon from the command line, it starts and loads my app without any issues. Here’s the log entries

2016-10-01 17:38:07.601995 INFO AppDaemon Version 1.3.6 starting
2016-10-01 17:38:12.888901 INFO Got initial state
2016-10-01 17:38:12.890812 INFO Loading Module: conf/apps/toggleoutsidelights.py
2016-10-01 17:38:12.893921 INFO Loading Object toggle_outside_lights using class ToggleOutsideLights from module toggleoutsidelights
2016-10-01 17:38:12.916375 INFO Waiting for App initialization: 1 remaining
2016-10-01 17:38:12.918572 INFO toggle_outside_lights: Toggle Outside Lights Initialized…
2016-10-01 17:38:12.919391 INFO toggle_outside_lights: 2016-10-02 07:15:13
2016-10-01 17:38:13.918882 INFO App initialization complete

I followed your instructions to start it at boot using init.d. When it starts up, it doesn’t load my app. It just starts, but doesn’t show that my app is loaded.

2016-10-01 17:45:33.257601 INFO AppDaemon Version 1.3.6 starting
2016-10-01 17:45:39.335874 INFO Got initial state
2016-10-01 17:45:39.337204 INFO App initialization complete

Could be a path issue in the script config file? This is what I used…

APPDAEMON_DIR=/home/pi/appdaemon

If I go into the config file and put a space, delete it and then save the file, the log shows that a change was made, but still doesn’t load the app.

2016-10-01 17:45:33.257601 INFO AppDaemon Version 1.3.6 starting
2016-10-01 17:45:39.335874 INFO Got initial state
2016-10-01 17:45:39.337204 INFO App initialization complete
2016-10-01 17:48:28.004618 INFO /home/pi/appdaemon/conf/appdaemon.cfg modified
2016-10-01 17:48:53.004659 INFO /home/pi/appdaemon/conf/appdaemon.cfg modified

Lol - happy to hear AppDaemon is helping you sleep :wink:

1 Like

Could you post both the command lines you used in the first example, as well as your init file please?

Here’s the command line I use:

Here’s the init file:

#!/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

One other thing I noticed. When I tried to launch it via command line, I got a permission error when it tried to write to the log file. The log file was created via the init.d process. I had to delete both log files before I could launch it via the command line without getting an error.

Here’s what happens if I start out fresh and let the init.d create the log files and then try to run it via command line:

Can you post the init file in code tags please?

That is not surprising - init runs as root so when it creates files they are owned by root. Subsequently running as a normal user will give you permission problems as it tries to reopen the previously created log files.

ok, that makes sense. How do I post in code tags?

Ok, figured it out how to post in code tags. Here’s the init file

#!/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

Ok, that looks good - what is in your appdaemon.conf?

[AppDaemon]
ha_url = https://######.duckdns.org/
ha_key = ########
logfile = /home/pi/appdaemon/logs/appdaemon.log
errorfile = /home/pi/appdaemon/logs/error.log
app_dir = conf/apps/
threads = 10
latitude = 99.99999999
longitude = -99.9999999
elevation = 17
time_zone = America/Chicago

# Apps
[toggle_outside_lights]
module = toggleoutsidelights
class = ToggleOutsideLights

I think the problem is that you have a relative directory for your appdir - make it absolute and
you should be good to go.

Good catch!! Let me make that change and see if it fixes the issue.

That did it!!! Thanks for all of your help!!

Also, a big thank you for all the work that you are putting into this app!!!

1 Like