Need help getting started with AppDaemon

Trying to migrate to appdaemon since it looks like it does so much of what I want to do, but having trouble even getting started. I see perfectly how to put data into HASS, but no clue how to call things in appdaemon from HASS other than some of the state change things, but even those aren’t real clear. So much documentation and really nothing that spells out how to get started.

I have an mqtt_listener that listens for events published from HASS (used to just call a shell command but didn’t want to start a new python environment and had a listener for a custom snips tts already).

So I have this function in appdaemon that works fine I imagine (does in my listener), how the heck do I call it from HASS? I guess I could create a sensor, and flip the state of it or something but that seems roundabout, when all I want to do is call it from other scripts with HASS at this point. As things go I would call it from other parts of this module and I can see docs on that.

So the hard parts seem easy but what seems like it should be easy to me is obtuse.

Thanks for any insight you can give.
Tod

The way I see it is the App listens for a state/event change in HA and does a callback on the specific event/state which the app does something with, so you don’t call an App it responds to a change in HA, well at least that’s how interpret how it works. However my knowledge is limited as I’ve only just started learning about it. Perhaps @ReneTode or @aimc could shed more light :slight_smile:

Actually, now that I dig all the way events might work for this. As it is all the docs talk about is appdaemon signalling back to hass, but I’ll dig deeper, thanks…

OK, events works fine for me, thanks for that prompt. They do have to be uppercase for whatever that is worth.

i wrote a starttup for appdaemon users.
the docs are a lot, because appdaemon gives a lot.
maybe this helpes:

Thanks a ton @keithh666 and @ReneTode I know just from browsing how helpful you have been to everyone working with appdaemon.

I wish I’d seen that before, would probably have saved me some frustration! Would be good to have that linked in the AppDaemon and/or HA docs. If I get time I’ll do a pull request.

So the docs are a little vague is on events and I had even read this line which to me again read as AD sending events to HA

For instance, if you would like to create a UI Element to fire off some code in Home Assistant…

Could be written as:

For instance, if you would like to create a UI Element in HomeAssistant to fire off some code in AppDaemon

Anyway, I got past that furstration level so working hard towards my next stumbling block. The 3 hours of sleep I got last night probably won;'t help.

1 Like

the docs are written in a way to explain how things work.
and allthough they are pretty good, they can be a little overwelming for newbies.
thats why i wrote my beginner course in a way that even someone who has no knowledge of anything can understand it.
it is linked severa times here on the forum, but still you need to stumble onto it :wink:

ill have a talk with @aimc if he thinks its worth a line in the docs :wink:

I’m sure it is :wink:

Link it here!

lol 2 posts back :wink:

1 Like

I have a short attention span …

1 Like

i know its after 17:00 and weekend :wink:

1 Like

I saw the new tutorials in the docs, awesome!

So that said, I wanted to avoid the workaround of passing sensor data to a script. I had all this working perfectly with some mqtt and custom sensor data, but all seemed kludgy. I had a custom mqtt listener just to avoid instantiating a python with a lot of includes every time, but of course appdaemon seemed absolutely perfect for this (which it absolutely is, just the automatic code refresh is a godsend!)

My use case is a custom tts and assistant stuff using snips. Snips passes an intent with a raw value of “five minutes” and a bunch of other more useful things like housr=0,minutes=5,seconds=0. So initially I wanted to get that data available to hass, so implemented a pull request for that. Ok, now HASS has it, need to get it to app daemon, could of course use a sensor, but nah, lets implement event_data_template so we can just pass it directly in an event. See I wasn’t just complaining and actually did something about it, LOL.

So in this, a script test_jarvis_timer passes data to a script set_timer, which fires an event to appdaemon with the custom data. Outside of test this would be a snips intent calling the service with similar arguments.

test_jarvis_timer.yaml

test_jarvis_timer:
  sequence:
    - service: script.set_timer
      data_template:
        name: "turkey"
        hours: 0
        minutes: 0
        seconds: 5

set_timer.yaml

set_timer:
  sequence:
    - event: JARVIS_SET_TIMER
      event_data_template:
        name: '{{ name }}'
        hours: '{{ hours }}'
        minutes: '{{ minutes }}'
        seconds: '{{ seconds }}'

From the logs (stripped for readability)

hass:  INFO (MainThread) [homeassistant.helpers.script] Script test_jarvis_timer: Running script             
hass: INFO (MainThread) [homeassistant.helpers.script] Script test_jarvis_timer: Executing step call service
hass: (MainThread) [homeassistant.helpers.script] Script Set_timer: Running script                    
hass: INFO (MainThread) [homeassistant.helpers.script] Script set_timer: Executing step JARVIS_SET_TIMER
appdaemon:  INFO jarvis: jarvis_set_timer: {'name': 'turkey', 'hours': '0', 'minutes': '0', 'seconds': '5'}
appdaemon:  INFO jarvis: duration: 5                                                                 
...5 seconds HAS passed...
appdaemon:  INFO jarvis: jarvis_timer_done: {'timer_name': 'turkey'}
appdaemon:  INFO jarvis: jarvis_say: {'text': 'OK, your timer for turkey is done'}

Submitted a pull request to implement the event_data_template here:

Thanks again so much for your work on appdaemon. I have been working with Ansible a lot of the last few months so built a pretty good understanding of the good and bad points in yaml and jinja2 templating, so I can make some things happen, but it’s so much easier without the middle man of yaml (which to be fair, is not really meant to be much more than what it is).

1 Like