SmartThings Community

[Release] Virtual Alexa Switch/Button

dth_virtual
alexa
dth_alerts
project_alerts

(Brian Pierron) #1

I put together some device handlers that take advantage of Alexa’s support for contact sensors:

Alexa now supports motion and contact sensors connected to a SmartThings Hub. Play a welcome message when the door opens, turn on a connected light when motion is detected, or ask, “Alexa, is the back door open?” To get started, connect a Works with SmartThings contact or motion sensor to the SmartThings Hub, following the manufacturer’s instructions, then link the SmartThings skill using the Alexa app.

These handlers can be triggered by SmartThings routines, while also showing up in Alexa as contact sensors.

Switch:

Button (momentary switch):


Using Contact and Motion Sensors to Trigger Alexa Routines (DTH in post 97) (Official Amazon Feature)
IHC Broadlink + Smartthings Integration How I did it using Alexa
(Eric) #2

I think you could have just used the Simulated Switch within SmartThings IDE and the Real Momentary Button.

Unfortunately your button like the SmartThings button kicks off multiple events when pushed causing issues for pistons in webCoRE.


(Brian Pierron) #3

I don’t think the real momentary button would work since it’s not a motion or contact sensor. This is the feature that these device handlers take advantage of:

Alexa now supports motion and contact sensors connected to a SmartThings Hub. Play a welcome message when the door opens, turn on a connected light when motion is detected, or ask, “Alexa, is the back door open?” To get started, connect a Works with SmartThings contact or motion sensor to the SmartThings Hub, following the manufacturer’s instructions, then link the SmartThings skill using the Alexa app.


Merkury SmartControl+
(Eric) #4

I use both of what I suggested daily with Alexa.

Not what you want to use them for though. I see what you are doing.


(Brian Pierron) #5

Thanks for the comments. I added some detail to the first post to try to clarify how these work.


(Jonny555555) #6

Can you give an example of what you could use these for? Why would I use this over the normal simulated contact sensor that I use webcore to control and then that in turn makes Alexa do things.


(Eric) #7

He doesn’t use webcore so using smart lighting he can’t control a simulated contact sensor. Using this he can turn a switch on / off with smart lighting and the contact sensor will open / close.

That said, these are much more useful when combined with webCoRE. For example, I have a contact sensor on my 4 year olds bedroom door. When it open and closes throughout the day I don’t really care to be notified, however at night when he is supposed to be sleeping it might be useful to get a verbal notification. I could create a virtual button like this and have a piston that says if certain conditions are set that tell SmartThings that my son is supposed to be sleeping, if his door opens, press the button. Then have Alexa speak something. It is an interesting idea.


(Brian Pierron) #8

I’m able to do that without webcore by using smartthings routines. For instance, I have a routine that only triggers when motion is detected between a certain time range, but only if no one is home. I send an alert in that scenario, but I could also use the device handlers I made to trigger an alexa announcement.


(Eric) #9

Yes, you can.

I’ve abandoned routines as there has been talk that ST is going to remove them. Not sure if they will. I just use webCoRE for everything because it has a lot more options.

It is a bit disappointing that I can’t trigger it to resume my audiobook.


(Eric) #10

where is the talk about ST and possibly abandoning routines?


(Eric) #11

I don’t remember where, but I think routines were to be replaced by scenes. It might be the same / similar functionality. Not sure. Historically routines were not very reliable. I moved away from them over a year ago. It might be better now. I’ve replaced all of my routines with Real Momentary Buttons and controlled them via webCoRE.


(Jonny555555) #12

Thanks for the explanations and ideas! I’ll try it out when I come up with an idea.


#13

I use virtual switches also to voice trigger a switch to cause something to happen, routine, etc., but in the new Alexa release virtual switches do not show when you select “device” under the routines process that can allow a custom text to speak action.


(Ron Czapala) #14

Thanks Brian! This is a great Device Handler that let me forward Smartthings button pushes to the Alexa simulated buttons so an Alexa routine cam react to the Smatthings button.

Much appreciated!


(ocpd+adhd+alz+md+hfa+fms+lol=me :)) #15

I’m sorry (I know the density here is in my head), but for some reason, I just can’t figure out what this is, or how to use it.

