AskHome - Alexa/SmartThings programmers kit. Alexa can do anything

//inputs
preferences {
	page(name: "configure")
}
def configure() {
	dynamicPage(name: "configure", title: "Choose Devices and Routine", install: true, uninstall: true) {
		section("Select your devices") {
			blah
			blah
			blah
		}
		section(title: "App ID") {
			paragraph "Application ID:\n${app.id}"
		}
		def actions = location.helloHome?.getPhrases()*.label
		if (actions) {
			actions.sort()
			section("Routines") {
				input "GMaction", "enum", title: "Routine to execute on Good Morning", options: actions, required: true
				input "GNaction", "enum", title: "Routine to execute on Good Night", options: actions, required: true
			}
		}
	}	
}

//case
		case "good morning" : 	switch (op) {			//Good Morning! Routine
									case "status"		: goodMorningNounResponse(); break 
									default				: defaultResponseUnkOp(noun,op)
								}
								break

//response
def goodMorningNounResponse() {
	location.helloHome?.execute(settings.GMaction)
	def theRoutine = settings.GMaction
	def otemp = outTemp.currentValue("temperature")
	def mtemp = medTemp.currentValue("temperature")
	def btemp = brTemp.currentValue("temperature")  as Integer
	def outHU = outdoorHu.currentValue("humidity")
	state.talk2me = state.talk2me + "Good Morning Scott, SmartThings has executed your morning routine.  "
	state.talk2me = state.talk2me + "Outside, it is ${otemp} degrees with a relative humidity of ${outHU} percent.  "
	state.talk2me = state.talk2me + "It is ${btemp} upstairs, and ${mtemp} downstairs.  "
	state.talk2me = state.talk2me + "I hope you have a great day.  "
}
4 Likes

Hey it’s only been a few weeks since your last system gutting, was wondering why it took you so long this time loool… I am right behind you bro. Wrapping up the 29 days of my bare minimum performance tracking and then, LET THE FUN BEGIN!!! Load up time. Cannot wait…Or as @bridaus would say, let the recipe for disaster begin…muahhhh

2 Likes

BTW, if you’re like me and would like to change up the prompts that the lambda function uses, here is a quick and dirty randomizer…

Define arrays for the various responses…
var STprompt = ['How can I help?', 'Smart things here.', 'Smart things is listening.']

call this instead of static text to randomly pick one…
var speech = STprompt[Math.floor(Math.random() * STprompt.length)];

Later this week I think it will be time to change the invocation name to ‘computer’, and dig up some old Majel Barret computer voice clips to use instead of text to speech. Anyone have these sounds already?

4 Likes

Much more elegance than my hard coding hack of routine and modes :slight_smile:

1 Like

How is this being used anyway… I am not sure what the LaunchRequest is for.

You can just say tell, ask, open, run, or launch SmartThings, without any other words, and it will prompt you for a command.

Push a button, activate something smart.

If you were lucky enough to snag one of those IoT buttons from amazon, and you got the demo working that sends an email to you…

You can add some of your AskHome lambda code to the exports.handler() of the Button’s lambda code and activate any of your nouns. Of course Alexa is not going to talk back to you, but any actions will be taken by the AskHome and what Alexa would have said is emailed to you.

Once this is configured, you can always use the button setup to change the wifi to another location. Basically this gives you a remote button to activate something on smartthings without having a smartthings hub on-site.

1 Like

Has anyone done a TTS with this?

I’m thinking I want to have a text field that I input what I want, I choose the speaker device, and I tell alexa to play it. and it plays on the speaker I chose.

2 Likes

Great idea, like ‘Dinner is ready’. It would be the only non wall mounted switch that my wife will ever use. TTS to speakers followed by SMS to all phones.

2 Likes
// Inputs for a music player and device, and what to say
input "vlctalk","capability.musicPlayer",title: "Select VLC",required:true, multiple:false
input "vlcwhat","string",title:"Say What?",required:true, multiple:false
----------------------------------

// call this from your case/switch statements
sayIT(vlctalk,vlcwhat);

//  ----------------------------------
//  TTS and Play on sound device
//
def sayIT(vlc,what)
{
     state.sound = textToSpeech(what)
     vlc.playTrackAndResume(state.sound.uri, state.sound.duration)
     // if you want it to come back out of Alexa too
     //   state.talk2me = state.talk2me + what
}
1 Like

