Changing the state and background of a standard tile when another is pressed?

I could use a little help here. I using a Arduino smartthings shield in order to control some LED strips. I have some tiles set up for a few colors along with an on/off tile.

At first I just set up the tiles with a basic background and no states.

Now Each tile for each color has an on state and an off state. Where the on state shows the color of the LED Strip and off is a bare white background on the tile. The issue I have is that lets say I press the blue tile, it turns on and in the app the tile is blue then turns off and app background is white. However if I press the blue then say pink tile the blue tile still remains blue instead of going to white and of course the pink tile is now pink as it should be. The actual strip is working like I want it changing directly to pink but I only want the On/Off switch and the current color to have the proper background. I hope this makes sense to someone. I am not very good at explaining.

I think I followed you, and I believe what you want to do is use sendEvent. I do that for some of my DH’s where I want a tile to update. Here’s some of my examples of formatting:

Here’s the tile I set:

	standardTile("waterState", "device.waterState", width: 3, height: 2, canChangeIcon: true, canChangeBackground: true, decoration: "flat") {
		state "none", icon:"http://cdn.device-icons.smartthings.com/alarm/water/wet@2x.png", backgroundColor:"#cccccc", label: "None"
		state "flow", icon:"http://cdn.device-icons.smartthings.com/alarm/water/wet@2x.png", backgroundColor:"#01AAE8", label: "Flow"
		state "overflow", icon:"http://cdn.device-icons.smartthings.com/alarm/water/wet@2x.png", backgroundColor:"#ff0000", label: "High"
	}

Here’s some code on how I use sendEvent for that tile:

    	if (delta > gallonThreshhold) {
        	sendEvent(name: "waterState", value: "overflow")
    	} else {
    		sendEvent(name: "waterState", value: "flow")
	}

In your example, when you turn on the pink tile, send an event to do what you want for the blue tile.

1 Like

Not sure I understand where to put the second part of your code.
Here are three of my tiles. The on/off works as I want it. changing states for on/off.

standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) {
	state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"off"
	state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"on"
	}
            
standardTile("Blue", "device.blue", height:1, width:1) {
    	state "off", label: 'Blue', action: "blue", icon: "st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState:"blue"
        state "blue", label:'Blue', action:"switch.off", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#0276FD", nextState:"off"   
    } 
	
standardTile("Pink", "device.pink", height:1, width:1) {
    	state "off", label: 'Pink', action: "pink", icon: "st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState:"pink"
        state "pink", label:'Pink', action:"switch.off", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#f934f3", nextState:"off"   
    } 		

so where do I put the send event. in the arduino code, in the commands sent to device?

You’d put that code (sendEvent) where you turn on or manage each color. What you’d do is send an “off” for all other colors.

In your example above, after executing “pink” you should use sendEvent to send off to all other color tiles. What I’d do, which may not be best coding practice, is to have each color have it’s own on and off - blueOn, blueOff, etc. instead of having “off” for each color. It can be done that way I’m sure, but offhand I’m not sure what the sendEvent statement would look like. In other words, after turning on pink, you’d have sendEvent commands like this:

sendEvent(name: “blue”, value: “blueOff”)
sendEvent(name: “red”, value: “redOff”)
etc…

Make sense or did I confuse? What you want to do is possible. Perhaps you can share more of your code? Unfortunately I’m going to be away from the community until tomorrow, but I can follow up then.

Here is my code for the device handler. I tried putting the send event in a few places and couldnt get it to work.

As of right now only pink and blue have two states, the other colors will come when I figure out how to change their background based on another tile press.

		capability "Actuator"
	capability "Switch"
	capability "Switch Level"
            capability "Sensor"
   attribute "whitestate", "string" 
   command "blue"
   command "pink"
   command "red"
   command "green"
   command "orange"
   command "yellow"
   command "purple"
   command "skyblue"
   command "rainbow"
   command "white1"
   command "white2"
   command "white3"
   command "white4"
}

