Skip to content

Instantly share code, notes, and snippets.

@bdwilson
Created February 13, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdwilson/8941d5dc0722ea67110204a56d51e770 to your computer and use it in GitHub Desktop.
Save bdwilson/8941d5dc0722ea67110204a56d51e770 to your computer and use it in GitHub Desktop.
/**
IFTTT Thermostat Driver for Hubitat
*
*/
metadata {
definition (name: "IFTTT Thermostat Driver", namespace: "brianwilson-hubitat", author: "Brian Wilson") {
capability "Thermostat"
command "setFollowSchedule"
attribute "followSchedule", "string"
}
main "temperature"
details(["thermostatFanMode", "heatingSetpoint", "coolingSetpoint","fanOperatingState","followSchedule","status"])
preferences {
input("APIKEY", "text", title: "IFTTT Webhook API Key", description: "Your IFTTT Webhook API Key", required: true)
input("deviceName", "text", title: "Device Name/Location:",required: true, defaultValue: "downstairs")
input("setHeat", "text", title: "Set Heat Name", required: true, defaultValue: "set_heat")
input ("setCool", "text", title: "Set Cool Name", required: true, defaultValue: "set_cool")
input ("resume", "text", title: "Resume Name", required: false, defaultValue: "resume")
input ("permHold", "text", title: "Perm Hold Name", required: false, defaultValue: "perm_hold")
//input ("tempHold", "text", title: "Temp Hold Name", required: false, defaultValue: "temp_hold")
input ("fanModeOn", "text", title: "Fan Mode On Name", required: false, defaultValue: "fan_mode_on")
input ("fanModeAuto", "text", title: "Fan Mode Auto Name", required: false, defaultValue: "fan_mode_auto")
input name: "debugOutput", type: "bool", title: "Enable debug logging?", defaultValue: true
}
}
// parse events into attributes
def parse(String description) {
log.debug("Here: ${description}")
}
// handle commands
def setHeatingSetpoint(Double temp)
{
logDebug("Settings: ${settings.setHeat}")
def cmd = ${settings?.setHeat}
def ifttt_base = "https://maker.ifttt.com/trigger/" + ${settings.deviceName} + "-" + ${cmd} + "/with/key/" + ${settings.APIKEY}
ifttt_base = ifttt_base + "?value1=" + ${temp}
logDebug("Sending request: ${ifttt_base}")
httpGet(uri: "ifttt_base"){response ->
if(response.status != 200) {
log.error "ERROR: ${response.status}"
}
else {
sendEvent(name: 'heatingSetpoint', value: temp as double)
}
}
}
def setFollowSchedule() {
def cmd = ${settings.resume}
def ifttt_base = "https://maker.ifttt.com/trigger/" + ${settings.deviceName} + "-" + ${cmd} + "/with/key/" + ${settings.APIKEY}
logDebug("Sending request: ${ifttt_base}")
httpGet(uri: "ifttt_base"){response ->
if(response.status != 200) {
log.error "ERROR: ${response.status}"
}
else {
logDebug "Successfully sent follow schedule.!"
}
}
}
def setCoolingSetpoint(double temp) {
def cmd = ${settings.setCool}
def ifttt_base = "https://maker.ifttt.com/trigger/" + ${settings.deviceName} + "-" + ${cmd} + "/with/key/" + ${settings.APIKEY}
ifttt_base = ifttt_base + "?value1=" + ${temp}
logDebug("Sending request: ${ifttt_base}")
httpGet(uri: "ifttt_base"){response ->
if(response.status != 200) {
log.error "ERROR: ${response.status}"
}
else {
sendEvent(name: 'coolingSetpoint', value: temp as double)
}
}
}
def fanOn() {
def cmd = ${settings.fanModeOn}
def ifttt_base = "https://maker.ifttt.com/trigger/" + ${settings.deviceName} + "-" + ${cmd} + "/with/key/" + ${settings.APIKEY}
logDebug("Sending request: ${ifttt_base}")
httpGet(uri: "ifttt_base"){response ->
if(response.status != 200) {
log.error "ERROR: ${response.status}"
} else {
sendEvent(name: 'fanOperatingState', value: "on")
}
}
}
def fanAuto() {
def cmd = ${settings.fanModeAuto}
def ifttt_base = "https://maker.ifttt.com/trigger/" + ${settings.deviceName} + "-" + ${cmd} + "/with/key/" + ${settings.APIKEY}
logDebug("Sending request: ${ifttt_base}")
httpGet(uri: "ifttt_base"){response ->
if(response.status != 200) {
log.error "ERROR: ${response.status}"
} else {
sendEvent(name: 'fanOperatingState', value: "auto")
}
}
}
private logDebug(msg) {
if (settings?.debugOutput || settings?.debugOutput == null) {
log.debug "$msg"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment