Can I Have webCoRE direct Output to the Last Active Echo Speaks Alexa Device?

Thank you! :slight_smile:

Problem is that, when I go to build a piston, that global variable is not available for me to choose to do anything with it.

This is another part I’m stumped on.
How can I edit the text of the piston?

I know how to edit a piston, but when I go in there, there is no way of modifying the ‘text’ on my end.
The only option I have is to choose one of the other items in a list that is pre-populated.

For this start where you already have a With (an Echo) block
Then select the device in that block, it will open this:


With Devices: being the Echo in your with block

Then hit the dropdown at the far right and get this:


and start typing the name of your global var (all globals start with @)

Then Select your global and BOTH devices will now be listed:

Finally, hit the dropdown again, and this time start typing the name of the device you want to remove in the box:


Clear the device’s checkbox and then hit save.

2 Likes

One last thing - you will likely have to strongly type the global variable by editing the variable itself like this:

1 Like

Aha! There it is.
I had the global variable set as dynamic.
After changing it to device, it now shows up as a device to choose. :slight_smile:

Thank you!

Don’t be embarrassed
I have several threads devoted to my own questions. :stuck_out_tongue:

Here’s my piston that runs when I ask Alexa where everyone is (It throws a switch in Alexa/ST)

@ReceivedMsg is the final message, and @Pistontrigger activates my Speaking Piston

Now, there’s two things going on here. If I want the message to go to a particular piston, I set AlarmVolume=99 to that Echo. The piston looks for that value and sends the message there. If there’s no 99, then it sends it to the Alexa that received the command.

(Switch 3 is my ANNOUNCEMENTS switch. I can turn off all Announcements by telling Alexa to “Turn off warnings”.)

The trick is to throw in the getDeviceActivity somewhere as close as possible to the beginning of the piston to start the activity search. I have it in both pistons, just to be safe. It still takes 2-3 seconds, but is nowhere near the original 10+ seconds that it used to be, which was very impractical.

2 Likes

@nathancu
Now it appears as though my global variable is no longer being updated.
Does that mean that, I have to modify it to ‘device’ each time I want to add it to a piston, and then change it back to ‘dynamic’ when I’m done so that it goes back to being able to be set dynamically?

No - what does the piston that is updating it look like now?

Well, the frustrating thing is that, earlier, all I did was import @mebejedi 's piston, and change the devices so it was using mine, and it worked.

Now though, after tweaking, and stuff, for some reason, it’s not.

So, I went so far as to delete my previously created pistons that I was working with for this, and started fresh with a new copy of @mebejedi 's piston (it now being the only one), and it’s still not working.

I think there must be something kooky going on with my system.

So, I suspect I have something completely unrelated to troubleshoot. :confused:

Is this part working for you? I kinda worry about that, since there will always be a LastSpokenTo device
even if it was spoken to several hours/days ago.

Can you put up the changed piston? (And describe what it’s doing instead)

2 Likes

You are correct. Once it’s set, it stays. I was thinking about clearing it out on a timer. But considering it’s always running in the background and how much I use Alexa - it’s usually one of my 3 most popular devices. It was on a todo list to change, but I haven’t needed to.

Here is a green version.
I have to go right now, but will get back to this later tonight


How are you testing it? I did it by going to one Echo and asking the time, and then going to another Echo, asking the time,b and then immediately testing the piston.

Ya. I’m pretty much doing the same thing. I have three of them right next to me (1st Gen Echo, Echo Show 5, and my Windows 10 computer); each using a different ‘wake word’.

Goofy thing is that, whereas earlier, when I first tested it, it was working, and would shift the spoken text from the single webCoRE piston to whichever Alexa device I was asking the question to, later, it just got stuck on one of them. Also, it was no longer updating the global variable.

I haven’t tried since I got back to the office. I will check it now and report back here in this comment



Update:
OK, now it looks like it is back to updating the global variable, but I’m consistently seeing it get hung up


Piston waited at a semaphore for 9267ms


and the update to the global variable doesn’t happen until after that.


Also, I noticed just now when I re-imported another copy just to see what it looks like right away, even though it asked for and I gave it 5 devices, it only has three for
device Echos =