// Simulator metadata
simulator {
	status "on":  "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
	status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"

	// reply messages
	reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
	reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
}

// UI tile definitions
tiles {
	standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true, canChangeBackground: true) {
		state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821", nextState:"off"
		state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff", nextState:"on"
	}
            
    standardTile("Blue", "device.switch.blue", height:1, width:1) {
    	state "off", label: 'Blue', action: "blue", icon: "st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState:"blue"
        state "blue", label:'Blue', action:"off", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#0276FD", nextState:"off"   
    } 
    
    standardTile("Pink", "device.pink", height:1, width:1) {
    	state "off", label: 'Pink', action: "pink", icon: "st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState:"pink"
        state "pink", label:'Pink', action:"off", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#f934f3", nextState:"off"
    } 
    
    standardTile("Red", "device.red", height:1, width:1) {
        state "red", label:'Red', action:"red", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ff0000"
    } 
    standardTile("Green", "device.green", height:1, width:1) {
        state "green", label:'Green', action:"green", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#00ff00"
    } 
   standardTile("Orange", "device.orange", height:1, width:1) {
        state "orange", label:'Orange', action:"orange", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ff9900"
    }
    standardTile("Yellow", "device.yellow", height:1, width:1) {
        state "yellow", label:'Yellow', action:"yellow", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffff00"
    }
    standardTile("Purple", "device.purple", height:1, width:1) {
        state "purple", label:'Purple', action:"purple", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#660066"
    }
    standardTile("Skyblue", "device.skyblue", height:1, width:1) {
        state "skyblue", label:'Skyblue', action:"skyblue", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#00ccff"
    }
    standardTile("Rainbow", "device.rainbow", height:1, width:1) {
        state "rainbow", label:'Rainbow', action:"rainbow", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#9966ff"
    }
    standardTile("White", "device.whitestate", height:1, width:1) {
        state "1", label:'White', action:"white1", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState: "2"
        state "2", label:'White 1', action:"white2", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState: "3"
        state "3", label:'White 2', action:"white3", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState: "4"
        state "4", label:'White 3', action:"white4", unit:"", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff", nextState: "1"           
    }    
    

	main "switch"
	details ("switch","Blue","Pink","Red","Green","Orange","Yellow","Purple","Skyblue","Rainbow","White")
}
}

// Parse incoming device messages to generate events
def parse(String description) {
	def value = zigbee.parse(description)?.text
	def name = value in ["on","off"] ? "switch" : null
	def result = createEvent(name: name, value: value)
	log.debug "Parse returned ${result?.descriptionText}"
	return result
}

// Commands sent to the device
def on() {
	zigbee.smartShield(text: "on").format()
}

def off() {
	zigbee.smartShield(text: "off").format()
}

def blue() {
	zigbee.smartShield(text: "blue").format()
}
def pink() {
	zigbee.smartShield(text: "pink").format()
}
def red() {
	zigbee.smartShield(text: "red").format()
}
def green() {
	zigbee.smartShield(text: "green").format()
}
def orange() {
	zigbee.smartShield(text: "orange").format()
}
def yellow() {
	zigbee.smartShield(text: "yellow").format()
}
def purple() {
	zigbee.smartShield(text: "purple").format()
}
def skyblue() {
	zigbee.smartShield(text: "skyblue").format()
}
def rainbow() {
	zigbee.smartShield(text: "rainbow").format()
}
def white1() {
	zigbee.smartShield(text: "white1").format()
}
def white2() {
	zigbee.smartShield(text: "white2").format()
}
def white3() {
	zigbee.smartShield(text: "white3").format()
}
def white4() {
	zigbee.smartShield(text: "white4").format()
}

I also did what you said and changed my code a bit using blueoff etc, I thought I had it working at one point but it didnt. I put the sendEvent in the def in smartthings groovy file and I tried smartthing.send(“blueoff”); in the arduino code. Nothing so far seems to be working.