A few pages back, something similar of my own : http://forums.androidcentral.com/android-apps/151247-llama-who-s-using-any-good-examples-24.html#post3648157
Made a few changes to improve it, I added battery conditions, I changed 10s to 1mn for wifi off action, added a variable for battery low...