Change virtual switch device handler to be momentary switch- please help i have no idea what im doing

hi all , i am trying to do a frankenstien electric curtain integration and im using the orvibo zigbee relays

i have been basing my setup on this post but i cant seem to figure out how to edit the Virtual DH made by erocm123 to change from being a normal on off switch to be a momentary switch.

im not a coder but im guessing its somewhere in this that i need to change from on /off to momentary

below is from here

definition (name: “Simulated Switch”, namespace: “erocm123”, author: “Eric Maycock”) {
capability "Switch"
capability "Relay Switch"
capability “Actuator”

	command "onPhysical"
	command "offPhysical"
}

tiles(scale: 2) {
	multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
		tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
			attributeState "off", label: '${name}', action: "switch.on", icon: "st.switches.light.off", backgroundColor: "#ffffff", nextState:"turningOn"
            attributeState "on", label: '${name}', action: "switch.off", icon: "st.switches.light.on", backgroundColor: "#00a0dc", nextState:"turningOff"
            attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.light.off", backgroundColor:"#ffffff", nextState:"turningOn"
            attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.light.on", backgroundColor:"#00a0dc", nextState:"turningOff"	
		}

}

You can just change the The device type by selecting a different dth from the dropdown list in the IDE under devices/your device/edit (at the bottom) /type* (choose momentary switch) /save.

If your insistent on coding it, you can create a device handler app from template but don’t actually hit create, you can see and or copy the code that shows up when you select momentary switch, i think it’s an option.

/**

  • 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.

  • SmartSense Virtual Momentary Contact Switch

  • Author: SmartThings

  • Date: 2013-03-07
    */
    metadata {
    definition (name: “Z-Wave Virtual Momentary Contact Switch”, namespace: “smartthings”, author: “SmartThings”, ocfDeviceType: “x.com.st.d.sensor.contact”) {
    capability "Actuator"
    capability "Switch"
    capability "Refresh"
    capability "Momentary"
    capability "Sensor"
    capability “Relay Switch”
    }

    // simulator metadata
    simulator {
    status “on”: "command: 2003, payload: FF"
    status “off”: “command: 2003, payload: 00”

    // reply messages
    reply "2001FF,2502,delay 2000,200100,2502": "command: 2503, payload: FF"
    reply "200100,2502": "command: 2503, payload: 00"
    

    }

    // tile definitions
    tiles {
    standardTile(“switch”, “device.switch”, width: 2, height: 2, canChangeIcon: true) {
    state “off”, label: ‘${name}’, action: “momentary.push”, icon: “st.switches.switch.off”, backgroundColor: "#ffffff"
    state “on”, label: ‘${name}’, action: “switch.off”, icon: “st.switches.switch.on”, backgroundColor: “#00a0dc
    }
    standardTile(“refresh”, “device.switch”, inactiveLabel: false, decoration: “flat”) {
    state “default”, label:’’, action:“refresh.refresh”, icon:“st.secondary.refresh”
    }

    main "switch"
    details(["switch","refresh"])
    

    }
    }

def parse(String description) {
def result = null
def cmd = zwave.parse(description, [0x20: 1])
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
log.debug "Parse returned ${result?.descriptionText}"
return result
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
[name: “switch”, value: cmd.value ? “on” : “off”, type: “physical”]
}

def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
[name: “switch”, value: cmd.value ? “on” : “off”, type: “digital”]
}

def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
if (state.manufacturer != cmd.manufacturerName) {
updateDataValue(“manufacturer”, cmd.manufacturerName)
}

final relays = [
    [manufacturerId:0x0113, productTypeId: 0x5246, productId: 0x3133, productName: "Evolve LFM-20"],
	[manufacturerId:0x5254, productTypeId: 0x8000, productId: 0x0002, productName: "Remotec ZFM-80"]
]

def productName  = null
for (it in relays) {
	if (it.manufacturerId == cmd.manufacturerId && it.productTypeId == cmd.productTypeId && it.productId == cmd.productId) {
		productName = it.productName
		break
	}
}

if (productName) {
	log.debug "Relay found: $productName"
	updateDataValue("productName", productName)
}
[name: "manufacturer", value: cmd.manufacturerName]

}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren’t interested in
[:]
}

def push() {
def cmds = [
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.switchBinaryV1.switchBinaryGet().format(),
“delay 3000”,
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
]
}

def on() {
push()
}

def off() {
[
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.switchBinaryV1.switchBinaryGet().format()
]
}

def refresh() {
delayBetween([
zwave.switchBinaryV1.switchBinaryGet().format(),
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
])
}

Hi Matt thanks so much for the quick reply. i think its a bit more complicated as the main DH has 3 separate relays all which work great as momentary switches, but smart things doesn’t separate the 3 relays into child devices which is why i need virtual switches to map to each relay to control them separate in routines etc. but at the moment the one i use from erocom123 works great except it keeps the relays on each time rather than just a “push button” or momentary as what i need.

1 Like

That’s for z-wave. You’re using zigbee.

1 Like

I following you now, thanks for the explanation!

so i guess this is just too complicated to be done ?

Looking for the same solution to use the ST Simulated switch with zwave momentary relay. Did you find solution ?