Buttons in SmartApp UI

(Geko) #1

I need to create a button in SmartApp UI. The Developer’s Guide lists buttons as one of the possibilities, but gives no details on syntax. See


  • buttons: Button to display.

Could not find any sample code in existing apps either.



Here’s a sample for the Big Turn OFF SmartApp. I believe it’s the last part of the code.

 *  Big Turn OFF
 *  Author: SmartThings
    name: "Big Turn OFF",
    namespace: "smartthings",
    author: "SmartThings",
    description: "Turn your lights off when the SmartApp is tapped or activated",
    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 I touch the app, turn off...") {
        input "switches", "capability.switch", multiple: true

def installed()
    subscribe(location, changedLocationMode)
    subscribe(app, appTouch)

def updated()
    subscribe(location, changedLocationMode)
    subscribe(app, appTouch)

def changedLocationMode(evt) {
    log.debug "changedLocationMode: $evt"

def appTouch(evt) {
    log.debug "appTouch: $evt"

(Geko) #3

There’s no buttons in this example. According to the Developer’s Guide I should be able to define buttons inside the ‘preferences / section’ statement:

preferences {
    section("Show Me Some Buttons") {
        buttons **what goes in here?**


Ah sorry! Thought you meant a pressable button on the SmartApp configuration tile (like Big Turn OFF).

I’ll check with the team and get back to you.

(Geko) #5

Hey @Tyler,
Thanks for trying to help me out. Any word from the developers?

(Geko) #6

Any ST developers out there? Still waiting for an answer. I’m looking for a syntax of the ‘buttons’ element of the SmartApp preferences as described here:


(Brian Steere) #7

/me pokes @urman and @ben

(Ben Edwards) #8

And @bflorian who I think is ultimately the man here.

(Geko) #9

Oh my… who’d have thought that it’s such a hard question to answer - 5 days and counting!

(Ben Edwards) #10

This is a community - not just a place to request support from SmartThings developers. There are a lot of things going on at the moment that are a higher priority than this issue. Nearly our whole engineering team is engaged in those activities.

We could have answered it right away with “we don’t know” but we are attempting to get to something better for you.

(Steve) #11

Buttons are an experimental element that may change in the future, may completely go away, and may not work the same between iOS and Android. They also have a tendency to not work before the SmartApp has been installed. There isn’t documentation for them because they are not fully supported yet.

That being said, if you want to try them at your own risk…BEHOLD!!!

def buttonsPage() {
dynamicPage(name: "buttonsPage", title: "Every 'button' type") {
	section("buttons") {
		buttons(name: "buttons", title: "required:false, multiple:false", required: false, multiple: false, buttons: [
			[label: "foo", action: "foo"],
			[label: "bar", action: "bar"]
		buttons(name: "buttonsRequired", title: "required:true", required: true, multiple: false, buttons: [
			[label: "foo", action: "foo"],
			[label: "bar", action: "bar"]
		buttons(name: "buttonsMultiple", title: "multiple:true", required: false, multiple: true, buttons: [
			[label: "foo", action: "foo"],
			[label: "bar", action: "bar"]
	section("Colored Buttons") {
		buttons(name: "buttonsColoredSpecial", title: "special strings", description: "SmartThings highly recommends using these colors", buttons: [
			[label: "complete", action: "bar", backgroundColor: "complete"],
			[label: "required", action: "bar", backgroundColor: "required"]
		buttons(name: "buttonsColoredHex", title: "hex values work", buttons: [
			[label: "bg: #000dff", action: "foo", backgroundColor: "#000dff"],
			[label: "fg: #ffac00", action: "foo", color: "#ffac00"],
			[label: "both fg and bg", action: "foo", color: "#ffac00", backgroundColor: "#000dff"]
		buttons(name: "buttonsColoredString", title: "strings work too", buttons: [
			[label: "green", action: "foo", backgroundColor: "green"],
			[label: "red", action: "foo", backgroundColor: "red"],
			[label: "both fg and bg", action: "foo", color: "red", backgroundColor: "green"]

Make sure you create a method that corresponds to your button.action like so:

def foo(params) {
  log.debug "foo($params)"

(Geko) #12

Pardon my impatience. I appreciate your effort and thank you for your support. :bouquet:

(Geko) #13

Awesome! Thank you, thank you, thank you!

(trac starr) #14

@geko @steve_vlaminck So do buttons no longer work? They just appear as text input for me.

(Geko) #15

Buttons work only in iOS, AFAIK.

(trac starr) #16

boo. But thanks for the info.