To monitor my mobile home I use a Pi Zero W with GPS, UMTS and a UPS with an additional Lithium ions battery.
The Pi is connected to the battery via a solid state relay.
This means that the relay needs a short voltage pulse to switch on and off (Relais has two coils one for on and one for off).
The power-on switch is operated manually. The power-off impulse should come from the pi itself (one of its GPIOs).
(The pi is measuring the voltage of the car and the lion battery and can detect when the battery has low voltage and it's time to power off.)
Now my question:
How can I proceed in order to switch off the Pi as gently as possible?
This means stopping as many processes as possible and protecting the file system from corruption before setting the appropriate GPIO, which will stop the disconnecting of the voltage. (root-fs is on sdcard)
It would be best to be able to set the GPIO directly before the message "System halted".
When is the last change to access the GPIOs?