preferences {
section(“Title”) {
// TODO: put inputs here
input “thebutton”, “capability.button”
}
}
def installed() {
log.debug “Installed with settings: ${settings}”
initialize()
}
def updated() {
log.debug “Updated with settings: ${settings}”
unsubscribe()
initialize()
}
def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
subscribe(thebutton, “button”, buttonHandler)
}
// TODO: implement event handlers
def buttonHandler(evt) {
if (evt.value == “held”) {
log.debug “button was held”
} else if (evt.value == “pushed”) {
log.debug “button was pushed”
}
// Some button devices may have more than one button. While the
// specific implementation varies for different devices, there may be
// button number information in the jsonData of the event:
try {
def data = evt.jsonData
def buttonNumber = data.buttonNumber as Integer
log.debug "evt.jsonData: $data"
log.debug “button number: $buttonNumber”
} catch (e) {
log.warn “caught exception getting event data as json: $e”
}
}
Have you tried an actual device, or is it just not working in the using a virtual device in the IDE?
I was just able to get a button device working an an app, but the virtual device didn’t work. You can test using physical devices.
Edit: In fact, your app is working for me with my minimote.