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

Nice work, I wonder if instead of Lambda, can I use my SSL webserver?

1 Like

This is great. I’ve got it up and running.

I like that I can ask for a specific door status, or I can get all of my doors at once.

I have run into a roadblock…

I can’t figure out how to get alexa to tell me the setpoint and temperature on my thermostats?

anybody wanna give me a hand on this one?

1 Like

Big Jim…Colors…awesome! I like this, if you can program a little you are never limited by someone elses time or imagination. :slight_smile:

PRTG Server

https://www.paessler.com/prtg

Some of you use it to monitor equipment. It runs on a PC, and monitors anything that’s network connected, and already knows how to talk to thousands of devices. The company that makes it lets you watch up to 100 things free. 1 thing on 100 servers or 10 things on 10 servers makes no difference. They have an awesome API…here is an example of how I can monitor status: (but it tracks everything, not just up and down!)

alexa, ask home about the email server
– The SMTP server is Down. The IMAP server is Up. The POP3 server is Up.

Example:

   // Inputs  
    input "purl","string",title: "Enter the PRTG url",required:true, multiple:false
    input "puser","string", title: "Enter the PRTG user",required:true, multiple:false
    input "phash","string", title: "Enter the PRTG hash",required:true, multiple:false


   // case/switch
     case "email server"        : switch(op) {
                 case "status"     : checkEmailServer(2406,"SMTP",purl,puser,phash); //do all
                                     checkEmailServer(2403,"IMAP",purl,puser,phash);
                                     checkEmailServer(2405,"POP3",purl,puser,phash); break;
                 default           : defaultResponseUnkOp(noun,op)
     }
     break



// Contact the PRTG server routine

    def checkEmailServer(id,part,url,user,hash) {
        // id = device probe number from PRTG
        // part = your name for it
        // url = url of your PRTG server
        // user & hash = your PRTG authentication

        def updown = "unverified"

        //  http://www.something.com:8080/api/getsensordetails.json?id=xxx&username=xx&passhash=xxx
        //  you can send a clear password or passhash (available where you set your prtg password)
        
        def pollParams = [
           uri: url,
           path: "/api/getsensordetails.json",
           requestContentType: "application/json",
           query: [id: id, username: user, passhash: hash]   //tack on more url stuff after a ?
        ]
           
        httpGet(pollParams) { resp ->
                updown = resp.data.sensordata.statustext
                log.debug "ces: ${resp.data}";
        }

        state.talk2me = state.talk2me + "The ${part} server is ${updown}.  "
    }

This is the JSON you get back from the sensordetails for watching an (very troublesome) POP server with an API call…so you see, it keeps track of a lot of stuff. Different types of devices have different information. What’s even greater is you can get graphs and charts and other things too…not suitable for “audio” but could make a great addition to a device handler.

{
	"prtgversion": 		"16.2.23.3269",
	"sensordata": {
		"name":                 "POP3",
		"sensortype": 	        "pop3",
		"interval": 		"60",
		"probename":            "127.0.0.1",
		"parentgroupname":      "Network Infrastructure",
		"parentdevicename":     "Exchange/ADS: tele",
		"parentdeviceid":       "2062",
		"lastvalue":  	         "",
		"lastmessage":          "Connection timed out Socket Error # 10060 Connection timed out. (socket error # 10060)",
		"favorite":		"",
		"statustext":	        "Warning",
		"statusid":             "4",
		"lastup":	        "42495.5499422801 [7 m 56 s ago]",
		"lastdown":             "42495.5291784028 [37 m 50 s ago]",
		"lastcheck":            "42495.5535538657 [164 s ago]",
		"uptime":               "69.2346%",
		"uptimetime":	        "9 h 58 m",
		"downtime":             "30.7654%",
		"downtimetime":         "4 h 25 m",
		"updowntotal":          "14 h 24 m  [=74% coverage]",
                "updownsince":          "42494.7434262500 [19 h 29 m ago]",
                "info":                  ""
	}
}

You could also have it watch your internet routers Ethernet port, and ask alexa if your internet connection was overloaded…you know, like when your video streaming is breaking up and you want to know why! :wink:

1 Like
//inputs
input "brTemp","capability.temperatureMeasurement", title: "Select the Bedroom temp sensor", required: true, multiple: false
			input "dwnsTemp","capability.temperatureMeasurement",title: "Select the Downstairs temp sensor", required:true, multiple: false
			input "uptherm","capability.thermostat", title: "Select the Upstairs thermostat", required: true, multiple: false
			input "downtherm","capability.thermostat", title: "Select the Downstairs thermostat", required: true, multiple: false
		}

//central commnad case statement
case "thermostats" : 	switch (op) {			//tell me my temps and settings
									case "status"		: thermostatsNounResponse(brTemp,dwnsTemp,uptherm,downtherm); break 
									default				: defaultResponseUnkOp(noun,op)
									}
								break
