Added further support for Custom Commands

* On Init
* On Wake
* On Sleep
Refactored some code to handle all state changes in one location