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)