Daily On Mode Magic Code


(Michael) #1

Does anyone have the code for the Mode Magic Daily On SmartApp? I am currently using it and would like to enhance it with a new luminance sensor I just bought. Thanks!


(Tim Slagle) #2

Should be able to find it in the IDE under “shared smart apps” in the code window of the IDE :smile:


(Michael) #3

Thanks. I looked there before I posted and didn’t see it. Maybe I missed it but unfortunately without a search feature it’s hard to find things there.


(Ben Edwards) #4

Here is is:

/**
 *  Scheduled Mode Change
 *
 *  Author: SmartThings

 *  Date: 2013-05-04
 */
preferences {
	section("At this time every day") {
		input "time", "time", title: "Time of Day"
	}
	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"
}

(Ben Edwards) #5

You can find this here:

Which is found here:


(Michael) #6

Ben thanks but unfortunately that is not the one. A month or so ago, I added a SmartThings application called “Daily On” (through my iPhone and not a custom SmartApp) that is in the Mode Magic category. It has several sections of input:
At sunrise… Change Mode to, Turn On, Turn off
At sunset… Change Mode to, Turn On, Turn off
Sunrise offset (optional)
Sunset offset (optional)
Zip code

I use this app specifically because I liked the Sunset offset feature where I turn my lights on an hour prior to sunset. I want to leverage this feature in my new app to also leverage a LUX value from my luminance sensor I just bought to turn on the lights even before an hour before sunset if the LUX is below a certain threshold.

Thanks!


App for changing mode when illumination changes