AppDaemon Q&A

@aimc After a few months I’m a bit frustrated that I can’t get a well working “keep lights on while motion detected” automation done. Endless amount of posts about this but nobody seems to have a decent working one.

I now use Appdaemon for state restore & occupancy simulation but I can’t (yet) make the from scratch.

In your examples I also see a ‘motion lights’ example ;does this keep the lights on or is it a ‘simple’ timer? Is there a way you can help me a bit with a “keep lights on while motion” app? I think it will make many happy.

I am gonna use motion with light this week for the first time.
im gonna use the example from andrew as base, but i think i need to change some parts.
when i get it ready i will post it on the forum.

Python3 compatibility seems to have been fixed by sseclient==0.0.14, so all is well again :slight_smile:

Hi guys!

Starting to get a grasp of what I want to achieve with my current hardware at home in HASS + AppDaemon.

Focusing mainly on getting some good schedule control as well as media play control moved over to AppDaemon due to the much freer nature of Python compared to yaml. My goal is to have most configurations inside HASS but let AppDaemon do the harder work, i.e. no automations and maybe move other parts over later on.

My question right now regards media play light control and scheduled lighting; so I have a system working that properly sets and resets brightness based on state of Plex. But my scheduling script (even though it is in AppDaemon) is pretty dumb. Since the schedules will kill the lights regardless of a movie playing or not. What I would like is for the scheduling to abort when triggered if a movie is playing, and a new schedule to be set for 10 minutes after end of movie. I can add all logic in to the schedule code, but it feels kind of ugly.

Right now these controls are in different .py’s and regardless of that would be different classes (I guess), but how can I in a simple fashion share information between these state machines to not duplicate stuff that would really be irrelevant for a clean single use class. What is the proper pythonic way of doing stuff. Should I keep them completely separated or is it a nice way of achieving this?

/R

the easieast way i can think of:

  1. an input boolean which is on as a movie is playing.
  2. that input boolean could be used as an callback constraint for existing lightschedules.
  3. when the input boolean turns off you can then activate a new schedule.

and for sharing between apps there is a part in the API.

other_apps_arg = self.config["some_app"]["some_parameter"].

To get AppDaemon's config parameters, use the key "AppDaemon", e.g.:
app_timezone = self.config["AppDaemon"]["time_zone"]

And finally, it is also possible to use the AppDaemon as a global area for sharing parameters across Apps.
Simply add the required parameters to the AppDaemon section of your config:

[AppDaemon]
ha_url = <some url>
ha_key = <some key>
...
global_var = hello world
Then access it as follows:
my_global_var = conf.config["AppDaemon"]["global_var"]

@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