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.
- Ask a question
- Wait 12-15 seconds
- If Yes, then do stuff
- 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?