AppDaemon Q&A

@tyfoon, i have rewritten the app from Andrew.

i have tested it for 24 hours now and i think it is working great.
you can put on several lights,scenes,switches,etc. and also based on several motion detectors.

i havent tested the multiple detectors yet, but will make those tests soon.

code can be found here:

Great stuff! Traveling for a few days so can’t try right now unfortunately

Okay, this is really becoming an issue for me. I have to delete .AppleDouble files periodically to avoid AppDaemon freaking out. Any idea what might be happening?

Regards
Martin

for me it seems that you have something wrong in your appdeamon.cfg file.

after every block you need a module and a class name.
so it must look like this:

[blockname]
module = your_module
class = your_class

do you have maybe 1 or more blocks where the module fails?

Thanks for your reply, Rene! However, all my blocks look just fine and the error disappears when I delete the .AppleDouble directory – this indicates to me that it’s an error with this directory (maybe matching as a separate script?), not an error in my current config.

i have no idea what .AppleDouble directory is.

where is it located and whats in it?

When a Mac connects to an AFP-share and modifies a file, an .AppleDouble directory is created to contain metadata that is available on OSX but not on NTFS. Read more here: https://en.wikipedia.org/wiki/AppleSingle_and_AppleDouble_formats

My workaround for now will be to create an SMB share.

i think that your right that it could be a problem.
appdaemon checks out the files in a certain area. so placing files that dont belong to the program there can cause problems.
i can think of a lot of other programs to, who could have a problem with that kind of behavior.

@aimc is there anyway possible to reinitialize an app without restarting appdaemon or changing something in the code or the config?
i would like to be able to reinit an app by a boolean, is that possible somehow?

That would have to b a feature request.

I would probably add a call that allowed a program to reload itself that you could call, and you would use the usual callbacks to monitor an input_boolean to d vide when to call it. Would that make sense?

oke. i was afraid i missed something :wink:

the reason why i ask:
there are a lot off apps running at some time.
i dont want to interupt all off them, but sometimes there are things changed in hass or in my settingsfiles and 1 want to start 1 app all over.

would be nice if i can put 1 setting in my app the way you use the constraints.
something like:

re_init = input_boolean.lightsapp.

and it would turn back to off after the reinit.

Hello everyone, a new guy to AppDaemon here, and very excited to start using it looking at the possibilities it offers.

I just installed following the Readme (using pip3) and when running the daemon manually I get an error:


