Making one switch turn another switch on or off?


(Natemare13) #1

Does anyone have an app or code suggestion that will turn off a switch if another switch is turned on/off a certain amount of times in a certain time window? Looking for a physical way to turn my alarm (sirens) off. I forgot the house was armed and the sirens went off – just at that moment my iPhone battery died. So now I had no way to control smartthings (or the sirens other then to run around the house to the two sirens and take the batteries out.

Looking for a suggestion on how to physically control the alarm (arm and disarm) which basically means physically controlling A) turning sirens off (probably the easier of the two) and B) changing the mode of smartthings into a “security” mode I have settup which arms doors and windows etc.


(Todd Wackford) #2

Take a look at the app “Double Tap”. With a little bit of modification it could do exactly what your looking for.

HTH,
Twack


(Natemare13) #3

Thanks Twack!


(Cory S) #4

Double Tap is an odd app. It works great on some switches for me, but not at all on others. Same brand and type throughout.


(Jason E) #5

i did something simular. I used the double tap as a start and here is what I came up with. It works most of the time.

/**
 *  Mirror Switch
 *
 *  Author: Jason E
 */
preferences {
	section("When this switch is used...") {
		input "master", "capability.switch", title: "Where?"
	}
	section("Turn on or off all of these switches as well") {
		input "switches", "capability.switch", multiple: true, required: false
	}
	section("And turn off but not on all of these switches") {
		input "offSwitches", "capability.switch", multiple: true, required: false
	}
	section("And turn on but not off all of these switches") {
		input "onSwitches", "capability.switch", multiple: true, required: false
	}
}

def installed()
{
	subscribe(master, "switch", switchHandler, [filterEvents: false])
}

def updated()
{
	unsubscribe()
	subscribe(master, "switch", switchHandler, [filterEvents: false])
}

def switchHandler(evt) {
	log.info evt.value
	def recentStates = master.statesSince("switch", new Date(now() - 6000))
	log.debug "${recentStates?.size()} STATES FOUND, LAST AT ${recentStates ? recentStates[0].dateCreated : ''}"

	if (evt.value == "on") {
		log.debug "detected on, turn on other light(s)"
		onSwitches().on()
	} else if (evt.value == "off") {
		log.debug "detected off, turn off other light(s)"
		offSwitches().off()
	}
}

private onSwitches() {
	switches + onSwitches
}

private offSwitches() {
	switches + offSwitches
}

private lastTwoStatesWere(value, states) {
	// first get a list of the only the on and off events, so that wakeup events don't mess us up
	log.debug "UNFILTERED: [${states.collect{it.dateCreated + ':' + it.value}.join(', ')}]"
	def onOff = states.findAll { it.isPhysical() || !it.type }
	log.debug "FILTERED:   [${onOff.collect{it.dateCreated + ':' + it.value}.join(', ')}]"
	onOff.size() > 1 && onOff[0].value == value && onOff[1].value == value
}

(Todd Wackford) #6

I put a slight spin on switching other switches. Look at my project “Switch With Me”.

Twack