Commit 3b9477cd by Alex Rhodes

Initial commit, open source code.

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/target/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Nest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.5
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>NestController</groupId>
<artifactId>Nest</artifactId>
<name>Nest for Echo </name>
<description>Control your Nest smart thermostat from your Amazon echo.</description>
<dependencies>
<!-- Nest Function and Echo Dependencies -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<!-- Amazon Provided, may not need all -->
<dependency>
<groupId>com.amazon.alexa</groupId>
<artifactId>alexa-skills-kit</artifactId>
<version>1.1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.0.6.v20130930</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.0.6.v20130930</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.directory.studio</groupId>
<artifactId>org.apache.commons.io</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.9.40</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<version>TFE-7_SNAPSHOT</version>
</project>
\ No newline at end of file
package com.alexscottrhodes.nest;
import com.amazon.speech.speechlet.SpeechletResponse;
import com.amazon.speech.ui.PlainTextOutputSpeech;
public class ErrorHandler {
public static SpeechletResponse failed(String message){
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(message);
return SpeechletResponse.newTellResponse(speech);
}
public static SpeechletResponse nestFailureResponse(String message){
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
message=message.toLowerCase();
if(message.contains("no write permission")){
message = "I'm sorry, I do not have permission to control that feature of your Nest.";
}
else if(message.contains("internal error")){
message = "I'm sorry, there was a problem with Nest's services. Please try again later.";
}
else if(message.contains("unauthorized")){
//Detailed response here
message = "I'm sorry, I do not have authorization to control that feature of your nest. Please make sure the Nest is present on your Nest account, and still activated through the Thermostat for Echo website.";
}
else if(message.contains("forbidden")){
//Detailed response here
message = "I'm sorry, I do not have authorization to control that feature of your nest. Please make sure the Nest is present on your Nest account, and still activated through the Thermostat for Echo website.";
}
else if(message.contains("service unavailable")){
message = "I'm sorry, there was a problem with Nest's services. Please try again later.";
}
else if(message.contains("internal error")){
message = "I'm sorry, there was a problem with Nest's services. Please try again later.";
}
else if(message.contains("blocked")){
message = "I'm sorry, Nest only allows me to control your Nest a limited number of times in a short period. Please try again later.";
}
else if(message.contains("not writeable")){
message = "I'm sorry, I can not contorl that feature of your Nest";
}
else if(message.contains("of wrong type")){
message = "I'm sorry, I could not understand the instruction you gave me.";
}
else if(message.contains("invalid thermostat id")){
message = "I'm sorry, I do not have authorization to control that feature of your nest. Please make sure the Nest is present on your Nest account, and still activated through the Thermostat for Echo website.";
}
else if(message.contains("is not a valid request")){
message = "I'm sorry, I could not understand the instruction you gave me.";
}
else if(message.contains("cannot set c and f temperatures simultaneously")){
message = "I'm sorry, I can not set both Celsius and Fahrenheit at the same time";
}
else if(message.contains("cannot set") && message.contains("while mode is")){
String mode = "x";
String temp = "x";
if(message.contains("target_temperature_high")){
temp = "a temperature range";
}
else if(message.contains("target_temperature_low")){
temp = "a temperature range";
}
else if(message.contains("target_temperature")){
temp = "an individual temperature";
}
if(message.contains("heat-cool")){
mode = "heat-cool";
}
else if(message.contains("heat")){
mode = "heat";
}
else if(message.contains("cool")){
mode = "cool";
}else if(message.contains("off")){
mode="off";
}
if(mode.equals("off")){
message = "I'm sorry, I can not set " + temp +" while your Nest is " + mode +". Please change modes first.";
}else{
message = "I'm sorry, I can not set " + temp +" while your Nest is in " + mode +" mode. Please specify either high or low temperature, or change modes.";
}
if(mode.equals("x") | temp.equals("x")){
message="I'm sorry, I couldn't set the temperature for you.";
}
}
else if(message.contains("cannot set") && message.contains("closer than")){
message = "I'm sorry, I can't set the temperature range that close together.";
}
else if(message.contains("low") && message.contains("value")){
message = "I'm sorry, I can not set the temperature that low";
}
else if(message.contains("high") && message.contains("value")){
message = "I'm sorry, I can not set the temperature that high";
}
else if(message.contains("low") && message.contains("lock")){
message = "I'm sorry, your nest has a locked temperature preventing me from setting the temperature that low.";
}
else if(message.contains("high") && message.contains("lock")){
message = "I'm sorry, your nest has a locked temperature preventing me from setting the temperature that high.";
}
else if(message.contains("larger than")){
message = "I'm sorry, I can't set the temperature that way, " + message;
}
else if(message.contains("energy-saving-events")){
message = "I'm sorry, I can't change the mode when your Nest is in an energy savings event";
}
else if(message.contains("thermostat lock is enabled")){
message = "I'm sorry, your thermostat is locked.";
}
else if(message.contains("cannot change hvac mode to")){
message = "I'm sorry, your Nest doesn't support that mode";
}
else if(message.contains("invalid hvac mode")){
message = "I'm sorry, your Nest doesn't support that mode";
}
else if(message.contains("while structure is away")){
message = "I'm sorry, your Nest is in Away mode";
}
else if(message.contains("invalid thermostat id")){
message = "I'm sorry, I can't reach the Nest you previously activated with your account. Please log in to www.ThermostatForEcho.com to manage your devices.";
}
else if(message.equals("not found")){
message = "I'm sorry, I can't reach the Nest you previously activated with your account. Please log in to www.ThermostatForEcho.com to manage your devices.";
}
else if(message.equals("no hvac fan")){
message = "I'm sorry, you do not have a fan that Nest can control.";
}
else if(message.equals("cannot activate fan during smoke")){
message = "I'm sorry, I can not activate your fan, your Nest is in a safety shutoff mode.";
}
else{
System.out.println(message);
message = "I'm sorry, I was unable to control your nest right now. Please try again later. If the problem persists, please email support@thermostatforecho.com";
}
speech.setText(message);
return SpeechletResponse.newTellResponse(speech);
}
}
package com.alexscottrhodes.nest;
import java.util.HashSet;
import java.util.Set;
import com.amazon.speech.speechlet.lambda.SpeechletRequestStreamHandler;
public final class NestRequestHandler extends SpeechletRequestStreamHandler {
private static final Set<String> supportedApplicationIds = new HashSet<String>();
static {
//Actual:
supportedApplicationIds.add("<Amazon application ID here>");
}
public NestRequestHandler() {
super(new NestSpeechlet(), supportedApplicationIds);
}
}
package com.alexscottrhodes.nest;
import com.alexscottrhodes.actions.NestFunctions;
import com.amazon.speech.slu.Intent;
import com.amazon.speech.speechlet.IntentRequest;
import com.amazon.speech.speechlet.LaunchRequest;
import com.amazon.speech.speechlet.Session;
import com.amazon.speech.speechlet.SessionEndedRequest;
import com.amazon.speech.speechlet.SessionStartedRequest;
import com.amazon.speech.speechlet.Speechlet;
import com.amazon.speech.speechlet.SpeechletException;
import com.amazon.speech.speechlet.SpeechletResponse;
import com.amazon.speech.speechlet.User;
import com.amazon.speech.ui.LinkAccountCard;
import com.amazon.speech.ui.PlainTextOutputSpeech;
import com.amazon.speech.ui.Reprompt;
import com.amazon.speech.ui.SimpleCard;
public class NestSpeechlet implements Speechlet{
//private static final Logger log = LoggerFactory.getLogger(EricaSpeechlet.class);
public void onSessionStarted(SessionStartedRequest request, Session session) throws SpeechletException {
//Initialization functions
}
public SpeechletResponse onLaunch(LaunchRequest request, Session session) throws SpeechletException {
//Initial greeting/launch
//log.info("onLaunch requestId={}, sessionId={}", request.getRequestId(), session.getSessionId());
return getGreetingResponse();
}
public SpeechletResponse onIntent(IntentRequest request, Session session) throws SpeechletException {
Intent intent = request.getIntent();
String intentName = (intent != null) ? intent.getName() : null;
if ("AMAZON.HelpIntent".equals(intentName)) {
return getHelpResponse();
}else if("AMAZON.CancelIntent".equals(intentName)){
return exitResponse();
}
else if("GreetingIntent".equals(intentName)){
return getGreetingResponse();
}else {
return NestFunctions.InitiateResponse(intent);
}
}
public void onSessionEnded(SessionEndedRequest request, Session session) throws SpeechletException {
//At the end of a session
}
//Core logic
//Initial greeting
private SpeechletResponse getGreetingResponse() {
String speechText = "Hello, I'm going to help Alexa control your Nest thermostat. How can I help you?";
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(speechText);
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
private SpeechletResponse exitResponse() {
String speechText = "Goodbye.";
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(speechText);
SpeechletResponse sr = new SpeechletResponse();
sr.setOutputSpeech(speech);
sr.setShouldEndSession(true);
return sr;
}
//Help response
private SpeechletResponse getHelpResponse() {
String speechText = "Thermostat can control your temperature and mode settings, or tell what your Nest is doing. You can say things like: set the temperature to seventy one degrees, switch to heating mode. How can I help you?";
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(speechText);
// Create reprompt
Reprompt reprompt = new Reprompt();
reprompt.setOutputSpeech(speech);
return SpeechletResponse.newAskResponse(speech, reprompt);
}
}
{
"intents": [
{
"intent": "NestTempQueryIntent",
"slots": [
{
"name": "THERMNAME",
"type": "LIST_OF_LOCATIONS"
}]
},
{
"intent": "NestAwayIntent",
"slots": [
{
"name": "THERMNAME",
"type": "LIST_OF_LOCATIONS"
},
{
"name":"AWAYSTATE",
"type":"LIST_OF_AWAY_STATES"
}
]
},
{
"intent": "NestIntent",
"slots": [
{
"name": "LOWTEMP",
"type": "AMAZON.NUMBER"
},
{
"name": "HIGHTEMP",
"type": "AMAZON.NUMBER"
},
{
"name": "RANGEEND",
"type": "LIST_OF_RANGE_ENDS"
},
{
"name":"THERMNAME",
"type":"LIST_OF_LOCATIONS"
}
]
},
{
"intent": "NestModeIntent",
"slots": [
{
"name":"MODE",
"type":"LIST_OF_MODE_TYPES"
},
{
"name":"THERMNAME",
"type":"LIST_OF_LOCATIONS"
}
]
},
{
"intent": "NestFanIntentOn",
"slots": [
{
"name": "THERMNAME",
"type": "LIST_OF_LOCATIONS"
}]
},
{
"intent": "NestFanIntentOff",
"slots": [
{
"name": "THERMNAME",
"type": "LIST_OF_LOCATIONS"
}]
},
{
"intent": "NestQuickIntentUp"
},
{
"intent": "NestQuickIntentDown"
},
{
"intent":"NestSingleIntent",
"slots": [
{
"name":"TEMPVAL",
"type": "AMAZON.NUMBER"
},
{
"name":"THERMNAME",
"type":"LIST_OF_LOCATIONS"
}
]
},
{
"intent":"NestSpecIntent",
"slots": [
{
"name":"DEGREES",
"type": "AMAZON.NUMBER"
},
{
"name":"DIRECTION",
"type":"LIST_OF_DIRECTIONS"
},
{
"name":"THERMNAME",
"type":"LIST_OF_LOCATIONS"
}
]
},
{
"intent":"NestQuickFilterIntent",
"slots": [
{
"name":"DIRECTION",
"type":"LIST_OF_DIRECTIONS"
},
{
"name":"THERMNAME",
"type":"LIST_OF_LOCATIONS"
}
]
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.CancelIntent"
},
{
"intent": "GreetingIntent"
}
]
}
home
here
back
arrived
going
away
gone
leaving
\ No newline at end of file
up
raise
increase
higher
heat
heat up
warmer
hotter
cooler
colder
down
lower
decrease
drop
cool
cool down
ac
air conditioning
\ No newline at end of file
living room
basement
dining room
entry way
hallway
kitchen
den
downstairs
family room
kids room
living room
office
upstairs
master bedroom
bedroom
\ No newline at end of file
heating
cooling
heat
cool
a.c.
heat-cool
heat cool
high-low
high low
range
off
\ No newline at end of file
low
lower
high
higher
bottom
top
upper
max
min
minimum
maximum
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment