Virtual Switch


I would like to create an app that is basically a virtual switch to send HTTP posts depending on the switch state.
I have no problems with the post part but I’m wondering how the virtual switch, not connected to any physical switch, needs to be implemented.

Thanks !

I did something similar with presence. You’ll need to pieces.

  1. A very basic device type for the switch
  2. A SmartApp to handle the http requests

My presence code is here if you want an example

How are you triggering the switch? It’s this a completely virtual setup or do you want physical interaction with it?

For example, I have a number of “virtual” switches that don’t exists in an form in the ‘real world.’ I turn them on and off via SmartApps. When they turn on they trigger other events/apps to turn.

For example, I have my Ubi setup so that when I say ‘Goodnight’ to Ubi, it turns on a virtual Switch. There is then a SmartApp with runs a routine for me. The final step in this routine is to turn off the virtual switch.

Is this the type of setup you’re looking for?

I had this same question a while back, I used a command in a basic device type (open/closed device) to send the commands. See below for example code, you call device.mycommand(“open”) from your smart app to “open” the device as an example or device.mycommand(“close”) to close the device. If you don’t want open/close use a different device type as your starting point (like a switch instead).

Good luck, let me know if you have any questions.

    metadata {
      definition (name: "virtualdevice", author: "you") {
        // Add commands as needed
        command "mycommand"
standardTile("tilename", "", width: 2, height: 2, canChangeBackground: true, canChangeIcon: true) {
              state "open",   label: '${name}', icon: "",   backgroundColor: "#ffa81e"
              state "closed", label: '${name}', icon: "", backgroundColor: "#79b821"

def mycommand(String status) {
     sendEvent (name: "contact", value: "${status}")

I’m trying to do the same but the virtual switch I’ve created doesn’t do anything. I can’t get ST to recognize it’s state. I coupled it to “Notify Me When” and when I change the button state on my app… nothing.

How did you set up your virtual button? What device type did you chose? Thanks!

The device type is “On/Off Button Tile.”

For what it’s worth I’ve only ever used these in SmartApps. I haven’t tried setting up rules from the dashboard.

Thanks Chris. I will follow your lead then.

EDIT TO ADD: The On/Off Button Tile does function correctly as a virtual button in the dashboard. Provides a nice way to create endless “Big Button” type of functionality. Thanks again @chrisb

@dawgonking my virtual devices seem to work fine with other Smartapps but not with the dashboard functions either like “notify me”. I was going to file a smartthings support request and see what they said since the base device code is right from their examples. I think it has something to do with some of the .state stuff not getting populated correctly but I have no idea why.