//response
def thermostatsNounResponse(theBrTemp,theDwnsTemp,theUpTherm,theDownTherm)
{
	def upTemp = theBrTemp.currentValue("temperature")  as Integer
	def downTemp = theDwnsTemp.currentValue("temperature")  as Integer
	def upMode = theUpTherm.currentValue("thermostatMode")
	def downMode = theDownTherm.currentValue("thermostatMode")
	def upHSet = theUpTherm.currentValue("heatingSetpoint")  as Integer
	def downHSet = theDownTherm.currentValue("heatingSetpoint")  as Integer
	def upCSet = theUpTherm.currentValue("coolingSetpoint")  as Integer
	def downCSet = theDownTherm.currentValue("coolingSetpoint")  as Integer
	if (upMode == "heat") {state.talk2me = state.talk2me + "SmartThings reports the Upstairs thermostat is ${upMode}ing to ${upHSet}, current temperature is ${upTemp} degrees.  "} 
		else if (upMode == "cool") {state.talk2me = state.talk2me + "SmartThings reports the  Upstairs thermostat is ${upMode}ing to ${upCSet}, current temperature is ${upTemp} degrees.  "}
		else {state.talk2me = state.talk2me + "SmartThings reports the  Upstairs thermostat is off, current temperature is ${upTemp} degrees.  "}  
	if (downMode == "heat") {state.talk2me = state.talk2me + "The Downstairs thermostat is ${downMode}ing to ${downHSet}, current temperature is ${downTemp} degrees.  "} 
		else if (downMode == "cool") {state.talk2me = state.talk2me + "The Downstairs thermostat is ${downMode}ing to ${downCSet}, current temperature is ${downTemp} degrees.  "}
		else {state.talk2me = state.talk2me + "The Downstairs thermostat is off, Downstairs temperature is ${downTemp} degrees.  "}      
}
5 Likes

Very nice scottinpollock!

1 Like

Anyone came up with a way to iterate through all the lights and report back the one that is on yet? Right now, I have her reporting every single light status which can be long. Would be nice if she can only report back the ones that are ON or OFF.

Take a look at the section for the batteries where it is setting the cut off limits for low. I don’t have it in front of me but I’m betting that can be configured fit other devices as well.

Ok, so Alexa respond really well to, ask home for the status of… , or, ask home if the blank is on/off.

I have my doors groped grouped together add external doors. When I all for a status of external doors she tells me the status of them all.

I want to say, ask home, are there any doors open?

Ideas?

(c; Follow your own advice above… input all of your door sensors, loop through them all using ‘handle.each’, checking the currentValue, and if open, adding it to the response.

1 Like

I thought about that after I posted it! Lol

1 Like

Here is what I used for lights…not all scenarios are accounted for but it lists devices on and if all are off: You may want to add dimmer info?

sample utterances
Command what {Noun} are {Operator}

LIST)OF_NOUNS
Lights

//inputs
input “alllt”,“capability.switch”,title: “Select ALL lights”, required: true, multiple: true

//switch noun
case “lights” : switch(op) { // check the status of all lights
case “off” :
case “on” : lightResponseOn(alllt,noun,op); break
default : defaultResponseUnkOp(noun,op)
}
break

//capability.switch report on
def lightResponseOn(handle, noun, op)
{
if (handle.currentValue(“switch”).contains(“on”))
handle.each {
def arg = it.currentValue(“switch”)
if (arg) {
if (arg == “on”) {
state.talk2me = state.talk2me + "${it} is ${arg}. "
}
}
}
else state.talk2me = state.talk2me + "All lights are currently off. "
}

2 Likes

I used the exact same code for Windows and Doors. Just change to capability.contactSensor and open, closed.

Has anyone addressed the case sensitivity yet? code for making everything lower case so there is no issue with Nouns not found due that case? I have added a couple with both cases to get around it but there has to be an easier way to process with lowercase()

1 Like

Has Alexa/Lambda sent anything to you with uppercase in it? The only thing it sent to me with an uppercase letter was my name “Keith”.

I was having some issue with Case sensitivity so I did toUpperCase() in the switch statement for everything. No more issue. :slight_smile:

1 Like

Since Alexa mostly sends lowercase, when Michael was having problems with matching ST device names where people might capitalize the first letter of some words, I suggested he just convert anything he reads out of smartthings to lower case, I guess that’s working for him. Upper or lower doesn’t matter if you make everything the same :wink:

It has, some of the Nouns come through upper and some lower. I haven’t found a reason or method for why. So some items that come through with caps I have to account for that in the case. “Me” and “me”. I have never had the issue for anything except the Noun. I input the text in alexa skill test I can replicate it but I done know how she will translate the txt to speech until I see it fail and look at the card.

1 Like

Thanks @cuboy29, that worked. I changed the def params to include .toLowerCase() and if fixed it for all of them.

1 Like

Thanks for sharing. Do you have any issue with the attribute multiple: true? Last time I used in in this smartapp, I lost the done button and the smartapp crashed and disappeared on its own.

I haven’t had any issues with the smartapp on Android using the attribute multiple: true?. I have six device groups that use it with no issues.

2 Likes