Smartthings Button smartapp

I just bought a samsung smartthings button and I need to create an app to send a webrequest whenever the button is pressed.
I already started to write the code, but it is not working so far.
Can you tell me what is wrong and how to make it work?

definition(
name: “The Button”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Call webhook when button is pressed.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png
)

preferences {
section(“When this Button is Pressed”) {
input “buttonDevice”, “capability.button”, title: “Notify”
}
}

def installed()
{
log.debug “Installed with settings: ${settings}”
subscribe(buttonDevice, “button”, buttonEventHandler)
initialize()
}

def updated()
{
log.debug “Updated with settings: ${settings}”
unsubscribe()
subscribe(buttonDevice, “button”, buttonEventHandler)
}

def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
}

def buttonEventHandler(evt) {
def buttonNumber = evt.jsonData.buttonNumber
log.debug buttonNumber
def deviceNetworkId = “c0a80002:50” // “10.10.0.10:3480” update with server IP in hex format
def ip = “192.168.0.2:80”
sendHubCommand(new physicalgraph.device.HubAction(""“GET /action.php?event=button1pressed HTTP/1.1\r\nHOST: ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "{deviceNetworkId}”))
log.debug “{location} - {presence.label ?: presence.name} - {evt.value}" sendPush("{location} - {presence.label ?: presence.name} - {evt.value}”)
}

What exactly isn’t working? Are you getting errors when installing/running? Or is your code not performing as intended? What is showing in your IDE log?

Hi Philh30, thanks for answering.
The goal of the app to notify a web server that the button was pressed.
This is not happening.
I checked the log and there was an error on line 59, I corrected it by removing variables on last lines log.debug and sendPush.
Now the log looks like this:

504e42e9-a799-4bba-bfca-8cb59ff4164d 6:44:48 AM: debug pushed

[504e42e9-a799-4bba-bfca-8cb59ff4164d]https://graph-na02-useast1.api.smartthings.com/ide/logs#504e42e9-a799-4bba-bfca-8cb59ff4164d) 6:44:48 AM: debug 1

504e42e9-a799-4bba-bfca-8cb59ff4164d 6:44:48 AM: debug pushed

504e42e9-a799-4bba-bfca-8cb59ff4164d 6:44:48 AM: debug 1

Hey, after I saved it and published it last time it started to work.
Thank you for your help.

For whoever needs a code to run according to a Samsung Button press:
evt.value is the kind of press, can be: pushed, held or double
evt.jsonData.buttonNumber is the button number

definition(
name: “The Button”,
namespace: “smartthings”,
author: “SmartThings”,
description: “Call webhook when button is pressed.”,
category: “Convenience”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet@2x.png
)

preferences {
section(“When this Button is Pressed”) {
input “buttonDevice”, “capability.button”, title: “Notify”
}
}

def installed()
{
log.debug “Installed with settings: ${settings}”
subscribe(buttonDevice, “button”, buttonEventHandler)
initialize()
}

def updated()
{
log.debug “Updated with settings: ${settings}”
unsubscribe()
subscribe(buttonDevice, “button”, buttonEventHandler)
}

def initialize() {
// TODO: subscribe to attributes, devices, locations, etc.
}

def buttonEventHandler(evt) {
def buttonNumber = evt.jsonData.buttonNumber
def deviceNetworkId = “c0a80002:50”
def ip = “192.168.0.2:80”
log.debug buttonNumber
sendHubCommand(new physicalgraph.device.HubAction(""“GET /buttonpressed.php?btnid={buttonNumber}&presstype={evt.value} HTTP/1.1\r\nHOST: ip\r\n\r\n""", physicalgraph.device.Protocol.LAN, "{deviceNetworkId}”))
log.debug “{evt.value}" sendPush("{evt.value}”)
}

Hello! I’m looking for a device handler for the Samsung Smartthings Button. The code posted here gives me multiple compiling errors. Would someone please point me to a working device handler?

Nevermind, I figured it out.

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.