I even read through the whole thread, thinking, well, I see that others have the same wonderings I’m having, but still, even then, I’m just missing it somehow.

Can somebody give a detailed, step by step example?

NOTE: I currently already use webCoRE for 99% of my automations.
In that, I use lots of simulated switches for all kinds of things.
I also have Alexa devices doing various things.
I also have some ‘Echo Buttons’ for this and that.


#16

Alexa routines (not smartthings routines) Can currently be triggered by a Contact sensor or the Echo button device, but cannot as yet be triggered by a switch or any other brand of button.

One of the advantages of the echo routine is it lets you cause echo to speak a custom phrase, so it’s a really easy way to get verbal notifications.

Because smartthings allows you to create a virtual contact sensor, that means you can now cause echo to speak a custom phrase for any event that you can recognize in smartthings.

The only question left is how do you change the state on the virtual contact sensor so that echo will trigger its own routine.

There are two ways to do that. If you are already using WebCore, you can create a piston that will change the state of the virtual contact sensor.

But if you are not already using webcore, it’s probably overkill for this particular use case. Instead, you just use a DTH for your virtual device which will cause that virtual device to look like both a switch and a contact sensor.

That way it’s easy to turn the switch on and off just using the regular smart lighting feature, but because it is also a sensor, echo will be able to react to the changes. Turning the switch on makes the contact sensor look like it’s open. Turning the switch off makes it look like it’s closed.

But there’s one more issue that you have to deal with one one way or another: turning the switch off again so that it will be ready to use the next time.

By making the virtual device look like both a contact sensor and a momentary button, the OP Has something that turns itself off. The problem with that is it means you can’t set up an echo routine based on the “off” condition, but is long as you know that, that’s OK.

Another alternative is just to use power allowance on the virtual binary switch and have it always turn itself off after one minute. That will be enough for many people.

So different things work for different use cases, but the reason why you want to have a virtual device which is both a contact sensor and a switch is just because right now Amazon doesn’t let you trigger your echo routines from a switch.

And the reason you might want to make that switch actually be a momentary button is so you don’t have to figure out a way to turn it off again.

Did that help?


(ocpd+adhd+alz+md+hfa+fms+lol=me :)) #17

@JDRoberts
Haha, “Did that help?” lol
Have you ever typed anything on this forum that didn’t help?

Yes. That helped a lot!
OMG, sometimes I swear I can’t see my own freakin hand when it’s right in front of my face!
Thanks for helping to untangle my brain…once again. :slight_smile:

So…
Currently, I have a number of the official Echo Buttons in use to turn lights on and off, etc, via Alexa Routines connected to ST Simulated Switches.

Well, when I first got going with them, I set them up to use Simulated Momentary Buttons, but for some reason (I can’t recall exactly) that didn’t work.

So, I had to change over to using Simulated Switches instead.
Along with that, I had to write the Piston in webCoRE to turn it back off after the event so that (as you mentioned) it would be ready for next time.

Basically, I just have them working as toggle switches, with the only state that’s actually being tracked being the ‘On’ change.

If I’m understanding you correctly, I could use this new DTH in place of the Simulated Switches, and be able to cut out a line of code in my webCoRE Pistons (i.e. the line that turns the sim switches back off).

Is that right?

EDIT: Actually, I just tried it, and it does indeed do what I was thinking…enables me to leave out a complete line of code in my Pistons where I would normally have to turn the darn thing back off.

So, thanks again also to @bjpierron
I will be using this a lot! :slight_smile:


(ocpd+adhd+alz+md+hfa+fms+lol=me :)) #18

Does anyone know if I somehow upset @JDRoberts or something with my last post above?
If so, I have no idea how or why (it was all positive about his helpfulness here on this forum, etc), but I’d sure like to clear it up if so. I even sent a PM, but no response. :frowning:


#19

No worries. :sunglasses:

I can’t help with Webcore or with code because I rely on text to speech and that just doesn’t work.

For the same reason, I rarely read PMs— it can take weeks before I get to those, if at all.

So hopefully someone else will be able to answer your question above. It’s just not one I can help with.


(ocpd+adhd+alz+md+hfa+fms+lol=me :)) #20

Whew! :wipesbrow:
Thanks, @JDRoberts :slight_smile:


Simulated Contact Sensor