How to turn Virtual Switch into a push button?

Hi, I’m new to SmartThings and almost done configuring my devices & scenarios. I use Virtual Switches to trigger Lighting scenes (eg. Late Afternoon, Evening, Late Evening). Use Virtual Switches as well to change stations on Sonos. It works as expected however, the “Device Type” code is currently written as a switch (with on & off state). Since lighting scenes do not neccessarily have to be switched off, I would like to turn this into a push button which does not visually change status.

The code I used to create the new Device Type is from Juan Risso:

    metadata {
        definition (name: "Virtual Switch", namespace: "smartthings", author: "Juan Risso") {
        capability "Switch"
        capability "Refresh"        

	// simulator metadata
	simulator {

	// UI tile definitions
	tiles {
		standardTile("button", "device.switch", width: 2, height: 2, canChangeIcon: true) {
			state "off", label: 'Off', action: "switch.on", icon: "st.Kids.kid10", backgroundColor: "#ffffff", nextState: "on"
			state "on", label: 'On', action: "", icon: "st.Kids.kid10", backgroundColor: "#79b821", nextState: "off"
		standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
			state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
		main "button"
		details(["button", "refresh"])

def parse(String description) {

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

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

Any hints how to turn this into a push button?


Any reason you wouldn’t use the existing “Momentary Button Tile” device type? This is a virtual push button (momentary on switch).

I do this too - I have code in the smart app to turn the button off after it has done its processing. The idea wasn’t mine, there are examples elsewhere in the forum.

Great, I replaced my old code with the “Momentary Button Tile” template code and now the on/off button turned into a push button. Thanks!!

@raulpesch can you show me your finish app I would like to see if it would work for me? thanks