7-day - Scheduled Mode Change


(veni) #1

Could anyone help me modify the “Scheduled Mode Change” app so it allows one to set a mode change based on a 7-day schedule and specific time?

I modified the code slightly but it seems to ignore the actual set day and triggers everyday at the specified time.

// Automatically generated. Make future change here.
definition(
    name: "test",
    namespace: "",
    author: "V. B",
    description: "test",
    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("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("Change to this mode") {
        input "newMode", "mode", title: "Mode?"
    }
}




def installed() {
    initialize()
}

def updated() {
    unschedule()
    initialize()
}

def initialize() {
    schedule(time, changeMode)
}

def changeMode() {
    if (location.mode != newMode) {
        if (location.modes?.find{it.name == newMode}) {
            setLocationMode(newMode)
            send "${label} has changed the mode to '${newMode}'"
        }
        else {
            send "${label} tried to change to undefined mode '${newMode}'"
        }
    }
}

private send(msg) {
    sendPush msg
    log.debug msg
}

private getLabel() {
    app.label ?: "SmartThings"
}

(Geko) #2

I don’t think you need to write an app for that. You can schedule “Hello Home” actions to run at specific time and days of week. And Hello Home action can be set up to change mode.


(veni) #3

You are absolutely correct, it can be achieved via the Hello mode setting. Thank you!