Tri-state simulated button with changeable text


#1

I want to be able to set a “mode” within WC by pushing a simulated button in the ST app. Within WC I’d like to be able to react to that button being pushed, and I’d also like to change the text seen in the ST app for the button. Something like it says “AUTO”, then if pushed it says “ON”, then if pushed again it says “MANUAL”. I’d also want to use the current text as an attribute I can see in WC for creating conditions/triggers.

I actually don’t care if it’s a simulated button. Just something that let’s me change the “mode” from the ST app, to see the current mode from the ST app, and react to changes and see the current “mode” from within WC pistons. Is there something like this, or any suggestions?

FWIW, for a two state scenario, a simulated switch is fine (even though I can’t change the text, since the name/label of the button with ON & OFF has been ok so far.) But I don’t know how to extend this to three or more states.


#2

With some minor tweaking, this should do the trick…


#3

Thanks. But I was hoping not to have to do any DTH coding. I can eventually if I have to, but I was hoping there might be a “standard” multi-state control device I could just drop in, maybe configure in the ST app, then just use from WC. :slight_smile: Or maybe my blinders weren’t letting me see another obvious way to achieve the ultimate goal using standard things.


#4

Tell me what buttons and symbols you want (4 modes) and I’ll re-code the DTH for you.


#5

Thanks. Assuming I use this, I’m sure I can do that myself. You code is very small and easily understandable, even if I don’t fully understand everything behind/underneath it. :slight_smile:


#6

I just knocked up the following DTH and piston which will toggle through modes with a momentary press and keep in sync with mode changes from elsewhere.

metadata {
	definition (name: "Mode Switch Tile", namespace: "smartthings", author: "Robin") {
		capability "Actuator"
		capability "Switch"
		capability "Momentary"
		capability "Sensor"
        attribute "Value1","string"
        command "changeValue1"
	}
	tiles(scale: 2){
		multiAttributeTile(name:"switch", type: "generic", width: 6, height: 4, canChangeIcon: true){
			tileAttribute("device.switch", key: "PRIMARY_CONTROL") {
				attributeState("off", label: 'Push', action: "momentary.push", backgroundColor: "#ffffff", nextState: "on")
				attributeState("on", label: 'Push', action: "momentary.push", backgroundColor: "#00a0dc")
			}	
		}
        valueTile("Value1", "device.Value1", width: 6, height: 2, canChangeBackground: true) {
 			state "default", label:'${currentValue}'
 		}
		main "switch"
		details "switch","Value1"
	}
}
def push() {
	sendEvent(name: "switch", value: "on", isStateChange: true, displayed: false)
	sendEvent(name: "switch", value: "off", isStateChange: true, displayed: false)
	sendEvent(name: "momentary", value: "pushed", isStateChange: true)
}
def on() {
	push()
}
def off() {
	push()
}
 def changeValue1 (param1) {
    sendEvent("name":"Value1", "value":param1)
}