This is an example of using ProntoScript to track the state of a device and then take action conditionally based upon the device state. It is good when discrete commands are not available. There is a write up that will walk the beginner through implementation.