Creative stay awake/sleep solution I came up with using a PMU

Not sure this would work on anything else but this is my solution and it seems to work on my bench.

I wanted to find a way to not have to start and stop my Pi every time I turn my car off and wanted to give a bit of a delay in case I stop to get gas or something.

I’m using a ECUMaster PMU24-DL for my car so this is what I came up with instead of using a 3rd party module.

The big key here is that I’m not using the actual key switch on the PMU. I have one wired up but I’m using a logical switch on an analog input instead. The PMU doesn’t pull much power at all when sitting idle and I have a separate switch wired up for killing power to it when I’m parking for a while.

Ok - so I have a logical switch on analog 2. When it goes active-low I start 2 timers for 19 and 20 minutes respectively. I transmit the button state and the 19 minute timer data. The button state raises the timer to visible. When the timer.elapsed hits the ‘1’ state I have a global action for a terminal command that sends ‘sudo shutdown -h now’ (passwordless sudo permission for that command). When the 20 minute timer hits I have a function that turns off everything on the PMU but the switch.

If I turn the switch back on during that 19 minutes it stops the timer and resets it.

Up next I’m going to make a button the touchscreen to send a CAN message that lets me reset the timer for another 19 minutes.

Not sure if this is helpful to anybody else but seems to fit my needs.