Detecting ground on GPIO and protect from positive voltage
Why can't you just clamp the input and put a high resistance to keep the input current low, like this simple circuit?







simulate this circuit &ndash; Schematic created using CircuitLab

With 30V input, the resistor sees about 25V across it. 25V / 10k = 2.5 mA. Pretty small. Power dissipated would be 25^2 / 10k = 0.0625 Watts, quite small.

The GPIO input of most MCUs are CMOS so current is ideally 0. Realistically most datasheets will spec maybe 100 nA, so 10k would be low enough to certainly detect the logic state at the input.

The zener would also protect from user accidentally injecting negative voltage as well as ESD strikes.