I’ve added Amazon’s new Flash Briefing ability to my Ask Home running at my home. :wink:
So now when I ask Alexa for my Flash Briefing, she’ll also give me a home status too.

I created a CASE statement entry that calls a subroutine to generate the briefing text:

            case "briefing"               :  sendBriefing(); 
                                                   break

Adjusted the JSON that gets normally returned to Lambda…Flash Briefing wants different things than Alexa/Lambda

  def whatsnow = new Date().format("yyyy-MM-dd'T'HH:mm:ss'.0Z'")
  
  if (noun == "briefing"  && op == "flash") {
       return ["uid": "1",
               "updateDate": whatsnow,
                "titleText": "Smart Things Home Briefing",
                "mainText": state.talk2me,
                "redirectionUrl": "https://graph.api.smartthings.com/",
                "description": "What's happening at home"
               ]
       
  } else {  
     return ["talk2me" : state.talk2me] 
  }

And load up this subroutine with any calls or strings you want as part of this briefing.

def sendBriefing()
{
     state.talk2me = state.talk2me + "Hey, this is your Smart Things news.  "
     // poolStatus()  //calls that add text to state.talk2me
     //  doorStatus()
     // etc...
}

In the Alexa Developer, you create a new skill. There’s a new option for Flash Briefing. It’s very much like when you create the Skill for AskHome or Ask Alexa. Except far simpler. None of those lists or utterances or anything. You will want to use the content type of “text”, and the URL will be the tricky part. You use the same App ID and Token you used in Lambda. In this case, the op is sent as “flash” so the Ask Home SmartApp returns the JSON for the Flash Briefing instead of for Alexa/Lambda. That also lets you say “Alexa, Ask Home for a briefing” and have it work too. With AskHome it will look something like this:

https://graph.api.smartthings.com/api/smartapps/installations/{substitute-app-id}/briefing/flash/none/none?access_token={substitute-token}

(This string would be different for MichaelS’s Ask Alexa, and of course he’d have to adjust the code and JSON to respond to a briefing if he decides to add this feature.)

You will have to go into the Alexa App on your phone/tablet and pick Skills, then “Your Skills” and choose this new skill and enable it. You can double check that it’s turned on in your flash briefing under Settings/Flash Briefing

1 Like

I’ve gone line by line installing the original code (not this newest code) and run into a problem with adding custom slot types. I can pull my live logs, but “Ask Alexa” never shows for me to get the URL for the device list. Did I install something wrong in a step before or looking in the wrong area?
thanks

Just getting started with SmartThings and looking forward to trying this out. Thanks for the Sparty love!

1 Like

Hey Keith, I wanted to say a BIG, BIG thank you for putting this together. Without it, the apps like Ask Alexa and Echosistant would not have been possible. You really meant it when you said Alexa can do anything you want. After working on Echosistant, I cannot agree more! Thank you, thank you, thank you. You made Alexa 1000 times smarter and more reliable in my home!!!

3 Likes

I couldn’t agree more!

3 Likes

Hi Keith,
Thank you very much for not only doing what we all thought Samsung and Amazon should be doing but for also sharing your work with us!

I have followed your guides and I think I am getting close to making my version work. One thing which is definitely confusing me is authentication as your guide says that setting it up in Amazon is not recommended but I don’t quite see the alternative. Is there any chance I could get some help? I would be very willing to pay for it.

Regards,
Jon
(UK)

Hi Joh!

The reason I didn’t use that authentication system is that Smart Things
will return ALL allowed lights, sensors, etc in a structure, even when you
ask for just one light in the programming. And the program I wrote is
based on individually registering each and assigning it to a variable name
as a mnemonic.

There’s another program called Ask Alexa that was based on mine, his
instructions are far better than mine, if you’re having trouble with
initial configuration, you might want to look through those for any
sticking points. I’m away fly-fishing (for my first time) this weekend, so
my responses might be a bit slow if you have follow up questions.

-Keith

1 Like

Thanks for the shout out! Here are those directions: http://thingsthataresmart.wiki/index.php?title=Ask_Alexa

Thanks for the advice and thanks, Michael, for Ask Alexa. Its awesome. Do you have a donations page?

Jon

Yes…while not required by any means folks have sent Amazon Gift Cards or simply doing the PayPal thing here: https://paypal.me/mstruck. I have even had people send me fractions of bitcoins (at the time it seemed worthless…but at almost $3000 per coin it adds up!).

I really appreciate the kind words!