Motion activated light only if light is already off?

Ok, so I managed to play with it a bit the other night. The good news is that I got something working - wrote a whole SmartApp that includes creating virtual devices and connecting to actual switch and to motion sensor and runs timers for auto-off, etc. (I realize much of this is duplicate of existing functionality, but I did it mostly to understand how this works) Overall its pretty cool to be able to write things in Groovy - but I got a number of questions due to somewhat lacking documentation. Specifically things like:

I found the way to create devices from app using the semi-undocumented addChildDevice() method (it is mentioned in documentation examples, but not in the reference page for methods available to SmartApps) - I was wondering if there was more documentation on this and if there is a way to create other components programmatically - specifically if there is a way to create “switch” apps (not sure if they are apps or devices or neither)? There is nothing in documentation (but then again, addChildDevice is missing too) and simple attempts to check what methods are available via reflection seem to have been disabled for security reasons. (So, is there a functional way to dump all the available methods?)

Also, it seems that there is some weird bug in the apps I am hitting that does not allow me to delete my custom smart app instances. I get errors. I found that if I delete the section of the code in update() that re-subscribe to the events and then update the app before deleting it, it works. It seems the issue is some dependency loop in creating child devices and subscribing to their events and then order of deletion of said subscriptions and child devices. (and yes, I tried an extra unsubscribe right before the code that deletes the child device, but delete still fails) Again, more documentation on lifecycle of SmartApp and child device creation would be ideal.

Next, I am trying to understand if there is a way to change state of a “switch” device without triggering events. More specifically I am trying to figure out a way to both control an actual (non-virtual) switch device AND react to that switch being controlled via means outside this smartapp. I realize the frequent way of using this is via a proxy virtual switch, however this is a problem if the light in question is controlled by the physical switch itself or a secondary controller that bypasses the ST hub altogether. Is there information on which smartapp triggered an even inside the event?

Lastly, and this is something I thought would be obvious but i find no way to do this - is there a way to provide default value for input fields in preferences?

Thanks,

-M