How does the Pi know it being underpowered and to show the lighting bolt?
As most of us know, if you use a bad power supply you get the lightning bolt telling you are underpowered.
I noticed that when I run my Pi on battery, the last 15 minutes or so before the Pi starts to reboot, the lightning bolt starts appearing, and eventually stays there until the reboots, which makes sense because my battery voltage is dropping as it is drained.
This got me thinking I could use this to make a program that turns the Pi off when it detects constant under-voltage. I know before this happened would be even better but I am not concerned about that.
Is there a command for voltage like
sudo vcgenmd measure_temp for temperature to know what the voltage is? If not how does the Pi know when it is being underpowered?
EDIT: This is not a duplicate because the other question suggests you need external hardware. I am pointing out this is not strictly necessary.