The following explains how the power circuitry of modern Pi (with 40 pin header) works [Raspberry Pi Power Limitations](http://raspberrypi.stackexchange.com/questions/51615/raspberry-pi-power-limitations). The lightning bolt is controlled by the kernel, and AFAIK there is no simple way to access it. The power state can be detected more easily. This is directly available through the system in B+ Pi2 `/sys/class/led1`, and accessible through a program on Pi3 http://raspberrypi.stackexchange.com/a/60275/8697