WebCoRE asks a question, my voice response determines the action

text-to-speech
answer
query
voice
alexa

#49

I split them up into two mini pistons for a few reasons:

(1) If I combined these 2 pistons into one, it would add two new triggers and waits to pre-existing pistons. This has the potential to cause logic flow issues. (in other words, pistons currently working could potentially break)But… by keeping “My Answer” separate as a “reset” piston, it should work with all types of pistons. (both old and new)

(2) The code in “My Answer” is used once. And only once. No matter how many questions you add at a later time. You just need the one piston. Think of it as the “clean-up” piston.

(3) The code in “My Question” piston can be inserted inside any piston, whenever you want a question prompt. It can use a current trigger, and then just continue with the couple lines of my code right after.


These are adjustable… in both pistons. Just keep in mind, the wait in “My Answer” must always be longer than the wait in “My Question”. During testing and real life use, my best results was when:

  • My Answer was 20-30 seconds (but no harm if you extend it to 60)
  • My Question was 12-15 seconds (I would not go below 10 in normal uses)

Personally, for rock solid reliability, I would keep “My Answer” to a 30 second reset. You can push it to 20, but why? This design is not set for a rapid fire list of questions, one after another.

2 questions per minute is the current limit, but you may be able to squeeze in 3 per minute if you lower the delay to 20 seconds. Just keep in mind if you choose that route, you will not be able to ask long questions without the switches resetting themselves.

As far as the timers in “My Question”… that can actually be adjusted on a per piston basis. So, for example, if you are asking a real short question (IE: Are you cold?), you could likely drop that 15 second timer all the way to 10 seconds.

This was the reason I found 12-15 seconds the most reliable in the most circumstances:

  • 1 sec for the speaker to begin
  • 6 sec for the question to be asked (although your question may be shorter)
  • 4 sec for our reply (Alexa Yes, or Alexa No)
  • 1 sec for the change to be recognized by SmartThings
  • 3 seconds for good measure.

Obviously, everyone’s environment is different, with different needs, and our speakers are likely not responding at the same rate, so feel free to tweak away! I made this public so you could all benefit from it, and incorporate it into your house. Make it personalized.

Just to make one thing clear:
If you drop the timers too low, you may have to scramble quickly to get a reply back into Alexa before it resets itself.


Some specifics:
I didn’t use globals in this, because pistons often do not see a change in globals until the piston completes, and then starts again.

I did not want to pass the data into another piston, because that would mean three pistons, and also the extra coding to send the command back. (My Question to Relay… Relay to My Question… My Answer to clean up)

The method I chose is streamlined… basically adding 4 lines of code to any piston.

  1. Ask a question
  2. Wait 12-15 seconds
  3. If Yes, then do stuff
  4. If No, then do stuff (or not)

Actually, I am leaving out the 4th line in many of my pistons. I can say “yes” if I want action, and ignore the question if I don’t. So yea, literally 3 lines of code per piston.

What more can you ask for?


#50

:+1:

Me too…


#51

If I follow this right you are saying you can have a virtual device trigger the question piston but would you need a separate virtual device and question piston for each type of question you set up?

Is there a way to have a global piston that just has Alexa wait for yes or no?

Ex. If motion just detected in Den ask questions #1.
If motion is detected in LR ask questions 2…


#52

You can have any normal trigger. Time of day, Garage door opens, Motion sensor changes to active, SimSwitch flips on/off etc. You just add this to the piston you want to ask a question:

IF something happens       <-- Trigger already existing in your piston
Then ask a question
Wait 15 seconds
    IF "Answer Yes" is on  <-- Condition, NOT a trigger
    Then do cool stuff
    END IF
    IF "Answer No" is on   <-- Condition, NOT a trigger
    Then do other stuff (or nothing)
    END IF
END IF

If you follow my method, all you need is two Simulated Switches, 1 copy of “My Answer” piston, and three lines of code added to any piston where you want to ask a question. This included hundreds of questions in hundreds of pistons. It is still the same requirements. 2 SimSwitches in total, 1 piston in total, and 3 lines of code per question.


Global variables will not work reliably with this.


This could definitely work. Just add a different question to the two pistons. (and don’t forget the 30 second cool down between questions)


#53

Did anyone ever figure out a way to determine which echo will ask the question depending on which one you’re talking to?


#54

My method on this page uses webCoRE to ask the question BEFORE you say a word to Alexa.
(So how would webCoRE know which speaker to use?)

Alternatively, there are many interesting options out there for Text-to-Speech (TTS). I am sure you can code some sort of logic to “guess” which room to play to… It sounds like it’d be worth digging thru some previous posts, or creating a new topic. I am sure you would get hundreds of views and opinions!

