Here you go:
/**
// Automatically generated. Make future change here.
definition(
name: “Schedule Basic Thermostat Settings”,
namespace: “jscgs350”,
author: “jscgs350”,
description: “Set my basic thermo settings, like heat/cool temp and fan, to a schedule”,
category: “My Apps”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png”)
preferences {
section(“Set these thermostats”) {
input “thermostat”, “capability.thermostat”, title: “Which?”, multiple:true
}
section("To these temperatures") {
input "heatingSetpoint", "number", title: "When Heating"
input "coolingSetpoint", "number", title: "When Cooling"
}
section("To this Fan setting") {
input "fanSetpoint", "enum", title: "Which setting?", multiple:false,
metadata:[values:['fanOn','fanAuto','fanCirculate']]
}
section("Configuration") {
input "dayOfWeek", "enum",
title: "Which day of the week?",
multiple: false,
metadata: [
values: [
'All Week',
'Monday to Friday',
'Saturday & Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
]
]
input "time", "time", title: "At this time"
//input "newMode", "mode", title: "Change to this mode"
}
section( "Notifications" ) {
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["Yes", "No"]], required: false
input "phoneNumber", "phone", title: "Send a text message?", required: false
}
}
def installed() {
// subscribe to these events
subscribe(thermostat, “heatingSetpoint”, heatingSetpointHandler)
subscribe(thermostat, “coolingSetpoint”, coolingSetpointHandler)
subscribe(thermostat, “temperature”, temperatureHandler)
subscribe(thermostat, “thermostatFanMode”, thermostatFanModeHandler)
initialize()
}
def updated() {
// we have had an update
// remove everything and reinstall
unschedule()
subscribe(thermostat, “heatingSetpoint”, heatingSetpointHandler)
subscribe(thermostat, “coolingSetpoint”, coolingSetpointHandler)
subscribe(thermostat, “temperature”, temperatureHandler)
subscribe(thermostat, “thermostatFanMode”, thermostatFanModeHandler)
initialize()
}
def initialize() {
log.debug "Scheduling Temp change for day " + dayOfWeek + " at time " + time
schedule(time, setTheTemp)
}
def heatingSetpointHandler(evt)
{
log.debug “heatingSetpoint: $evt, $settings”
}
def coolingSetpointHandler(evt)
{
log.debug “coolingSetpoint: $evt, $settings”
}
def temperatureHandler(evt)
{
log.debug “currentTemperature: $evt, $settings”
}
def thermostatFanModeHandler(evt)
{
log.debug “thermostatFanMode: $evt, $settings”
}
def setTheTemp() {
def doChange = false
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
int currentDayOfWeek = localCalendar.get(Calendar.DAY_OF_WEEK);
// Check the condition under which we want this to run now
// This set allows the most flexibility.
if(dayOfWeek == 'All Week'){
doChange = true
}
else if((dayOfWeek == 'Monday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.MONDAY){
doChange = true
}
else if((dayOfWeek == 'Tuesday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.TUESDAY){
doChange = true
}
else if((dayOfWeek == 'Wednesday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.WEDNESDAY){
doChange = true
}
else if((dayOfWeek == 'Thursday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.THURSDAY){
doChange = true
}
else if((dayOfWeek == 'Friday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.FRIDAY){
doChange = true
}
else if((dayOfWeek == 'Saturday' || dayOfWeek == 'Saturday & Sunday') && currentDayOfWeek == Calendar.instance.SATURDAY){
doChange = true
}
else if((dayOfWeek == 'Sunday' || dayOfWeek == 'Saturday & Sunday') && currentDayOfWeek == Calendar.instance.SUNDAY){
doChange = true
}
// some debugging in order to make sure things are working correclty
log.debug "Calendar DOW: " + currentDayOfWeek
log.debug "SET DOW: " + dayOfWeek
// If we have hit the condition to schedule this then lets do it
if(doChange == true){
log.debug "setTheTemp, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
log.debug " Initiating thermostat changes..."
thermostat.setHeatingSetpoint(heatingSetpoint)
thermostat.setCoolingSetpoint(coolingSetpoint)
thermostat.setThermostatFanMode("${fanSetpoint}")
thermostat.poll()
send "${label} has changed the heat to '${heatingSetpoint}' and cooling to '${coolingSetpoint}' and fan to '${fanSetpoint}'"
}
else {
log.debug "Temp/Fan change not scheduled for today."
}
log.debug "End of thermostat setting SmartApp"
}
private send(msg) {
if ( sendPushMessage != “Yes” ) {
log.debug( “sending push message” )
sendPush( msg )
}
if ( phoneNumber ) {
log.debug( "sending text message" )
sendSms( phoneNumber, msg )
}
log.debug msg
}
private getLabel() {
app.label ?: “jscgs350”
}
// catchall
def event(evt)
{
log.debug “value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}”
}