Using Virtual Switch to trigger Routine?

Thanks, this new version does not require a condition for Toggle off which is what I needed. Thanks again

Can you add “Widgets” for iOS? A couple of things I do all of the time that I would love to be able to have on my iPhone lock screen or somewhere other than going through the steps of opening up the App, scrolling, and clicking.

Official smart things widget feature for iOS can only represent a routine.

Alternatively, you can use an IFTTT do button, which gives you more options.

2 Likes

@JDRoberts, are you a DemiGod?! Don’t even know you but I love you man!

3 Likes

These two apps - Switch Activates Home Phrase and Switch Changes Mode - look identical. They also aren’t switches; virtual or not. The first requirement of both apps is to choose a switch. For the first app there isn’t any way to specify the IFTTT integration. The second switch seems to be intended for Modes but has no way of using it as the trigger or as the action. The configuration pages of both apps are exactly the same. And in my testing, they do exactly the same thing: choose a trigger switch (an EXISTING switch) and then what Routine to fire if it’s ON and which to fire when it’s OFF. And again, there’s no way to use IFTTT with it. Maybe the apps are broken? Maybe there’s some buttons or features missing? Maybe I’m missing something but if I want to create a virtual switch shouldn’t there just be a virtual switch I can add to my Things list that can fire off any Routine (or more)? Seems like the SmartThings app is missing some really basic functions.

It sounds like you’re feeling frustrated right now, and I think we’ve all been at that place. Smartthings is both powerful and flexible and can do many different functions. But it’s not intuitive and it can be hard to figure out how to get it to do those things. :disappointed_relieved:

For example, Unfortunately, SmartThings doesn’t give you a way through the mobile app to create a virtual switch. You have to go through the IDE (integrated development environment), which is a website that gives you access to your account information. You can get there by clicking on the community link at the top right of this page which will take you to the first page of the forum, and then clicking on “developer tools” at the top right of that page.

Once you have created a virtual switch, it will show up on any of your device lists for switches. Including on the selection list for the two smartapps.

The two smartapps do different things. One lets you assign a routine to the switch. The other lets you assign a mode to the switch. I know that doesn’t seem like a big distinction, but these two smartapps were written quite early after smartthings came out, and it was a big deal at the time. The switch can be virtual or physical.

For a step-by-step set of instructions on how to do all of this, including creating the virtual switch, see the FAQ for setting up echo to control a routine. You just don’t need to do the final step to have echo do it, just do the first two.

As far as then tying everything to IFTTT, again, once you have created the virtual switch, it will show up on any of your lists of switches. Including the one where you authorize IFTTT to use that switch. Once you have done that, then the virtual switch will be available in the SmartThings service/channel and you can just select it when you’re creating an IFTTT applet.

So three basic steps:

One) Create a virtual switch through the IDE

  1. use the smartapp from the marketplace to have the switch run a routine. (After that, every time that switch comes on, the routine you specified will run.)

  2. if you want to use it with IFTTT, you will need to authorize IFTTT to access the virtual switch in the SmartThings service/channel, and after that it will be available to use in an IFTTT applet/recipe.

Again, if this all seems frustrating and unnecessarily complicated, I don’t think any of the community members are going to disagree with you. We can’t change the way SmartThings has chosen to design things, we can just share the information we have collectively discovered about how to accomplish the end result.

2 Likes

Is there any way to see the SmartApps list as one big list instead of categorized?

Unfortunately, no.

There used to be an unofficial list in the forum of the smartapps available in the marketplace section of the SmartThings mobile app, but it has not been updated for over a year:

The community created wiki has quick browse lists of community-created smartapps (The ones that don’t show up in the mobile app), but those are also divided by category. It’s just intended to make the forums easier to search.

http://thingsthataresmart.wiki/index.php?title=How_to_Quick_Browse_the_Community-Created_SmartApps_Forum_Section

I tried to create a simple walk through on how to set this up and I also created some new code. One issue I found was that the switch can’t turn on multiple times when using it with Ifttt, so I created a new Smart App for that. Hope it helps

There is an app in the market place that allows a virtual switch to run a mode or routine. It was one of the first apps I wrote and was amazed when SmartThings published it. Look under MarketPlace->Lights/Switches->Switch Activates Home Phrase or Switch changes mode.

Enjoy!

1 Like

As of a few months ago, you no longer need an extra smartapp in the middle. Routines now have the built-in ability to be triggered when a switch comes on, and that includes a virtual switch. You just need to have that same routine turn the virtual switch off again so that it will be ready for the next time.

