The following is a Smartthings app developed to call Salesforce and use the resulting guest temperature preference to set a thermostat heat point based on the return value.
/**
* Salesforce Temperature Controller
**/
definition(
name: “Salesforce Temperature Controller”,
namespace: “Kloudhaven”,
author: “William Symans”,
description: “Sets temp based on guest profile”,
category: “SmartThings Labs”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/[email protected]”,
oauth: true)
preferences {
section (“Settings.”) {
input “switch1”, “capability.switch”
input “Thermostat”, “capability.thermostat”
}
}
def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}
def initialize() {
//the input for this POC will be a switch but would more likely be a sunrise event or presence event
subscribe(switch1, “switch”, switchhandler)
//Set the default thermostat values
Thermostat.heat();
Thermostat.setHeatingSetpoint(65);
}
def switchhandler(evt) {
log.debug “$evt.value”
//set the parameters to connect to Salesforce API
//for simplicity does not include Oauth or user identification
def params = [
uri: ‘https://smartthingspoc-developer-edition.na34.force.com’,
path: ‘/services/apexrest/guest/’
]
try {
httpGet(params) {resp ->
log.debug “resp data: ${resp.data}”
Thermostat.heat();
Thermostat.setHeatingSetpoint((resp.data.preftemp).toInteger());
}
} catch (e) {
log.error “error: $e”
}
}