So, no real fix from sixfab, so I came up with something that does the trick.
My solution is to simulate a button press when power comes on with hardware using a 555 timer IC. This works for me, it may work for you, but use it at your own risk.
The circuit operates by sensing voltage on the power source and uses a mosfet to simulate a quick press on the button. Since the ‘short press’ has no effect when the system is already on, power can be applied/removed in cases where the normal safe shutdown (battery level) is being used. I do not use it in this way.
I added some code to read_sensors.py that responds to the battery state and initiates a shutdown. To boot from a hard shutdown, use S1, from soft shutdown, use S2.
To run the read_sensor.py script at boot up, add:
@/home/pi/startup.sh
to the end of:
/etc/xdg/lxsession/LXDE-pi/autostart
and place the startup.sh file in the appropriate place. It will run:
x-terminal-emulator -e ‘cd /home/pi/Gits/sixfab-power-python-api/ && watch python3 ./example/read_sensors.py’
to launch a window at startup to monitor the operating mode It monitors system input power, since during high power usage, it will be in BATTERY_POWERED even when plugged in.
(This would be more correctly described as ‘BATTERY_DISCHARGING’)
The schematic, cnc, and all the needed files can be obtained from my git: