How to change the state of a tile?

(Simeon Simeonov) #1
    attribute "tamper" , "string"

	standardTile("tamper", "device.tamper", inactiveLabel: false, width: 3, height: 3) {
    	state "NO", label:'No Tamper', action:"refresh.refresh", backgroundColor:"#B1D57D"
	    state "YES", label:'${currentValue}', action:"refresh.refresh", backgroundColor:"#FFCC7B"

When a tamper occurs:

     def time = new Date().format("hh:mm:ss", location.timeZone)
	 result << createEvent(name: "tamper", value: "Tampered \n${time}")
     sendEvent (name: "tamper", value: "YES", isStateChange: true) //my desperate try

And when the tile is pressed:
def refresh() { sendEvent(name: "tamper", value: "NO", displayed: false) }

I fail to turn the tile to state “YES” showing the time. I don’t know if I should use sendEvent or createEvent and my confusion is: To pass a value to the tile, I need to use the “value”, but also “value” is used to switch the state of the tile.

Where is my stupid mistake?

( co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

createEvent just returns a Event object. It doesn’t fire it. (The parse method of a DTH fires the Event of its return command).

So sendEvent() is the correct method to call.

I’m not sure at a glance why the code isn’t working, but it’s helpful to look at the docs and several simple examples from the SmartThings GitHub.

There are quirks.

Try, for example, using just “tamper” rather than “device.tamper” in the Tile definition. It might work.

(Simeon Simeonov) #3

When I change the line:

 sendEvent (name: "tamper", value: "YES", isStateChange: true)


cmd << sendEvent (name: “tamper”, value: “YES”, isStateChange: true)


result << sendEvent (name: “tamper”, value: “YES”, isStateChange: true)

the tile change its status, but its value is “YES”, instead of ‘${currentValue}’

Any ideas? Is it even possible to have such functionality - where a tile has multiple states and one of them is holding the variable ‘${currentValue}’ ?

@doncaruana, help :slight_smile:

( co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #4

I’m confused…

After running sendEvent (name: "tamper", value: "YES", isStateChange: true) … the $currentValue is "YES"… you have just SET the value to "YES"…!!!

(Jim Anderson) #5

It looks like you’re trying to display the value of an attribute, which may change. standardTile is not suited for this - as stated in the docs, “Use a Standard Tile for attributes that have discrete, specific values.”

What you probably want is a valueTile(), which as the documentation states, “Use a Value Tile for attributes that have non-discrete values. Typical examples include temperature, humidity, or power values.”

(Simeon Simeonov) #6


The “problem” is that when I use “valueTile”, the tile is not active. The “action:“refresh.refresh”” does nothing.

I want to use non-discrete value on an active tile. And it actually worked to some extent.

standardTile("tamper", "device.tamper", inactiveLabel: false, width: 3, height: 3) {
			state "tamper", label:'${currentValue}', action:"refresh.refresh", backgroundColor:"#FFCC7B" 

does the job, but I want to use different background colours for two different tile’s values.
I assume that this is not possible ?

(Jim Anderson) #7

Did you try this?

(Simeon Simeonov) #8

Yes, but the tile’s values in my case are not integers and the device handler does event even run (showing the error "Sorry, but there was an unexpected error.)