Change the button color when it is pressed in the device handler?

Hi Folks,

I am new to Smarthings IDE and looking for help to change the tile colors when it is pressed (or maybe showing a visual effect that it is pressed). I have a motor control and 3 buttons : Up, down and Stop

Another question, is there a way for a tile to change color based on the dynamic state or it is only through Smartapp
I mean to have a standard tile that shows the status of the motor whatever I press out of the 3 buttons.

Thanks.

A tile definition usually references one of the device handler’s attributes and includes a line for all the states that attribute can have. The attributes are usually defined by the capabilities that the device handler supports.

For example, the “Switch” capability has the “switch” attribute and you can have a different color and text based on its states “on” and “off”.

See the documentation for detailed information on how to actually implement that:
http://docs.smartthings.com/en/latest/device-type-developers-guide/tiles-metadata.html

1 Like

Also note the nextState attribute. The dev docs don’t say much about it. To illustrate the use, think of a dimmer.

When you tap the tile to turn on the dimmer, it will take a few seconds to ramp up, and the DH will wait a few seconds before asking the physical device for its status, then the physical device will send a message to the hub that it is ON. The DH parses the message from the physical device and creates an event to notify ST that the dimmer is ON.

At this point, the UI will change the tile to the ON state. BUT, that means waiting about 5 seconds to see the UI respond to the aforementioned tap.

To make the UI more responsive, nextState allows the state of the tile to change without an actual change in state of “switch”. A dimmer DH will usually have two virtual tile states, “turningOn” and “turningOff” in addition to “on” and “off” states.

For example:

standardTile("switch", "device.switch", width: 2, height: 2) {

//shown when state = "on", green tile, when tapped, calls off() and shows the tile for the virtual state "turningOff"
state "on", label:'${name}', action:"switch.off", backgroundColor:"#79b821", nextState:"turningOff"

//shown when state = "off", white tile, when tapped, calls on() and shows the tile for the virtual state "turningOn"
state "off", label:'${name}', action:"switch.on", backgroundColor:"#ffffff", nextState:"turningOn"

//shown when a tile with nextState:"turningOn" is tapped, green tile
state "turningOn", label:'${name}', action:"switch.off", backgroundColor:"#79b821", nextState:"turningOff"

//shown when a tile with nextState:"turningOff" is tapped, white tile
state "turningOff", label:'${name}', action:"switch.on", backgroundColor:"#ffffff", nextState:"turningOn"

}

So, when state “off” tile is tapped, the state “turningOn” tile will be shown even though the state of “switch” is still “off” (for the subsequent 5 seconds)

2 Likes

Thanks Geroge, the nextState was very helpful

2 Likes