Trigger at a specific time not working?

I altered some code from ‘The Flasher’ so that my lights would blink at a certain time of night. It worked great but over the last week or so it just decided to die on me. Anyone else have that happen? Could it be related to the change just made to ‘delay’?

In case it would be helpful - Here’s the code:

/**
 *  Sleepy Time Mr. B
 *
 *  Author: oneaccttorulethehouse@gmail.com
 *  Date: 2014-02-10
 *
 * Code Heavily lifted from The Flasher
 * 
 * Flash the lights when it’s time to stop playing games and go to bed.
 *
 */
preferences {
	section("When the clock strikes…"){
		input "time1", "time", title: "When?", required: true
	}
	section("Then flash..."){
		input "switches", "capability.switch", title: "These lights", multiple: true
		input "numFlashes", "number", title: "This number of times (default 3)", required: false
	}
	section("Time settings in milliseconds (optional)..."){
		input "onFor", "number", title: "On for (default 1000)", required: false
		input "offFor", "number", title: "Off for (default 1000)", required: false
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	schedule(time1, "scheduleCheck")
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unschedule()
	schedule(time1, "scheduleCheck")
}

def scheduleCheck()
{
	log.trace "scheduledCheck"
	flashLights()

}

private flashLights() {
	def doFlash = true
	def onFor = onFor ?: 1000
	def offFor = offFor ?: 1000
	def numFlashes = numFlashes ?: 3

	log.debug "LAST ACTIVATED IS: ${state.lastActivated}"
	if (state.lastActivated) {
		def elapsed = now() - state.lastActivated
		def sequenceTime = (numFlashes + 1) * (onFor + offFor)
		doFlash = elapsed > sequenceTime
		log.debug "DO FLASH: $doFlash, ELAPSED: $elapsed, LAST ACTIVATED: ${state.lastActivated}"
	}

	if (doFlash) {
		log.debug "FLASHING $numFlashes times"
		state.lastActivated = now()
		log.debug "LAST ACTIVATED SET TO: ${state.lastActivated}"
		def initialActionOn = switches.collect{it.currentSwitch != "on"}
		def delay = 1L
		numFlashes.times {
			log.trace "Switch on after  $delay msec"
			switches.eachWithIndex {s, i ->
				if (initialActionOn[i]) {
					s.on(delay: delay)
				}
				else {
					s.off(delay:delay)
				}
			}
			delay += onFor
			log.trace "Switch off after $delay msec"
			switches.eachWithIndex {s, i ->
				if (initialActionOn[i]) {
					s.off(delay: delay)
				}
				else {
					s.on(delay:delay)
				}
			}
			delay += offFor
		}
	}
}

There’s been some chatter recently with problems with the runIn command as well as the delay command. Check here:

http://build.smartthings.com/forums/topic/delay-commands-greater-than-60s-not-permitted-since-when/

and here:

http://build.smartthings.com/forums/topic/bug-report-runin-function-fails-with-delay-60/

My guess is that the problems there are what’s effecting you app.

@oneaccttorulethehouse, Your “Flasher” clone app on a schedule should have started working again. As @chrisb mentioned there was a recent change with delayed commands that would have broke your app with delays longer than 60 seconds. That change has been reverted and they are now allowed again. We normally recommend folks use runIn in favor of delayed commands for longer delays ( > 60 seconds) because of command stacking issues. However, in your case it won’t be an issue because you’re triggering the entire flasher style sequence on a schedule, so your continued use of delayed commands should be just fine.

Unfortunately, it’s still not working. I’ve been playing with this app and another that died after the change to ‘delay’ over the last couple days (both under 60 seconds) and haven’t been able to resurrect either of them.

@oneaccttorulethehouse I’m sorry to hear it’s still not working for you. I tried the exact code you posted above against both a virtual and several different types of physical switches and it seems to work fine for me. I did notice a couple of times the scheduled time was late to fire by a minute or two, but it did always flash the correct number of times and delay between flashes. A few questions for you:

Is it never firing on the schedule time or are the actual commands being sent to the switch failing?
What type of and how many switches are you trying to flash?
How many times and what delay between flashes are you using?

I tried the flasher app as well and it also works as expected. I’ll try other variations and see if I’m able to reproduce your issue.

@Rappleg Sorry for taking so long to get back. So it’s still not working but I’ve got a bit more information. I’m using all the defaults in flasher (3 flashes for 1000 ms). I’m trying to get it to flash a lamp connected to a WeMo outlet. If I run this program through the simulator - no problem, works like a charm, even for the physical lamp that I’m trying make work IRL. Once I try to use it in practice, what I find is when I check the Activity log for the outlet that the program is sending the command to turn on and off, but the light itself is unaffected (i.e. nothing happens). Any suggestions?

Does the WeMo respond fine when you try switch it on/off outside of using a delay or from the things view? Have you tried it with any different outlets other than a WeMo? I don’t have one to test with at the moment, but will try and get my hands on one to see if I can reproduce your issue. It seems like it may be something to do with your WeMo rather than a problem with delay, but after I get one to do some more testing we’ll be able to confirm that or not. Thanks for the extra details, that should help us get to the bottom of your issue.

Don’t have any other outlets to try - but it definitely looks like it’s an issue with the WeMo. I see the commands sent to turn on and off the outlet but nothing happens. Recently I’ve noticed even the standard apps don’t trigger the WeMo anymore (i.e. Sunrise/Sunset). Any suggestions? Known issue?