@KellyDarren,
Here is my code. I used a Virtual Momentary button instead of a regular virtual switch.
This just turns things on. You should be able to setup Harmony to turn off the switch at the conclusion of the off activity.
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* TV Source ON is a modified version of Big Turn ON by SmartThings
*
* Author: DarcRanger
*/
definition(
name: "TV Source ON",
namespace: "DR",
author: "DarcRanger",
description: "Use a Virtual Momentary Switch to turn one switch with an option to add a delay before turning on another switch.",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png"
)
preferences {
section("Trigger for two switches with delay in between") {
input "master", "capability.momentary", multiple: false, title: "Momentary button is pushed...", required: false
}
section("Select First Switch to turn on...") {
input "switches", "capability.switch", multiple: false
}
section("Select Second Switch to turn on... with Option for delay") {
input "theSwitch", "capability.switch", multiple: false
}
section("Turn it on how many SECONDS later?") {
input "delay", "number", title: "When?", defaultValue: 10
}
section("Notification by...") {
input("recipients", "contact", title: "Send notifications to", required: false) {
paragraph "Enter Phone Number for SMS"
input "phoneNumber", "phone", title: "Send a text message to?", required: false
paragraph "Enble Push Notifications with Silent Option"
input "pushNotification_Normal", "bool", title: "Select Push Notification Option", required: false, defaultValue: "false", submitOnChange:true
input "pushNotification_Silent", "bool", title: "Select Silent Push Alert", required: false, defaultValue: "false", submitOnChange:true
}
}
}
def installed()
{
subscribe(master, "momentary.pushed", onHandler)
subscribe(app, appTouch)
}
def updated()
{
unsubscribe()
subscribe(master, "momentary.pushed", onHandler)
subscribe(app, appTouch)
}
def onHandler(evt) {
log.debug "onHandler: $evt"
switches.on()
log.debug "Switches ${switches} turned: ON" //${evt.value}"
runIn(delay, SecondSwitch)
}
def appTouch(evt) {
log.debug "onHandler: $evt"
switches.on()
log.debug "Switches ${switches} turned: ON" //${evt.value}"
runIn(delay, SecondSwitch)
}
def SecondSwitch(){
log.debug "Turning on in ${delay} Seconds"
theSwitch.on()
log.debug "theSwitch ${theSwitch} turned: ON" //${evt.value}"
send app.label + " has been triggered. ${switches} and ${theSwitch} are turned: ON within ${delay} seconds."
}
private send(msg) {
if (location.contactBookEnabled) {
sendNotificationToContacts(msg, recipients)
}
else {
if ( phoneNumber ) {
log.debug( "sending text message" )
sendSms( phoneNumber, msg )
}
if (pushNotification_Normal && pushNotification_Silent) {
sendNotificationEvent(msg)
}else if(pushNotification_Normal && pushNotification_Silent == false){
sendPush(msg)
}
}
log.debug "NOTIFY---------------------------------------------"
log.info app.label + " has been triggered. First switch, ${switches} is turned: ON. After ${delay} second delay, the second switch, ${theSwitch}, is turned: ON."
}