Use a Motion Sensor or Virtual Switch to trigger an Alexa Routine

Sure, it's easy to do that. Here's a modified driver that optionally turns off in 0.5 seconds:

metadata {
	definition (name: "Virtual contact with auto-off Switch", namespace: "cw", author: "cwwilson08") {
		capability "Sensor"
		capability "Contact Sensor"
        capability "Switch"
	}   
}

preferences {
        section {
		    input (
                name: "AutoOff",
                type: "bool",
                title: "Enable auto off", 
                required: false, 
                displayDuringSetup: false, 
                defaultValue: false
            )
        }
}


def on() {
    sendEvent(name: "contact", value: "closed")
    sendEvent(name: "switch", value: "on")
    if (AutoOff) {
        runInMillis(500, off)
    }
}

def off() {
    sendEvent(name: "contact", value: "open")
    sendEvent(name: "switch", value: "off")
}   

def installed() {
}

After installing this, just turn on the option "Enable auto off" and save preferences.

Just so there's no misunderstanding or incorrect attribution. This driver isn't mine. It is modified from a Virtual Motion with Switch driver posted originally by @cwwilson08.

3 Likes