Configurator shots of my auto head light functions. If you want the xml code ask, but I think it is easier to follow here. The "2" is the light sensor value and the "100" is a countdown to delay turning them off. These numbers are placeholders until I play with the hardware for real. Averaging on the input will delay them turning on for brief shadows.
The third head_light variable is for an override off and on buttons in my Ride Runner skin.