Hi all,
I am trying to create a virtual remote control with several button capabilities that change colors for the hue lights.
I am trying to set one of the tile to display the last button pressed (current selected color) so the value of the attribute should change when a button is pressed.
Unfortunately, I am stuck at sending the button’s label to that variable.
Maybe I didn’t explain correctly, but hopefully the code will be more easy to understand:
metadata {
definition (name: “Philips Hue Theme Selector”, namespace: “Custom Device Handlers”, author: “SmartThings”) {
capability "Actuator"
capability "Button"
capability "Configuration"
capability “Sensor”
attribute "value","string"
command "blue_theme"
command "red_theme"
command "purple_theme"
command "Unassigned"
command "Unassigned"
command "Unassigned"
command "Unassigned"
command "Unassigned"
}
simulator {
status "button 1 pushed": "command: 2001, payload: 01"
status "button 2 pushed": "command: 2001, payload: 29"
status "button 3 pushed": "command: 2001, payload: 51"
status "button 4 pushed": "command: 2001, payload: 79"
status "button 1 held": "command: 2001, payload: 15"
status "button 2 held": "command: 2001, payload: 3D"
status "button 3 held": "command: 2001, payload: 65"
status "button 4 held": "command: 2001, payload: 8D"
status "wakeup": "command: 8407, payload: "
}
tiles {
standardTile("button", "device.button") {
state "default", label: "", icon: "st.unknown.zwave.remote-controller", backgroundColor: "#ffffff"
}
valueTile("current_theme", "device.value", width: 3, height: 1) {
state "default", label: '${currentValue}', backgroundColor: "#1E90FF"
}
standardTile("blue_theme", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Blue", backgroundColor: "#1E90FF", action: "blue_theme"
}
standardTile("red_theme", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Red", backgroundColor: "#DC143C", action: "red_theme"
}
standardTile("purple_theme", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Purple", backgroundColor: "#9932CC", action: "purple_theme"
}
standardTile("push4", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Push 4", backgroundColor: "#ffffff", action: "push4"
}
standardTile("dummy1", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: " ", backgroundColor: "#ffffff", action: "push4"
}
standardTile("hold1", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Hold 1", backgroundColor: "#ffffff", action: "hold1"
}
standardTile("hold2", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Hold 2", backgroundColor: "#ffffff", action: "hold2"
}
standardTile("dummy2", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: " ", backgroundColor: "#ffffff", action: "push4"
}
standardTile("3", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Hold 3", backgroundColor: "#ffffff", action: "hold3"
}
standardTile("hold4", "device.button", width: 1, height: 1, decoration: "flat") {
state "default", label: "Hold 4", backgroundColor: "#ffffff", action: "hold4"
}
main "button"
details(["current_theme","blue_theme","red_theme","purple_theme","button","push4","dummy1","hold1","hold2","dummy2","hold3","hold4"])
}
}
def parse(String description) {
}
def blue_theme() {
push(1)
}
def red_theme() {
push(2)
}
def purple_theme() {
push(3)
}
def push4() {
push(4)
}
def push5() {
push(5)
}
def push6() {
push(6)
}
def push7() {
push(7)
}
def push8() {
push(8)
}
private push(button) {
log.debug "$device.displayName button $button was pushed"
sendEvent(name: “button”, value: “pushed”, data: [buttonNumber: button], descriptionText: “$device.displayName button $button was pushed”, isStateChange: true)
sendEvent(name: “value”, “value”:“device.button”)
}
private hold(button) {
log.debug "$device.displayName button $button was held"
sendEvent(name: “button”, value: “held”, data: [buttonNumber: button], descriptionText: “$device.displayName button $button was held”, isStateChange: true)
}