So far, I am able to create automations that result in a particular bit of text being spoken aloud from a particular Alexa device using Echo Speaks in webCoRE. This is great!
Now, I want to see if there is a way of having the Alexa device that speaks the text be dynamic.
i.e. I want it to come out of the one that I was last speaking with (Whereas right now, itās just coming out of whichever one I specified in the webCoRE piston).
I think I may have even seen this concept discussed previously, but I forget where, and canāt find it at the moment.
Yes it can be done. I use a combination of two webcore pistons.
One piston triggers on waslastspokento=true for all of the devices I care about and stuffs the one that triggered the change into a global variable.
The second piston uses whatever device is in the global variable as the rltarget Alexa device.
Caveat: was last spoken to is only updated by Echo Speaks approximately every 60 seconds. So if you have just spoken to a specific device that was different than the previous last spoken to and youāre experiencing response to come back to that device you might get unexpected results.
Is there any way of manually, programmatically triggering Echo Speaks to reevaluate for waslastspokento? If so, I could add that command into the piston to have it happen before the command to say something.
So basically before you make your voice call, stuff all your echo devices in a device list variable then ādoā a āfor eachā device in devicelist: .getdeviceactivity()
I havenāt tried this because the 1 minute resolution is plenty good for what Iām doing.
I guess that seems like a bit too much for me to get into just to have Alexa say something in exactly the way Iām wanting. lol Iām also assuming it would probably take too long for the system to go through all that in order for it to have the response be timely enough to seem natural.
Eric you may be able to get away with not having the call to get device activity in that particular piston.
Reason, youāre triggering on one of the echos changing waslastspokento to true. So when that happens, webcore has already noted a change in the subscribed device and fired the trigger. So updating the activity is redundant.
Youāll want the call to update the activity BEORE you call any speech command that you want to place like this.
It would be more like thisā¦
Call to GetDeviceActivity (possibly in its own utility piston to refresh latest status and possibly trigger your last spoken to piston)
Call to Speech command (to lastspokento)
Other than that optimization, looks good. Hope it works for you
It works perfectly as is. I have a central speaking piston for all the others. They are activated first, and then the output is sent to that piston. The getactivity command gets the Echo information almost as quickly as a normal Alexa command.
[EDIT] Ok, I take that back. Itās 99% fast enough.
First, Iām assuming I have something messed up, or maybe just donāt understand, butā¦
I didnāt fully understand it at first, but I imported it to give it a try anyway.
I thought maybe this was going to be something that I would add to a piston to help with directing Echo Speaks traffic. However, as I sit here and test speaking commands to different Alexa devices, I see that this thing is updating the variable automatically shortly after my voice interactions.
I am seeing an error in the logs when it runs, but it still appears to be working.
That is very cool!!
Regardless of the rest of my questions, I will probably leave this thing in place.
Now, with the delay Iām seeing, this would not be a viable solution for the thing Iām looking for.
Is there any way to sort of build this into a piston to have this info available mid-stream in an automation?
Is that just simply a matter of me understanding whatās happening here, and plugging the appropriate parts into my piston?
ā¦and/or is that what @nathancu is talking about after your comment? lol
EDIT:
Oh waitā¦I see now that it is a local variable, and not global.
I guess that means I should be able to use it in a piston.
So, I will give it a try lol ā¦
I have the global variable set, but I canāt figure out how to use it.
I did all kins of searching, and read through all kinds of threads about global variables, but I just donāt see it anywhere, and it is not available when I go to build a piston to use it.
Soā¦ @mebejedi how do I actually use it? :embarrassed:
Hereās how I use mine:
This piston is a generic piston I use anytime Iām trying to do a speech announcement. It accepts a few arguments - sMessage being the message itself. The other arguments are a set of flags that determine how the announcement behaves, do I do the last Echo, a subset of echos or ALL of my echos. Iām also monitoring the status of a virtual switch to determine if the alert will happen at all. (Wife Acceptance Factor). Itās not at all finished but itās workable.
Notice Iām basically setting up a list of devices to target based on the flagsā¦ You could clean that all out if you want. The default no argument ānullā condition on bAnnounce and bOverride sends the announcement to the last spoken Echo device. This requires the Global Variable @LastSpokenTo to be not NULL
Now @LastSpokenTo is set within 60 seconds any time an Echo updates its .wasLastSpokenTo attribute to TRUE in this piston:
So whenever I call the speech piston it doesnāt have to ask - it just points and shoots. I did not find any good reason to update the device status - 60 seconds resolution is good enough for me.
This is an example of calling the Speech piston from another. I have a piston that evaluates whether my garage doors SHOULD be open and if not, alerts by message and voice. (Yes, I know I have some work to do in this one both for optimization and to handle multiple alerts at once, but it gets the job done.)
(BTW, I used to be a teacher so this is as good of a clue Iām going to point at - youāll do better if you figure out whatās happening in these pistons. This is homework. Youāre getting there - keep it up!)
OKā¦while I really freakin appreciate your input, and will, at some point, LOVE to take advantage of that kind of teaching format, unfortunately, as of right now, I am not able to dedicate the necessary brain power or time it appears necessary to consume and synthesize all of that.
Soā¦ are you saying that the simple way Iām looking for (which I normally use in other pistons to send notifications to Echo Speaks devices) simply canāt be done when the device I want to send it to is being represented by a global variable (even though, when it is being represented by a local variable, I can)?
No Iām saying what youāre looking for are those three lines.
42: I set the Value of a local variable devSpeakEchoDevices to the contents of the global variable @LastSpokenTo
52: Crap I should have said 50 - my error - need new glasses. This entire clause is WITH devSpeakEchoDevices (It could have just been @LastSpokenTo if weāre trying to simplify this)
we
56: DO Speak Text with the variable sMessage which contains my message
You already set @LastSpokenTo in the other piston, so with those together it should go.
Basically yes. OR you could just call it as the device itself. Instead of picking one of your echoes, pick that.
Now when picking a variable that stores a device, sometimes the UI wigs out and wonāt show you all the methods available. What I like to do is use an actual device and get it working the way I want, then go and edit the code to change the device to my variable.