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

Expose a motion sensor in the Alexa Skill and you should be able to just use it. For a switch to trigger, a regular virtual switch isn't supported by AWS. Only motion sensors and contact sensors are. So you need to use this simple custom code.

Copy this code from Chris Wilson @cwwilson08 and create a new virtual device using this driver. Then expose it to the Alexa Skill. It will mimic a motion sensor output when a switch is digitally turned on within HE

metadata {
	definition (name: "Virtual motion with Switch", namespace: "cw", author: "cwwilson08") {
		capability "Sensor"
		capability "Motion Sensor"
        capability "Switch"
	}   
}

def on() {
    sendEvent(name: "motion", value: "active")
    sendEvent(name: "switch", value: "on")
    runIn(12, off)
}

def off() {
    sendEvent(name: "motion", value: "inactive")
    sendEvent(name: "switch", value: "off")
}

def installed() {
}
4 Likes