Skip to content

Instantly share code, notes, and snippets.

@joshualyon
Created January 3, 2022 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshualyon/27144f408a5156a340815dd155381a38 to your computer and use it in GitHub Desktop.
Save joshualyon/27144f408a5156a340815dd155381a38 to your computer and use it in GitHub Desktop.
Virtual Momentary button
/**
* Virtual Momentary Button
*/
metadata {
definition (name: "Virtual Momentary Button", namespace: "joshua_lyon", author: "Josh Lyon") {
capability "Switch"
capability "Momentary"
capability "PushableButton"
}
preferences {
}
}
def push(int buttonNumber = 1) {
sendEvent(name: "switch", value: "on")
sendEvent(name: "pushed", value: 1, isStateChange: true)
sendEvent(name: "momentary", value: "pushed", isStateChange: true)
runIn(1,toggleOff)
}
def toggleOff(){
sendEvent(name: "switch", value: "off")
}
def on() {
push()
}
def off() {
push()
}
def installed() {
initialize()
}
def updated() {
initialize()
}
def initialize() {
sendEvent(name: "numberOfButtons", value: 1)
push();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment