1 //Create a class for thermostat device
3 import SmartThing.SmartThing
5 class Thermostat extends SmartThing {
6 // id, label, and display name of the device
10 // Maps from features to values
11 HashMap<String, String> deviceValuesMap = new HashMap<String, String>()
12 HashMap<String, Integer> deviceIntValuesMap = new HashMap<String, Integer>()
14 Thermostat(Closure sendEvent, String id, String label, String displayName, Integer currentTemperature, Integer currentCoolingSetpoint,
15 Integer currentHeatingSetpoint, Integer currentThermostatSetPoint, String currentThermostatOperatingState, String currentThermostatFanMode,
16 String currentThermostatMode, String currentClimateName) {
17 deviceValueSmartThing = deviceValuesMap
18 deviceIntValueSmartThing = deviceIntValuesMap
20 labelSmartThing = label
21 displayNameSmartThing = displayName
22 sendEventSmartThings = sendEvent
27 this.displayName = displayName
29 deviceValuesMap.put("temperature", currentTemperature)
30 deviceValuesMap.put("thermostatOperatingState", currentThermostatOperatingState)
31 deviceValuesMap.put("thermostatFanMode", currentThermostatFanMode)
32 deviceValuesMap.put("thermostatMode", currentThermostatMode)
33 deviceValuesMap.put("climateName", currentClimateName)
34 deviceIntValuesMap.put("coolingSetpoint", currentCoolingSetpoint)
35 deviceIntValuesMap.put("heatingSetpoint", currentHeatingSetpoint)
36 deviceIntValuesMap.put("thermostatSetpoint", currentThermostatSetPoint)
39 // Methods to set values
40 def setThermostatSetpoint(int newValue) {
41 action(newValue, "thermostatSetpoint")
44 def setCoolingSetpoint(int newValue) {
45 action(newValue, "coolingSetpoint")
48 def setCoolingSetpoint(String newValue) {
49 setCoolingSetpoint(newValue.toInteger())
52 def setHeatingSetpoint(int newValue) {
53 action(newValue, "heatingSetpoint")
56 def setHeatingSetpoint(String newValue) {
57 setHeatingSetpoint(newValue.toInteger())
60 def setThermostatFanMode(String newValue) {
61 action(newValue, "thermostatFanMode")
64 def setThermostatOperatingState(String newValue) {
65 action(newValue, "thermostatOperatingState")
68 def setThermostatMode(String newValue) {
69 action(newValue, "thermostatMode")
73 action("cool", "thermostatMode")
77 action("heat", "thermostatMode")
81 action("auto", "thermostatMode")
85 action("emergencyHeat", "thermostatMode")
89 action("off", "thermostatMode")
92 def setClimate(String info, String newValue) {
93 action(newValue, "climateName")
96 def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
97 setHeatingSetpoint(heatingSetpoint)
98 setCoolingSetpoint(coolingSetpoint)