I'm not 100% sure, but I seem to remember someone saying that http://geck.gamesas.com/index.php/GetDetectionLevel only works in combat? I know that it can be used from the console, where it returns two numbers, http://geck.gamesas.com/index.php/Category:Detection and light level, regardless of combat or no combat, but that does not help you much. In my security overhaul, I ended up using http://geck.gamesas.com/index.php/GetDetected, even though it does not return the nuances of the HUD.
It is possible, however, that you could make a hack to get most of the results from the HUD: Danger is when the PC is detected by someone that wants to attack the PC (http://geck.gamesas.com/index.php/GetDetected+http://geck.gamesas.com/index.php/IsInCombat+http://geck.gamesas.com/index.php/GetCombatTarget==PC) and Hidden when the PC is undetected. The Caution setting is somewhat more difficult. http://geck.gamesas.com/index.php/GetAlarmed could be useful?