Does that matter at all?

At any rate, the one I’m actually using has just three actual devices, and that field only shows one of them.


Also, when I test now, when it does work, it only works on the two ‘native’ Alexa devices, and not Windows 10 unit.

Weird that it would work before, but not now. :confused:


Oh
to test, I just have a very simple piston in webCoRE that says
If THIS SWITCH turns on
Using @theGlobalVariable
Speak THIS


and as I test it just now, it’s stuck on sending the spoken msg to just one of the native Alexa devices, even though I tested with the other one.

Oh well. It was cool while it lasted. :expressionless:

Here are FULL logs from a single run of the piston


1/16/2020, 8:31:17 PM +394ms
+2ms ╔Received event [EchoShow].wasLastSpokenToDevice = false with a delay of 172ms
+9460ms ║RunTime Analysis CS > 31ms > PS > 9416ms > PE > 13ms > CE
+9461ms ║Piston waited at a semaphore for 9339ms
+9463ms ║Runtime (44763 bytes) successfully initialized in 9416ms (v0.3.110.20191009) (9461ms)
+9464ms ║╔Execution stage started
+9468ms ║║Cancelling statement #6’s schedules

+9653ms ║║Executed physical command [EchoGen1].getDeviceActivity() (178ms)
+9654ms ║║Executed [EchoGen1].getDeviceActivity (180ms)
+9806ms ║║Executed physical command [EchoShow].getDeviceActivity() (147ms)
+9807ms ║║Executed [EchoShow].getDeviceActivity (149ms)
+9941ms ║║Executed physical command [Win10].getDeviceActivity() (129ms)
+9942ms ║║Executed [Win10].getDeviceActivity (131ms)
+9957ms ║║Comparison (string) true is (boolean) true = true (1ms)
+9959ms ║║Comparison (string) false is (boolean) true = false (2ms)
+9961ms ║║Comparison (string) false is (boolean) true = false (1ms)
+9966ms ║║Condition #2 evaluated true (20ms)
+9967ms ║║Condition group #1 evaluated true (state did not change) (21ms)
+9969ms ║║Cancelling statement #3’s schedules

+9972ms ║║Executed virtual command setVariable (1ms)
+9977ms ║║Calculating (string) Last Echo spoken to was + (string) EchoGen1 >> (string) Last Echo spoken to was EchoGen1
+9980ms ║║Executed virtual command setState (0ms)
+9982ms ║╚Execution stage complete. (518ms)
+9983ms ╚Event processed successfully (9983ms)

Do you have a separate speaking piston? Can I see that as well?

Ya, but like I said, it’s extremely simple.
Here it is though


EchoSpeaksDirector-UrWlcm

I also have an Alexa Routine.
When it hears me say ‘Thank you’,
it turns on a particular simulated switch in SmartThings (Switch 47 here in this green screenshot).


Additional info:
I just remembered that when I initially started testing this thing, I had the piston actions to send the msg written right into the same piston as the one doing the work to update the global variable, and it may have been when I separated them that it stopped behaving nicely.

So, as another step in testing, I’m going to recombine, and see what happens


OK, with it all recombined (other related pistons completely disabled, AND I don’t even need the WAIT in there at all), it works, but only for the two native Alexa devices. When I engage the Windows 10 unit’s Alexa app in exactly the same way, the global variable never gets updated with the Windows 10 unit’s device name like it does with the two native ones.

So
perhaps the Alexa app for Windows 10 doesn’t even report wasLastSpokenToDevice, and maybe I only imagined that this piston worked with the Windows 10 unit during my initial round of testing?

I would add the getactivity command to the beginning of the speaking speaking piston as well. You should also have the “if wasLastSpokenToDevice=true, save devices to X” check right before the actual speaking.

2 Likes

Thanks.

Ya, I just recombined it all back into a single piston, and it works just fine (except for the Windows 10 Alexa endpoint).

In that case, I don’t even need to use the global variable.

Is there a simplified way of doing the speaking piston if I wanted to keep them separated, or would it basically be just about the same amount of code for each one (I’m not in a place I can actually look at it right now)?