Skip to Content

How to Trigger Alexa Routines with Anything From SmartThings

How to Trigger Alexa Routines with Anything From SmartThings

One of the hardest things to do right now is to trigger Amazon Alexa routines with any device or any condition from Samsung SmartThings. Right now, what you can do is attach Contact and Motion Sensors to Alexa and use those to trigger Alexa Routines, but what if you want to trigger with something like a Leak Sensor? What about temperature? Humidity? Lighting levels? What about a certain time of day, plus the presence of someone in your home?

These are the kinds of requests I get each and every day on Automate Your Life and as such, I went out and found a solution. Now, full credit to BJ Pierron who wrote this Device Handler code for a specialized device type that will allow you to do this.

You can use code for SmartThings to make your own Simulated Alexa Switch. The simulated Alexa Switch code for SmartThings is provided by ‘bjpierron’: https://raw.githubusercontent.com/bjpierron/SmartThings-Alexa/master/devicetypes/bjpierron/simulated-alexa-switch.src/simulated-alexa-switch.groovy

Automate Your Life is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to amazon.com and other Amazon websites.

Simulated Alexa Switch by BJ Pierron

/**
 *  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.
 *
 */
metadata {

    definition (name: "Simulated Alexa Switch", namespace: "bjpierron", author: "bjpierron") {
        capability "Switch"
        capability "Sensor"
        capability "Actuator"
        capability "Contact Sensor"	    		
    }
    
    simulator {
		status "open": "contact:open"
		status "closed": "contact:closed"
	}

    tiles {
        standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
            state "off", label: '${currentValue}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
            state "on", label: '${currentValue}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#00A0DC"
        }
        main "switch"
        details(["switch"])
    }
}

def parse(description) {
}

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

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

Now, to implement all of this! Watch our video below that will help you integrate Alexa and SmartThings in this new and exciting way.

https://youtu.be/BqJ3cHHcNyc

Aur-El

Friday 1st of April 2022

Thank you so much guys! I was able to modify the code to also acts as a motion sensor, now i can use all my Echo paired Zigbee devices into the smarthings app.

Mike

Wednesday 12th of January 2022

I tried the above fix. I was able to get the device handler and the device uploaded. When I go to the app the simulated switch does not show in routines. It does show up as a device. There is a note at the bottom of the list of available devices that says devices without available conditions aren’t shown. Any suggestions?

Ankur

Wednesday 5th of January 2022

Thanks Alan, appreciate your work – this is super helpful. This works well with almost all devices. The only routine I am not able to run is getting Alexa to open garage door or driveway using a YoLink controller (i.e. as a trigger switch instead of a passive switch). This may be an Alexa restriction. Because when I go to create an Alexa routine where ST virtual switch triggers a YoLink controller in Alexa, it shows that my only option is to CLOSE the YoLink garage/driveway controller, with no option to OPEN. So it’s great if I forgot to close the garage and need to close it. But not if I lost my physical controller and want to open it from ST app.

Tom

Tuesday 27th of April 2021

This is nice, simple, and just what I needed! THANKS!!

Alan Varughese

Saturday 22nd of May 2021

You're welcome Tom!

John

Thursday 19th of November 2020

Works GREAT!!!! I'm new to the smart game. I have a lot of different products that are all now work with Alexa now!

Thanks

Alan

Thursday 19th of November 2020

That's great John. It's exciting to see everything start to work!