App that will turn off switch after a short period?

Hi everyone! I have wire up a relay that will buzz me into the front door of my apartment using a Linear switch hooked up to the buzzer button in my apartment. It works great but I need to ensure that it never stays on for longer then 20 seconds or so. Is there any easy program I can use to ensure it only stays on for an allotted amount of time? Thanks a lot!

Power Allowance would allow you do set it for a minute but that is too long for your purpose. You could modify it.

/**
 *  Power Allowance
 *
 *  Author: SmartThings
 */
preferences {
	section("When a switch turns on...") {
		input "theSwitch", "capability.switch"
	}
	section("Turn it off how many minutes later?") {
		input "minutesLater", "number", title: "When?"
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
}

def switchOnHandler(evt) {
	log.debug "Switch ${theSwitch} turned: ${evt.value}"
	def delay = minutesLater * 60
	log.debug "Turning off in ${minutesLater} minutes (${delay}seconds)"
	runIn(delay, turnOffSwitch)
}

def turnOffSwitch() {
	theSwitch.off()
}

Amazing thanks a lot Ben!

Sorry I’m really new to developing for Smartthings…How would I customize this to just effect the Linear relay?

If the linear relay comes in as a switch device type then it should work (does it come in as a switch for you?). The modification you would want to make is in the minutes/seconds bit.

It shows up as a Z-Wave Relay. Would that be considered a switch?

@urman does a device type of relay have capability of switch?

Yes, the relay has a capability of switch.

I used to have an app in the shared area called “Turn me off quick.” It should still be there. I did was Ben suggested you do… modified it to use seconds instead of minutes.

And here it is :smile:

/**
 *  Turn me off quick
 *
 *  Author: seateabee@gmail.com
 *  Heavily based on Power Allowance by SmartThings
 *  Date: 2013-06-28
 */
preferences {
	section("When a switch turns on...") {
		input "theSwitch", "capability.switch"
	}
	section("Turn it off how many SECONDS later?") {
		input "secondsLater", "number", title: "When?"
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
}

def updated() {
	log.debug "Updated with settings: ${settings}"

	unsubscribe()
	subscribe(theSwitch, "switch.on", switchOnHandler, [filterEvents: false])
}

def switchOnHandler(evt) {
	log.debug "Switch ${theSwitch} turned: ${evt.value}"
	def delay = secondsLater * 1000 /*Because delay is counted in mill-seconds, multiple seconds by 1000 to get the proper delay. */
	log.debug "Turning off in ${secondsLater} minutes (${delay}ms)"
	theSwitch.off(delay: delay)
}
1 Like

Thanks everyone for all the help! It is up an running and I am officially keyless!

1 Like

Andrew, could you share which Linear switch you used for your buzzer? Sorry, I’m new to this! Just want to get my door buzzer working with my SmartThings and there’s nothing to purchase off the shelf apparently. Here’s their Z-Wave product catalog for reference: http://www.linearcorp.com/pdf/literature/Z-Wave_Family_Brochure_Lit.pdf

Hi Kalvin!

Thats switch that I used. If you are not planning on putting this in wall, you can wire up the powered leads to an extension chord, or add a plug to them, then just plug it into the wall. Let me know if you have any more questions on it.

-Andrew

Hey Andrew, sorry I don’t understand your answer. I linked to all of Linear’s switches in one PDF, are you saying they are all exactly the same? Because I was asking which switch you used.

I actually just realized why you needed this script-- it’s because you got a switch that turns on and off? I guess what I really want is a “button”-- what’s the name for that?

The only Linear z-wave device in that PDF that looks possible is the “Isolated Contact Fixture Module” but I have no idea if that would work for a door buzzer.

Old thread but I’m hoping this will lead me to what i’m looking for.

I have a water valve that would control water refilling my boiler. When I open this valve manually, it’s usually only for about 15 seconds. If I were to automate this, I’d want to ensure that the switch that opens this value almost immediately shuts off. Otherwise I’d risk damaging my boiler and potentially flooding my basement.

I thought i’d use a momentary switch to avoid any issues with hitting the switch. Is the above smartapp the one I’d use to ensure the switch turns off? When I tried copying the above smartapp into IDE, i’m getting a metadata error?

thanks!

Hi im super new to ST, i love this diamond of code, for me its the thing i need to make my front gate and my garage door automated, but when i paste the code and try to publish it i have this error “Metadata definition not found”.

Can some body help?

If you are using the LFM-20 relays, just change the device type in the web ide for your device to " Z-Wave Virtual Momentary Contact Switch".

The relay will then behave like a momentary switch. You can then try this app: New smart app to link the virtual/simulated garage door device with two actual devices

Works very nicely for me.

I don’t have that exactly model, i have the Enerwave ZWN-RSM1S, i want an app like the one in this topic because i wanna make my buzzer works. With the Virtual Momentary Switch i have to press one to activate and press again to stop the buzz, and some times takes so long stop, so i need something to send a 1 or 2 sec pulse/signal to the relay.

Check this post for info on how you can bake momentary into a device type.

You’ll always be reliant on the reliability (or lack thereof) of Smartthings, however. That said, I use this momentary device type on my MIMOlite for my doorbell, and it seems to work pretty well. Definitely works better than using a smart app to “reset” the relay.