This is what I have, in AppDaemon (but it could easily be done in an automation.yaml)!
When my phone starts my morning alarm, Tasker shoots out an event on the HomeAssistant REST API called external_wakeup. The following is a snippet of the app I use to govern external events.
import appdaemon.appapi as appapi
from datetime import datetime
class ExternalEventsListener(appapi.AppDaemon):
def initialize(self):
self.listen_event(self.wakeup, event='external_wakeup')
...
def wakeup(self, event_name, data, kwargs):
time = datetime.now().strftime('%A, at %-I:%M')
conditions = self.get_state('sensor.pws_weather')
precip_chance = data['rain_chance']
temperature = round(int(float(self.get_state('sensor.pws_feelslike_f'))))
greeting = ("Good morning! It's currently {}. The weather out is {} with a {} percent "
"chance of rain. It is {} degrees outside. It's time to get up!"
.format(time, conditions, precip_chance, temperature))
self.call_service('tts/google_say', entity_id='media_player.bedroom', message=greeting)
So every morning I get a custom greeting that tells me what the current time is and what the weather’s like outside. Things I instinctively check each morning before getting ready for the day.
Absolutely - as long as tasker is capable of hitting an arbitary URL path with a post request, and either setting a specific header, or appending URL parameters you can go straight to an app.
@poebae You should be able to get it working with an HTTP POST in Tasker.
I would recommend you check out the below links. It used to be that we had to use Home Assistant as the method of communication between Tasker and AppDaemon, but that is no longer the case and Andrew offers a direct mode of communication, with a slight bit of setup.
Thanks for the links. I’ve read through both a bunch of times and still trying to get my head around it. Does the new functionality significantly change the code you pasted above?
Does it still require my api_password at the end, or any other information?
Note: I’ve followed these instructions:
The RESTFul API is disabled by default, but is enabled by adding an ad_port directive to the AppDaemon
section of the configuration file. The API can run http or https if desired, separately from the dashboard.
Am I supposed to reference the port I specified somewhere? I’ve also tried subbing out ‘ad_port’ for ‘api_port’ following someone’s instructions.
EDIT: it seems that the Appdaemon API requires the api_key in the header if one is set up and Tasker requires root/a plugin to do that, so now I’m trying RUN SHELL:
And while I’m here, thanks for all your hard work @aimc and @SupahNoob. I’m new to HA and Python and your examples have really helped kickstart my understanding!
That’s a cool idea. I have Tasker app used before but couldn’t get my head around it. Could you share steps that you created in Tasker app to achieve this?
+ @sbmlat … so unfortunately, I don’t use either Tasker or AppDaemon anymore - longer story, for another time.
@poebae what do you get if you flash the %HTTPD variable in Tasker? This will help with debugging so we can tell if you’re getting an HTTP 200 or not. If you are, then something might be wrong in your AppDaemon app coding. If you are getting a 4xx error, then you are not authenticating correctly and should fix that first. Tasker can pass the data, but I do not remember exactly which field it should be passed in.
Let’s figure out the response code first, though! If need be, I’ll finally redownload Tasker to help.
What response data does %HTTPD / %locjson send back? I am looking to confirm that you are getting the proper response. Your code snippets all look fine to me.
Older versions of hass.io did not support the API - which version are you using of the AppDaemon plugin? And what version of AppDaemon is showing in the AppDaemon logfile?
After shelving this project for a while out of frustration, I revisited it today and finally figured it out. What I needed to fix:
Changing the api_port to 5050. It seems to be a hass.io limitation that only one open port is supported, as outlined here by @Mark_Boss. I don’t currently use the Dashboard anyway so I disabled it and hijacked port 5050.
Adding {} to the Data/File section of my Tasker task (or if using curl, -d ‘{}’
Switching /appdaemon/api for /api/appdaemon
So the final command that got it working was:
curl -i -X POST -H "Content-Type: application/json" http://myaddress:5050/api/appdaemon/endpointname?api_password=mypassword -d '{}'