Created
July 1, 2013 19:06
-
-
Save Dianoga/5903614 to your computer and use it in GitHub Desktop.
Nest Device Type for SmartThings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Nest | |
* | |
* Author: dianoga7@3dgo.net | |
* Date: 2013-06-24 | |
*/ | |
// for the UI | |
metadata { | |
simulator { | |
} | |
tiles { | |
valueTile("temperature", "device.temperature", width: 2, height: 2) { | |
state("temperature", label:'${currentValue}°', unit:"F", | |
backgroundColors:[ | |
[value: 31, color: "#153591"], | |
[value: 44, color: "#1e9cbb"], | |
[value: 59, color: "#90d2a7"], | |
[value: 74, color: "#44b621"], | |
[value: 84, color: "#f1d801"], | |
[value: 95, color: "#d04e00"], | |
[value: 96, color: "#bc2323"] | |
] | |
) | |
} | |
standardTile("thermostatMode", "device.thermostatMode", inactiveLabel: false, decoration: "flat") { | |
state "off", label:'${name}', action:"thermostat.heat" | |
state "heat", label:'${name}', action:"thermostat.emergencyHeat" | |
state "emergencyHeat", label:'${name}', action:"thermostat.cool" | |
state "cool", label:'${name}', action:"thermostat.auto" | |
state "auto", label:'${name}', action:"thermostat.off" | |
} | |
standardTile("thermostatFanMode", "device.thermostatFanMode", inactiveLabel: false, decoration: "flat") { | |
state "auto", label:'${name}', action:"thermostat.fanOn" | |
state "on", label:'${name}', action:"thermostat.fanCirculate" | |
state "circulate", label:'${name}', action:"thermostat.fanAuto" | |
} | |
controlTile("heatSliderControl", "device.heatingSetpoint", "slider", height: 1, width: 2, inactiveLabel: false) { | |
state "setHeatingSetpoint", action:"thermostat.setHeatingSetpoint", backgroundColor:"#d04e00" | |
} | |
valueTile("heatingSetpoint", "device.heatingSetpoint", inactiveLabel: false, decoration: "flat") { | |
state "heat", label:'${currentValue}° heat', unit:"F", backgroundColor:"#ffffff" | |
} | |
controlTile("coolSliderControl", "device.coolingSetpoint", "slider", height: 1, width: 2, inactiveLabel: false) { | |
state "setCoolingSetpoint", action:"thermostat.setCoolingSetpoint", backgroundColor: "#1e9cbb" | |
} | |
valueTile("coolingSetpoint", "device.coolingSetpoint", inactiveLabel: false, decoration: "flat") { | |
state "cool", label:'${currentValue}° cool', unit:"F", backgroundColor:"#ffffff" | |
} | |
standardTile("refresh", "device.thermostatMode", inactiveLabel: false, decoration: "flat") { | |
state "default", action:"polling.poll", icon:"st.secondary.refresh" | |
} | |
main "temperature" | |
details(["temperature", "thermostatMode", "thermostatFanMode", "heatSliderControl", "heatingSetpoint", "coolSliderControl", "coolingSetpoint", "refresh"]) | |
} | |
} | |
// parse events into attributes | |
def parse(String description) { | |
} | |
// handle commands | |
def setHeatingSetpoint(temp) { | |
setThermostatMode('heat', temp) | |
} | |
def setCoolingSetpoint(temp) { | |
setThermostatMode('cool', temp) | |
} | |
def off() { | |
setThermostatMode('off'); | |
} | |
def heat() { | |
setThermostatMode('heat'); | |
} | |
def emergencyHeat() { | |
setThermostatMode('emergency heat'); | |
} | |
def cool() { | |
setThermostatMode('cool'); | |
} | |
def setThermostatMode(mode, temp = null) { | |
api('set_temperature_mode', [mode, temp as Integer]) | |
} | |
def fanOn() { | |
setThermostatFanMode('on') | |
} | |
def fanAuto() { | |
setThermostatFanMode('auto') | |
} | |
def fanCirculate() { | |
setThermostatFanMode('circulate') | |
} | |
def setThermostatFanMode(mode) { | |
api('set_fan_mode', [mode]) | |
} | |
def poll() { | |
api('status', [], true) | |
} | |
def api(action, args = [], update = false) { | |
def params = [ | |
uri: "http://scripts.3dgo.net/nest/api.php?/", | |
headers: [ 'X-Auth': device.deviceNetworkId ] | |
] | |
params.uri = params.uri + action | |
for(arg in args) { | |
params.uri = params.uri + '/' + arg | |
} | |
log.debug("Calling: " + params.uri) | |
def success = { response -> | |
log.debug "Response: " + response.data | |
if(response.data.temperature) { | |
log.debug "Setting temp: " + response.data.temperature | |
sendEvent (name: 'temperature', value: response.data.temperature as Integer, unit: response.data.temperature_units as String) | |
} | |
if(response.data.mode == 'cool') { | |
sendEvent (name: "coolingSetpoint", value: response.data.target_temperature, unit: response.data.temperature_units) | |
} else if (response.data.mode == 'heat' || response.data.mode == 'emergency heat') { | |
sendEvent (name: "heatingSetpoint", value: response.data.target_temperature, unit: response.data.temperature_units) | |
} | |
if(response.data.fan_mode) { | |
log.debug "Setting fan mode: " + response.data.fan_mode | |
sendEvent (name: "thermostatFanMode", value: response.data.fan_mode as String) | |
} | |
if(response.data.mode) { | |
sendEvent (name: "thermostatMode", value: response.data.mode) | |
} | |
} | |
httpGet(params, success) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment