I have a question about this. I set it up, and it’s pretty cool. It takes a little bit to update. One of the things I’m hoping to be able to do is to run an alexa routine, that triggers an automation. For example at the moment I have an input boolean that turns on as part of an alexa routine, The input Boolean is a trigger for an automation that kicks off a TTS back to the Echos. Currently I have it do TTS to a specific Echo, but would love for it to run on the lastalexa instead. But as it stands now, its a bit too slow to update.
Anyway, what is the best way to that? Any tips, recommendations, scripts, sensors to share?
You can change the default 60 seconds scan interval
I have been using a dummy bulb rather than an input Boolean in the Alexa Apps as this give me 99 triggers rather than 1. Got fed up of lots of input booleans switches in the alexa app.
I did see the dummy bulb post the other day. Genius, and I plan on converting over to that. So simple and clean. I thought about scanning every 60 seconds, but even that is not quick enough. Is there a way in the automation, to get -lastalexa immediately?
I think if it like this.
“Alexa, give me the surf report” (Alexa Routine, ran in kitchen)
up to 60 seconds later
“The water temp is X, the UV level is X, High tide, is X”
Is a little too long.
Right now I get the response back right away, but… only on a designated echo (which is fine 90% if the time). I only have a few of these “reports or queries”, but would like to add a few more as I get more involved.
I have not. So, I guess my question is more of - is there a way to run the " alexa_remote_control.sh -lastalexa" command on demand in an automation, and use the results in your automation. Rather than the sensor. I agree that for many types of automations, one a minute would be just fine. I also have a few automations already running that send me alerts or notifications on multiple alexas, so it could be “wrong” sometimes, or not what I expected. But if I ask a question, I know that the last alexa is the one I’d want to get a response on right away
The simplest way of getting results from external scripts is using Command line sensors. try dropping the scan rate. I put a response in the Alexa app saying something like “please wait while I check” this gives you another 10 seconds leeway
@ReneTode may have some clever options in Appdeamon, but I’m not aware of any other way of getting the info back to HA short of using the HA API and curl
My only concerns about running the script every 10 seconds would be the overhead on the echos? I guess it’s really just polling alexa.amazon.com, but do you think there is any sort of internal network traffic related to the echos?
i wouldnt run the script every 10 secs. i think that would cause more trouble then it gives back.
what i do:
i got a custom skill from alexa. that can be in HA, but i got it connected to appdaemon)
if that gets triggered a piece of appdaemon is triggered so then i change the sensor.last_alexa.
i also scan every minute.
i also have emulated hue, that triggers some input_booleans. and the change from the input_boolean triggers an (appdaemon) automation. in that automation i also scan for the last_alexa.
so that way i can let alexa speak something when i use emulated hue.
its probably also possible to create a custom component from emulated hue and let the scan take place when theat component is triggered.
and i dont know if emulated hue gives some kind of event, because then that also could be used to trigger the scan.
I am using HA cloud. I’ve managed to not have to use emulated hue or appdaemon yet. I do have several input booleans, that I use with Alexa to kick off automations, I guess my question is how to you force the sensor to update?
Hmm, now that I’m typing do you maybe link your sensor to a different entity ID (like an input boolean in my case), and use that to cause it to update?
with emulated hue (probably also possible with cloud)
speak to alexa
input_boolean.A gets triggered
an automation gets started by the change from input_boolean.A
that automation can do everything you want.
switch lights
change heating
scan for last_alexa
send tts to last alexa
etc.
i use AD, but it can be done with all kind of things.
appdaemon app
and because everything i got is in appdaemon, i can scan at any given point.
the only thing that throws things out of order is when i ask AD for music, the weather or a routine.
the last one i do rarely, but i could always include a input_boolean inside every routine
the fact that music is started i can see in the media players (so they change state, so that can also be a trigger for the scan)
import appdaemon.plugins.hass.hassapi as hass
import datetime
import tempfile
import subprocess
class last_alexa_sensor(hass.Hass):
def initialize(self):
runtime = datetime.datetime.now() + datetime.timedelta(seconds=5)
self.run_every(self.check_last_alexa,runtime,60)
def check_last_alexa(self,kwargs):
cmd = ["/home/renetode/alexamedia.shl","-lastalexa"]
try:
with tempfile.TemporaryFile() as f:
self.subprocessresult = subprocess.Popen(cmd, stdin=None, stdout=subprocess.PIPE, stderr=f)
out,err = self.subprocessresult.communicate()
if out != None:
state = out.decode("utf-8").strip()
self.set_state("sensor.last_alexa", state = state)
#self.log("last alexa: "+ state)
else:
self.set_state("sensor.last_alexa", state = "cookie problem")
#self.log("last alexa: subprocess did return None")
except:
self.log("last alexa couldnt be updated")
that scans for last alexa every minute.
the function check_last_alexa i can call everywhere inside appdaemon by using the get_app function from appdaemon.