Or use the virtual momentary button tile for your virtual switch since it turns itself off each time (like a traditional doorbell button).

So just create your routine and choose the “automatically perform when” option for that routine and then specify your virtual switch. :sunglasses:




On the switch definition, you would do this?

definition (name: “Virtual Switch”, namespace: “mattfrancis”, author: “Matt Francis”) {
capability "Switch"
capability "Refresh"
capability “Momentary”

  • Then you would call the .push() method?

Most people just use the existing virtual device types. So you just add a new device and assign it to one of the existing virtual device type handlers.

So just sign into the IDE and go to “devices” then choose “+ new device.”

And then under “type” choose the type a virtual switch you want. If you want one that will turn itself off every time, choose the “momentary button tile.”

You shouldn’t need to write any code if all you want is to have a virtual switch Run a routine. That’s what this thread has been about. Once you have the switch, you can just have echo turn it on. :sunglasses:

  1. create a virtual Switch (not a dth–use one of the existing DTH’s)

  2. create a routine that does everything you want and have it automatically turn on when your virtual switch turns on. If you use a virtual binary switch, also have the routine turn the switch off again. Otherwise use a virtual momentary switch

  3. now you have a routine that will run when that switch turns on. If you want to do it through echo, just authorize the switch to echo and when you tell echo to turn it on, your routine will run.

If you want to do it with any other automation, including the official Smart lighting feature or core, since the virtual switch should show up in your list of switches, you just select it as normal and again the routine will be activated.

So why were we using IFTTT?

So it’s really pretty simple now. You only need IFTTT if you want to use a custom phrase to start the process. You don’t need an extra smartapp. You just need a routine that runs when a specific switch comes on, and a virtual switch that echo has been authorized to turn on. :sunglasses:

If what you’re trying to do is have echo run that routine using a custom phrase , it’s exactly the same process for 1)-- create the virtual switch. Then you use the Alexa IFTTT service custom phrase as the “if” and that virtual switch coming on as the "that"in your applet.

So your two choices are:

“Alexa, turn on movie time” where “movie time” is the name of a virtual switch that will automatically start the routine you want to run. No IFTTT needed

Or

“Alexa, trigger movie time” where “movie time” is the custom phrase in the Alexa IFTTT service. You still use a virtual switch to automatically start the routine, but you don’t use the switch name with echo. You use your custom phrase.

Some people find there is less lag if they leave IFTTT out of the picture. Other people prefer to use custom phrasing rather than always having to say “turn on.” Choice is good. :sunglasses:

Old thread, but this inspired me to write up quick app that allows mode change to activate routine.

*** Under Test *** literally just finished, but wanted to post before forgot.

ModeSwitchRoutine.groovy

3 Likes

I don’t see this app anymore. I think SmartThings cleared out a few old ones… is this an app they removed?

Hello @justinlhudson. I’m just wondering what exactly your app does.

Does it control multiple individual switches that each relate to one of the routines? (A switch for each home, away, night etc.) or is it one switch per smart app and if you want to control multiple routines you need to have multiple apps all running?

Example I am using the old smart security app that is driven by mode… however with the routines that been added when a go to bed routine for example is activated I also want to change mode to night to activate alarm system.

As mentioned in my post 19 above, that smart app is no longer needed because a few months ago they added the ability for a routine to be triggered when a switch comes on. It’s right in the routine set up wizard. You just “automatically perform” when “something turns on or off.”

A Mode change should already automatically activate the routine as long as the routine is set up to run in that new Mode, so you don’t need to do anything for that.

If you only want to run a routine when changing from a specific Mode to a different mode, such as when changing from night to home but not when changing from away to home, The most straightforward way to do that will be with web core, although there are some other ways to do it as well.

If you don’t want to use web core, you can bootstrap it with the official features.

Create a routine which runs when a virtual switch comes on as described above.

Create a smart lighting automation which runs when the mode changes and which turns on that virtual switch and which itself only runs in a specific mode

That way the mode changes from night to home, the smart lighting automation run which turns on the virtual switch, the routine runs because the virtual switch came on.

So there are many different ways to handle all of these things, none of which should require writing your own smart app.

So start by looking at the “automatically perform when” options at the end of the routine set up wizard and you can add your virtual switch coming on there. :sunglasses:

1 Like

Awesome, thanks for the explanation

Yep. This is one if the apps that was deprecated.