Personally, I use this method to speak outloud. I give up the ability of having it spoken on a particular device, but I gain the freedom of having absolutely NO restrictions when sending commands to my Echo. (any Alexa Skill or command that you can use your voice to activate, will work 100% with that method)

To be honest, if I had to choose, I definitely prefer having this freedom over restricting the voice to a specific device. I am using webCoRE to make Alexa do things that no third party app can do…

Sorry I cannot be of more help on that topic. I am very pleased with my text to speech, and think it will be quite some time before another method impresses me enough to switch over.


#55

From author of Ask Alexa…“There is a serial number that is identified by my lambda (and then passed to the app) to determine what speakers are being spoken to. So I have mine set up to say “turn on the lights in here” and it knows ‘in here’ as a cross reference to a room that is associated with the device. However, this is NOT passed to SmartThings in any way.”


#56

Well, to be honest, I was curious to see if there was a method of determining which echo was bring talked just for future reference. I also thought it would be nice if, having given a command to an echo that might require a later question/answer, it would be possible to send the question to the echo where the original command was sent. It wasn’t a big deal… Just wondering.


#57

It is likely possible with an alternative TTS in place…

Just keep in mind the method you are describing is:
Alexa > ST > webCoRE > 3rd Party App > Spoken Question > Alexa > ST > webCoRE

The method I am describing here is:
webCoRE > Spoken Question > Alexa > ST > webCoRE

(notice the last steps are the same)

My advice would be to get the core functionality up and running first, and then have fun with it.

I intentionally designed it simple so that things could be added to it later.


#58

I ran into one issue. I have this running a AnswerYes in my Den if motion is detected in my Den ask If I want to watch TV and is Yes it will run a harmony routine. The issue is each time i am close to the motion it asks.

I am trying to think of a elegant way to present the question from being asked over and over if people walk in while I am already ion that room.


#59

Maybe something like this?

IF Motion changes to active       <-- Trigger
Then 
    IF askedRecently is not true  <-- Condition (boolean variable)
    Then 
        Ask question
        Wait 15 seconds
        IF Answer Yes is on       <-- Condition
        Then
            Do Harmony stuff
            Set variable askedRecently to true
        END IF
        IF Answer No is on        <-- Condition
        Then
            Set variable askedRecently to true
        END IF
    END IF
END IF

IF Motion stays inactive for 15 minutes
Then
    Set variable askedRecently to false
END IF

I had to account for Answer No as well so she won’t keep bugging you if you are just reading the paper etc.

As long as you answer either Yes or No to her first question, she will not ask again until the room has been empty for awhile.


#60

would AskedRecently be a global or local boolean?


#61

Has to be local to be reliable in this case


#62

What I wish to do: when Schlage lock is opened from the inside (not with a presence sensor, not with a code), have Alexa report the state of the garage and if closed, ask if you would like it opened… and do so or not based on the reply (or lack of reply).

Then again, looking at the android control tablet right by that lock and tapping it to open or close the garage as desired is easy enough. Lol


#63

I agree Glen. If your control tablet is near the Schlage lock, you will get a quicker response by just tapping an icon on the Android. (since the methods on this page has a built-in 15 second delay)


#64

Did anyone make it work with Google Home? I’m not sure, where to start…


#65

The concept should be similar. Just make sure that Google Home is able to control the two SimSwitches. (Answer Yes and Answer No)


#66

Okay, having an issue.

I’m trying to create a piston that will query me every half-hour after midnight to see if I’ve fallen asleep with the TV on. I’m testing it with my desk lamp for now.

For one thing, I’d love to figure out a way to have it check on me every half-hour after midnight (until, say, 2:00).

The other thing I’m having an issue with is setting it to ask me only when the TV (or, in this case, light) is on. I was hoping that putting the If ComputerLight=On restriction would work if I put it at the beginning of the piston, but instead, I’ve had to put it in every instance when AR speaks. What am I doing wrong here?


#67

I have not tested this inside a 30 minute timer, but I believe this would work. (using 75% less code)
It runs every 30 minutes between 12AM and 1:59AM.

One caveat: depending on what time the piston was last saved,
the first alert will happen between 12AM and 12:29AM.


Edit March 2020:

ATTN Everyone… Please do not use this piston. I made the mistake of starting with code that was not 100% examined, so a lot of things slipped past my radar. There are two or three things that would need to change to make the above piston work properly.

To preserve the flow of conversation, I am only editing / removing the import code.


#68

I’ll give it a shot!

[EDIT] Shouldn’t that be INSIDE OF RANGE?

[EDIT] It works! Seems kind of a waste of processing to have it counting every 30 minutes all day long (but only running the piston between 12 and 2), but I’ll take what I can get!