AppDaemon Q&A

i Always use what i have at hand to get what i want :wink:
if i want to put in a nail and a stone is more near then a hammer then i use a stone :wink: (or any other heavy thing that is near my hand :wink: )

but i guess i nead to read up again. so i will try to understand the kwargs part of python :wink:

Sounds very practical to me :wink:

This may be obvious, or perhaps it can’t even be done, but how would you send additional variables to a notify service call?

For instance, in the normal service call for a notification you would put:

self.call_service("notify/myservice", message = "My Message")

which equates to the following JSON body:

{
  "message":"Testing"
}

But for the official iOS app they are working on, the notifications requires, at the very least, a notification category under the data and push subheadings, in which the JSON body looks like this:

{
  "message":"Testing",
  "data":
  {
    "push":
    {
      "category":"GENERIC"
    }
  }
}

So how would this be sent in a self.service_call?

I imagine the same problem would arise for a call to the Telegram service if you were attaching a picture or a location

i dont know if that would work but i would try:

self.call_service(‘notify/notify’, message = ‘Testing’, data =’{“push”:{“category”:“GENERIC”}}’)

or

self.call_service(“notify/notify”, message = “Testing”, data [“push”][“category”]=“GENERIC”)

Yep, that looks along the right lines Rene, the first example would probably work, but I believe the second would error out as you haven’t created the “push” dictionary before you reference it and add a sub-dictionary. You can also create the dictionary with a few lines of code prior to the call, maybe like this:

data = {}
data["message"] = "testing"
data["push"] = {}
data["push"]["category ] = "GENERIC"
self.call_service("notify/notify", data}

When I created the notify() call I figured I would have to expand on it eventually as I have a very simple case for notification compared to others, and now we have iOS (which I am looking at too) I will probably need to do some work to build this out.

1 Like

I feel really stupid asking this but after reading the documentation (https://github.com/acockburn/appdaemon/blob/master/README.md) I’m still unsure how to start. I guess most of you are active ‘builders’ of apps but for now, I’m just going to be a user which is super keen on getting some apps (and especially AIMC new occupancy app) running.

I’m asking this with the perspective of a total NOOB when it comes down to Linux. To get HASS up and running I used the AIO installer and got by with the instructions I found on the AIO installer page and Brusc videos.

So given the fact that I have an RPI3 with the AIO install I still have the following Q’s (I just want to be sure as I don;t want to mess my working system);

  • In the instructions (the link above). It mentions “For either method you will need to clone the AppDaemon repository to the current local directory on your machine.” : Is the current local directory the HASS directory (where my configuration.yaml is stored) or is this the directory I get when I login to the RPI3?
  • Then: $ git clone https://github.com/acockburn/appdaemon.git
  • Then: $ cd appdaemon
  • Then: $ sudo pip3 install
  • Then: Do the configuration part according to instuctions
  • Then: run it via: $ appdaemon -c conf/appdaemon.cfg (can I run this from any directory?)
  • Then: I want to add this to startup as I don’t want to start it manually. It mentions: “To run AppDaemon at reboot, I have provided a sample init script in the ./scripts directory. These have been tested on a Raspberry PI - your mileage may vary on other systems. There is also a sample Systemd script.”. My Q: I have never added anything to a startup of an RPI. Can somebody please explain in small steps what I should do here to have the AppDeamon start automatically).
  • I guess from there on I’m good to go and can use Apps from others…

Again, sorry for taking your time for this basic stuff but I guess your answers might be very usefull for other NOOBS wanting to use Apps.

Hi there - and welcome to AppDaemon :slight_smile:

It doesn’t matter - you just need to clone the repository to somewhere where you can run the install. Some people make a directory to keep this kind of thing in - you could make that a subdirectory of the hass user if you like.

Yes - by this time, AppDaemon has been installed and is in your system path.

Take a look at the init script - it has instructions on how to set it up at the top.

Yep - once it is set up you add apps just by copying them into the correct directory and configuring them in the configuration file.

No worries :slight_smile:

Now got stuck at running Appdeamon.

Modified the config:

[AppDaemon]
ha_url = http://192.168.1.196:8123
ha_key = [deleted]
logfile = STDOUT
errorfile = STDERR
app_dir = 
threads = 10
latitude = [xxxxxx]
longitude = [yyyyyy]
elevation = 9
time_zone = Europe/Amsterdam
# Apps
[hello_world]
module = hello
class = HelloWorld

When I then do

appdaemon -c conf/appdaemon.cfg

I get below (if I remove the ha_key)

And this with HA_key being my HASS API password (basically nothing happen after “Got initital state”, if I press CTRL-C it says it can’t connect to HASS):

for completness I have done a Sudo reboot and then executed “appdaemon -c conf/appdaemon.cfg” I got below

There is an appdeamon.cfg present in that directory (owner is root while owners of other files in that dir are PI)

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)