AppDaemon Q&A

That’s it, in the instructions in the comments of the service state that to enable we have to:

sudo systemctl --system daemon-reload

That confused me at first too.

Regarding the autostart, do you see many errors on the log if you restart the system? I get many connection-to-HA errors and finally the correct block with the HelloWorld. I think that the problem is that we have to start AppDaemon after HA has completely booted up so I tried adding in the appdaemon.service:

[email protected] (name of your HA service)

But still some errors thrown into the log. I tried adding a delay (e.g., OnBootSec=8min) too but with no luck. Anyone found a solution to this? AppDaemon is booting fine, but I would like to remove those errors from the log.

Thanks!

Thanks for this tip. I struggled to get it going and this was the cause. It is specific to mounting the drive and editing the files on a Mac. The OS makes the apple double file for each file in each directory of a network drive. This screws up appdaemon.
Deleting these files and all is well.
Is there anyway to have appdaemon ignore the .appledouble files?

this setting turns this property off and seems to work.
defaults write com.apple.desktopservices DSDontWriteNetworkStores true

info gleaned from
https://guylabs.ch/2014/12/11/get-rid-of-ds_store-files-on-mac-os-x-10-10/

(homeassistant) homeassistant@raspberrypi:/home/pi $ sudo systemctl enable appdaemon.service
Synchronizing state for appdaemon.service with sysvinit using update-rc.d...
Executing /usr/sbin/update-rc.d appdaemon defaults
Executing /usr/sbin/update-rc.d appdaemon enable

Well we’re getting somewhere… but I still don’t think it’s running. :frowning:

(homeassistant) homeassistant@raspberrypi:/home/pi $ ps -ef | grep appdaemon
homeass+  1312   875  0 13:30 pts/0    00:00:00 grep --color=auto appdaemon

I’m new to appdaemon and Python. How do you debug your code syntax? All I can see from the documentation is how to run it again by restarting appdaemon. And that doesn’t tell me my syntax errors.

your syntax errors get listed in your error logfile. (the one you have set in your appdaemon.cfg)
you dont even need to restart appdaemon. as soon as you save a changed app it will re initialize and if you have any errors in your code it will show up in the error log.

ok, thanks.

The tutorial at https://github.com/home-assistant/appdaemon/blob/master/API.md says to import homeassistant.appapi, but appdaemon is complaining about it not existing.

you problably didnt read it right.

the line should be:

import appdaemon.appapi as appapi

edit: sorry you did read it right but i think thats an doc error? @aimc

great because that doesn’t give any errors. Do I have to do anything other than set the ha_url in the appdaemon.cfg file to integrate it with HA? It doesn’t seem to be responding to anything I do in HA?

what code do you have in your app?
and what do you have in your cfg?

appdaemon.cfg

[AppDaemon]
ha_url = http://localhost:8123
#ha_key = 
logfile = /home/hass/appdaemon/appdaemon.log
errorfile = /home/hass/appdaemon/appdaemon.err
app_dir = /home/hass/appdaemon/conf/apps
threads = 10
latitude: 35.189788
longitude: -89.708958
elevation: 104
time_zone: America/Chicago
# Apps
[hello_world]
module = hello
class = HelloWorld
[XmasTreeOn]
module - xmastree
class = XmasTreeOn

xmastree.py app (hello world works)

(hass) hass@hass:~/appdaemon/conf/apps$ cat xmastree.py 
import appdaemon.appapi as appapi
#import homeassistant.appapi as appapi
#
# XmasTree App
#
# Args:
#

class XmasTreeOn(appapi.AppDaemon):

  def initialize(self):
     self.log("Turning on Xmas Tree")
     self.listen_state(self.adjust_tree_state, entity = "switch.den_power_outlet",new = "on")

  def adjust_tree_state(self, entity, attribute, old, new, **kwargs):
    lux = float(new)
    self.log("turning Light off")
    self.turn_off("light.den_fan_light")
(hass) hass@hass:~/appdaemon/conf/apps$

if you have an entity in hass which is called switch.den_power_outlet then your callback should go off when the switch is turned on.
it should then turn off light.den_fan_light

in your logfile you should at least see the line “turning on xmas tree” appear.

if thats not there the there should be something in the error log.

Is it just a copy paste error because I see a big problem in your configuration : module - xmastree should be module = xmastree

2 Likes

i missed that 1.

that is probably the problem. :wink:

It just caught my eye for some reason :slight_smile:

That was it. Now I’m getting another error when I turn on the power outlet, but I haven’t dug into that yet.

But now you’re in the code, in your own domain, easier to debug.

Ok,
I’m getting messages from the initialization function, but when I turn on the switch, I get the following.
Here is the error I am getting - TypeError: adjust_tree_state() takes 5 positional arguments but 6 were given

The documentation says that

For state callbacks, a class defined callback function should look like this:

  def my_callback(self, entity, attribute, old, new, **kwargs):
    <do some useful work here>

My code has def adjust_tree_state(self, entity, attribute, old, new, **kwargs):

Which are the same variable names as the documentation calls for (I’m not very inventive until I need the variables for something that deserves a different name).

So it’s not making sense to me.

your code is right just lose the ** before kwargs.

Wonderful, got it working!!!

Now I can start working on getting something actually useful to work. :slight_smile:

Thanks

1 Like

i was just working on a new app myselve.
nothing special but now we can switch lights on and off without touching anything