# Multiple http:// buttons

**URL:** <https://community.smartthings.com/t/multiple-http-buttons/209550>\
**Category:** Writing Device Types\
**Created:** [October 25, 2020, 6:32pm UTC](https://community.smartthings.com/t/multiple-http-buttons/209550 "2020-10-25T18:32:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andysmith13](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@andysmith13](https://community.smartthings.com/u/andysmith13)\
**Post date:** [October 25, 2020, 6:32pm UTC](https://community.smartthings.com/t/multiple-http-buttons/209550/1 "2020-10-25T18:32:14Z")

</div>

Hi,  
Does anyone have, or can anyone create a tile for the Samsung smartthings app, that has a number of momentary buttons that send http: commands?  
I have a pi running apache, that in turn is controlling some shutters and blinds.  
need 5 or 6 buttons on the same device / tile though.  
Any suggestions?  
many thanks  
ANdy

---

<div class="post-metadata">

**Author:** ![nayelyz](https://avatars.discourse-cdn.com/v4/letter/n/59ef9b/32.png) [@nayelyz](https://community.smartthings.com/u/nayelyz)\
**Post date:** [October 28, 2020, 1:17am UTC](https://community.smartthings.com/t/multiple-http-buttons/209550/2 "2020-10-28T01:17:08Z")

</div>

Hello @andysmith13,  
Configuring more than one button in the same device card/tile is not available yet, but there are two alternatives:

1. Create a multi-component device (Picture 1)

In the generated event of the button, you can identify the source component. Below, you will find a code snippet of the [SmartThings Schema](https://smartthings.developer.samsung.com/docs/devices/smartthings-schema/schema-basics.html) example.

```auto
const connector = new SchemaConnector()
    .enableEventLogging(2)
    .discoveryHandler((accessToken, response) => {
      const d1 = response.addDevice('st-schema-MultButton', 'ST schema MultButton', 'deviceProfileID')
      d1.manufacturerName('xxxx');
      d1.modelName('xxxx');
    })
    .stateRefreshHandler((accessToken, response) => {

      let d1 = response.addDevice('st-schema-MultButton')
      let main = d1.addComponent('main');
      main.addState('st.momentary')
      
      let comp2 = d1.addComponent('compone');
      comp2.addState('st.momentary')
      //...
    })
    .commandHandler((accessToken, response, devices) => {
      for (const device of devices) {
        for (const cmd of device.commands) {
          if (cmd.component === 'main' && cmd.command === 'push') {
            //HTTP request
          } 
        }
      }
    });

```

1. Create a custom capability with a List display type (Picture 2)

You would select the option you want and receive a command with its argument to use it as a condition to make the HTTP request.  
For more information about this option, you should see this [post](https://community.smartthings.com/t/custom-capability-and-cli-developer-preview/197296).  
The function to create new capability presentations is being fixed and will be available as soon as possible, so you could take this option as a future enhancement.  
The capability presentation to get an element similar to my example is:

```auto
"detailView": [
        {
            "label": "List Element",
            "displayType": "list",
            "list": {
                "state": {
                    "value": "listElement.value",
                    "alternatives": [
                        {
                            "key": "off",
                            "value": "Off",
                            "type": "inactive"
                        },
                        {
                            "key": "on",
                            "value": "On",
                            "type": "active"
                        },
                        {
                            "key": "autoOff",
                            "value": "Auto Off",
                            "type": "inactive"
                        }
                    ]
                },
                "command": {
                    "name": "setListElement",
                    "alternatives": [
                        {
                            "key": "off",
                            "value": "Off",
                            "type": "inactive"
                        },
                        {
                            "key": "on",
                            "value": "On",
                            "type": "active"
                        },
                        {
                            "key": "autoOff",
                            "value": "Auto Off",
                            "type": "inactive"
                        }
                    ]
                }
            }
        }
    ]

```

 ![multi-component](https://global.discourse-cdn.com/smartthings/original/3X/b/4/b4a06acb2e98712f2e64d6372ee81fe534256518.jpeg) ![list_display](https://global.discourse-cdn.com/smartthings/original/3X/7/7/77e4652dd5364531d1fecca99043b8b34db23f32.jpeg)

---

<div class="post-metadata">

**Author:** ![andysmith13](https://avatars.discourse-cdn.com/v4/letter/a/48db29/32.png) [@andysmith13](https://community.smartthings.com/u/andysmith13)\
**Post date:** [October 31, 2020, 9:31pm UTC](https://community.smartthings.com/t/multiple-http-buttons/209550/3 "2020-10-31T21:31:19Z")

</div>

thanks for this. the single button i am using (and it works fine), is the code below.

Is there a simple way to have say 6 of these buttons together?

thanks so much.  
andy

/\*

- HTTP Button
- Category: Device Handler
- 
- Source: [[BETA RELEASE] URI Switch -- Device Handler for controlling items via HTTP calls](https://community.smartthings.com/t/beta-release-uri-switch-device-handler-for-controlling-items-via-http-calls/37842)
- 
- Credit: tguerena, surge919, CSC
- v1.1 - changes to enhance the behavior of the button and make it a momentary button  
\*/

import groovy.json.JsonSlurper

metadata {  
definition (name: “HTTP Button”, namespace: “sc”, author: “SC”) {  
capability “Actuator”  
capability “Switch”  
capability “Momentary”  
capability “Sensor”  
}

```
preferences {
	input("DeviceIP", "string", title:"Device IP Address", description: "Please enter your device's IP Address", required: true, displayDuringSetup: true)
	input("DevicePort", "string", title:"Device Port", description: "Empty assumes port 80.", required: false, displayDuringSetup: true)
	input("DevicePathOn", "string", title:"URL Path", description: "Rest of the URL, include forward slash.", displayDuringSetup: true)
	//input("DevicePathOff", "string", title:"URL Path for OFF", description: "Rest of the URL, include forward slash.", displayDuringSetup: true)
	input(name: "DevicePostGet", type: "enum", title: "POST or GET", options: ["POST","GET"], defaultValue: "POST", required: false, displayDuringSetup: true)
	section() {
		input("HTTPAuth", "bool", title:"Requires User Auth?", description: "Choose if the HTTP requires basic authentication", defaultValue: false, required: true, displayDuringSetup: true)
		input("HTTPUser", "string", title:"HTTP User", description: "Enter your basic username", required: false, displayDuringSetup: true)
		input("HTTPPassword", "string", title:"HTTP Password", description: "Enter your basic password", required: false, displayDuringSetup: true)
	}
}

// simulator metadata
simulator {
}

// UI tile definitions
tiles {
	standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
		state "off", label: 'Push', action: "momentary.push", backgroundColor: "#ffffff", nextState: "on"
		state "on", label: 'Push', action: "momentary.push", backgroundColor: "#53a7c0"
	}
	main "switch"
	details "switch"
}

```

}

def parse(String description) {  
log.debug(description)  
}

def on() {  
push()  
}

def off() {  
push()  
}

def push() {  
log.debug “—Sending command— ${DevicePathOn}”  
sendEvent(name: “switch”, value: “on”, isStateChange: true, display: false)  
sendEvent(name: “switch”, value: “off”, isStateChange: true, display: false)  
sendEvent(name: “momentary”, value: “pushed”, isStateChange: true)  
runCmd(DevicePathOn)  
}

def runCmd(String varCommand) {  
def host = DeviceIP  
def LocalDevicePort = ‘’  
if (DevicePort==null) { LocalDevicePort = “80” } else { LocalDevicePort = DevicePort }

```
def userpassascii = "${HTTPUser}:${HTTPPassword}"
def userpass = "Basic " + userpassascii.encodeAsBase64().toString()

log.debug "The device id configured is: $device.deviceNetworkId"

def path = varCommand
log.debug "path is: $path"
//log.debug "Uses which method: $DevicePostGet"
def body = "" 
//log.debug "body is: $body"

def headers = [:] 
headers.put("HOST", "$host:$LocalDevicePort")
headers.put("Content-Type", "application/x-www-form-urlencoded")
if (HTTPAuth) {
	headers.put("Authorization", userpass)
}
log.debug "The Header is $headers"
def method = "POST"
try {
	if (DevicePostGet.toUpperCase() == "GET") {
		method = "GET"
		}
	}
catch (Exception e) {
	settings.DevicePostGet = "POST"
	log.debug e
	log.debug "You must not have set the preference for the DevicePOSTGET option"
}
log.debug "The method is $method"
try {
	def hubAction = new physicalgraph.device.HubAction(
		method: method,
		path: path,
		body: body,
		headers: headers
		)
	log.debug hubAction
	return hubAction
}
catch (Exception e) {
	log.debug "Hit Exception $e on $hubAction"
}

//sendEvent
if (varCommand == "off"){
	sendEvent(name: "switch", value: "off")
    log.debug "Executing OFF"
} else {
	sendEvent(name: "switch", value: "on")
    log.debug "Executing ON"
}

```

}