2016-12-10 12:23:43.213919 INFO AppDaemon Version 1.3.6 starting
2016-12-10 12:23:44.537659 WARNING ------------------------------------------------------------
2016-12-10 12:23:44.540546 WARNING Unexpected error:
2016-12-10 12:23:44.543361 WARNING ------------------------------------------------------------
2016-12-10 12:23:44.573171 WARNING Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py”, line 763, in run get_ha_state()
File “/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py”, line 726, in get_ha_state states = ha.get_ha_state()
File “/usr/local/lib/python3.4/dist-packages/appdaemon/homeassistant.py”, line 166, in get_ha_state return r.json()
File “/usr/local/lib/python3.4/dist-packages/requests/models.py”, line 850, in json return complexjson.loads(self.text, **kwargs)
File “/usr/lib/python3.4/json/init.py”, line 318, in loads return _default_decoder.decode(s)
File “/usr/lib/python3.4/json/decoder.py”, line 343, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “/usr/lib/python3.4/json/decoder.py”, line 361, in raw_decode raise ValueError(errmsg(“Expecting value”, s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

2016-12-10 12:23:44.577585 WARNING ------------------------------------------------------------
2016-12-10 12:23:44.580293 WARNING Not connected to Home Assistant, retrying in 5 seconds


I’m currently using HA (0.34.4) through SSL using a cert signed with Let’s Encrypt, I’m not sure if the problem may be there. I tried adding both the CA cert (a fullchain.pem: combination of server, root and intermediate certificates) and the private key (a privkey.pem) but none of them work and throw an error.

So, is it needed to add any of those certs or is the cert_path referring to something else? If I need to add them, what I’m doing wrong? And, finally, if that’s not the problem, what could be?

Thank you very much in advance!

You don’t need to do anything with certs - just specify the HA path and the password. Can you post your config?

Thank you for the help @aimc. I just added the password I use to access de HA’s UI to the key ha_key just for testing (I thought this key was referring to something else) but still no luck.

My config:
[AppDaemon]
ha_url = https://myurlusingddns:1234/
ha_key = mypass
logfile = STDOUT
errorfile = STDERR
app_dir = /home/hass/.homeassistant/appdaemon/conf/apps/
threads = 10
latitude = 40.831452
longitude = -3.705621
elevation = 506
time_zone = Europe/Madrid

Apps

[hello_world]
module = hello
class = HelloWorld

Hello again @aimc I’m not sure what happened here, but now it’s working. I tried changing the url to a local IP (e.g., 10.0.14.20:1234) and got an SSL error because the host was not the one used with the certificate, then went back to the url used in the certificate, the one using the DDNS and now everything is fine… I’m thinking maybe I misspelled something when testing different combinations.

Anyway, my problem was that I was not using the ha_key, maybe you could further explain in the readme that the key is the password for HA, just for distracted guys like me :smiley:

Now I can start playing with AppDaemon, thank you!

1 Like

Hi,

I’m getting the same problem as stated by claorden above… here’s my config. I’m running Hassbian.

[AppDaemon]
ha_url = http://192.168.1.113:8123/
ha_key = <redacted pw>
logfile = STDOUT
errorfile = STDERR
app_dir = /home/homeassistant/.homeassistant/appdaemon/conf/apps
threads = 10
latitude = 33.0856
longitude = -96.6116
elevation = 190
time_zone = America/Chicago

# Apps
[hello_world]
module = hello
class = HelloWorld

and my log+traceback for reference…

2016-12-10 13:28:42.459440 INFO AppDaemon Version 1.3.6 starting
2016-12-10 13:28:42.628679 WARNING ------------------------------------------------------------
2016-12-10 13:28:42.630420 WARNING Unexpected error:
2016-12-10 13:28:42.631446 WARNING ------------------------------------------------------------
2016-12-10 13:28:42.641900 WARNING Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/appdaemon/appdaemon.py", line 763, in run
    get_ha_state()
  File "/srv/homeassistant/lib/python3.4/site-packages/appdaemon/appdaemon.py", line 726, in get_ha_state
    states = ha.get_ha_state()
  File "/srv/homeassistant/lib/python3.4/site-packages/appdaemon/homeassistant.py", line 166, in get_ha_state
    return r.json()
  File "/srv/homeassistant/lib/python3.4/site-packages/requests/models.py", line 850, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/lib/python3.4/json/__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.4/json/decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.4/json/decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

Try deleting the last “/” from the URL. I just tested adding it and it throws that error. Remove it and I think you will be fine.

1 Like

Try deleting the last “/” from the URL.

You’re absolutely correct. I figured since this is pure-python anyway, I would just go look to see what happens! As I saw your notification reply come in, I found this …

#homeassistant.py

def get_ha_state(entity_id = None):
  ...
  if entity_id == None:
    apiurl = "{}/api/states".format(conf.ha_url)
  ...

which confirms what you’re saying. Obviously if you put it as I have, apiurl would be my_url//api/states which would throw an error :slight_smile:

# 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

Well, I’ve gotten all this working … but autostart won’t! I’m running HASS in its own environment and this is losing me. I’ve followed these directions a countless number of times but it won’t start on reboot. Starting it manually is no problem though.

systemd enable appdaemon didn’t seem to do anything. It just gave me the response of “Excess arguments”

# -- /etc/systemd/system/appdaemon.service

# Sample unit file for systemd
#
# Edit top suit your environment, then copy to /etc/systemd/system
#
# run "systemd enable appdaemon" to make it start at boottime
#
[Unit]
Description=AppDaemon service for Home Assistant

[Service]
ExecStart=/usr/local/bin/appdaemon -c /home/homeassistant/.homeassistant/appdaemon/conf/appdaemon.cfg
#
[Install]
WantedBy=multi-user.target

.

# -- /etc/init.d/appdaemon

#!/bin/bash
### 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/homeassistant/.homeassistant/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

I saw the problems a user above was having, but none of the solutions there seemed to work! I’m really at a loss here.

To enable a service to start on boot do

sudo systemctl enable appdaemon.service