Is it possible to have 2 push buttons in 1 tile

Not sure how to explain but is it posible to have to momentry push buttons within one device handle. been playing with the code but its the first time i have even looked at it so its a very step learning curve. basically i need a device type that lets me click on 2 seperate buttons within it. this is then linked to mqtt sending an on and off command. i cant use a switch as i have no way of knowing the current state, hence the 2 buttons.

the code below is what i have been hacking about at learning. where i have put PUSH1 this is what i would like to do for that button and then push is the other. just have no idea how or if even possible :frowning:

/**
 *  Copyright 2015 SmartThings
 *
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
 *
 *  Momentary Button Tile
 *
 *  Author: SmartThings
 *
 *  Date: 2013-05-01
 */
metadata {
	definition (name: "Momentary Button Tile", namespace: "smartthings", author: "SmartThings") {
		capability "Actuator"
		capability "Switch"
		capability "Momentary"
		capability "Sensor"
        capability "Switch Level"
	}

	// simulator metadata
	simulator {
	}

	// UI tile definitions
	tiles {
		standardTile("switch1", "device.switch", width: 6, height: 4, canChangeIcon: true) {
			state "off", label: 'Turn off', action: "momentary.push1", backgroundColor: "#ffffff"
		}
              	}
            
                tiles(scale: 2) {
		multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4, canChangeIcon: true){
			tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
				attributeState "on", label:'Turn On', action:"momentary.push", icon:"http://cdn.device-icons.smartthings.com/Lighting/light10-icn@2x.png", backgroundColor:"#79b821"
		
			}
			tileAttribute ("device.level", key: "SLIDER_CONTROL") {
				attributeState "level", action:"switch level.setLevel", range:"(5..32)"
			}
		}
     
	}
		main "switch"
      details(["switch1", "level","switch"])
	}
      preferences {

		input name: "room", type: "text", title: "room number", description: "Enter room number", required: true, displayDuringSetup: true
        input name: "devicenumber", type: "text", title: "device number", description: "Enter device number", required: true, displayDuringSetup: true
	
	}
  
def parse(String description) {
}

def push() {
	sendEvent(name: "switch", value: "100,!R${room}D${devicenumber}F1", isStateChange: true, display: false)
}
def push1() {
dEvent(name: "switch", value: "100,!R${room}D${devicenumber}F0", isStateChange: true, display: false)
}

def setLevel(value) {
	if (value == 0) {
  sendEvent(name: "switch", value: "100,!R${room}D${devicenumber}F0", isStateChange: true, display: false)
		
	} else {
    	sendEvent(name: "switch", value: "100,!R${room}D${devicenumber}FdP${value}", isStateChange: true, display: false)
		sendEvent(name: "switch", value: "onee ${value}" )
		sendEvent(name: "level", value: '${value}')
		
    	}
}

def on() {
	push()
}

def off() {
	push()
}
  1. Please surround code with three back-quotes to ensure its format is retained.

image

def method() {
   //do stuff
}
  1. Any “Standard Tile” can issue any specific Command regardless of the current State of the Attribute. So just create 2 unique Attributes, and 2 Standard Tiles.

http://docs.smartthings.com/en/latest/device-type-developers-guide/tiles-metadata.html#standard-tile

1 Like

Hi,

thanks for the heads up on the code, thats much simpler now.

how would you create the unique attributes, thats the but i dont really understand. had a quick look at the link but i’m at work on my lunch at the min. i have

state "off", label: 'Turn off', action: "momentary.push1", backgroundColor: "#ffffff"

and

attributeState "on", label:'Turn On', action:"momentary.push", icon:"http://cdn.device-icons.smartthings.com/Lighting/light10-icn@2x.png", backgroundColor:"#79b821"

and def as

def push() {
	sendEvent(name: "switch", value: "100,!R${room}D${devicenumber}F1", isStateChange: true, display: false)
}
def push1() {
dEvent(name: "switch", value: "100,!R${room}D${devicenumber}F0", isStateChange: true, display: false)
} 

push works not push1, and i can swap them over and push then works on the other tile and push1 doesn’t if that makes sense. i’m sure i’m probably missing something simple

think i’m sorted!!!

i noticed that i had put sendevent wrong missed “sen” out

i also needed to add a command in for push1 but this now works :slight_smile:

2 Likes

Can you please post the working version? We’re trying to use htmlTile to format the main tile but we can’t figure out two buttons in one main.

just posted on the other thread, mine was just on the main tile not actually on the main screen.

Thank you sir. I read through your post. Appreciate it.

If any one does find a way please let me know as it’s something I would like to do aswell