OH on Raspi - how to restart after having been shut down (by a UPS)? [SOLVED]

I needed a solution for the following scenario: My NAS (QNAP) as well as my OH3-server (Raspberry 4B) are powered by an UPS (uninterruptable power supply, PowerWalker Basic VI 650 SB) to avoid uncontrolled shutdown and data loss when there is a power outage.
The NAS is connected via USB to the UPS and will be shutdown after 30 mins of power outage.
The NAS serves as Master in a NUT environment and will send a “power failure” message via LAN to the openHAB Raspberry.
How te set up the Raspi as “NUT slave” is very well documented in this topic: Guide to Network UPS Tools (NUT) on multiple Raspberry PI’s (Openhab 2.5 and other systems
What to observe to receive the message from the QNAP NAS master is documented here.

Now my challenge: If the power outage exceeds 30 mins, the UPS will send a shutdown command to the NAS (and this to the Raspi) which works well. After power is restored, both should be restarted remotely.
For the NAS, this can be done by connecting to my local network via VPN and sending a WakeOnLAN command - works well.
In another forum I found it mentioned to connect the Raspi to the USB of another device to get it started when this device is powered up. As the 4B needs a 3A USB supply, the USB from the NAS would be overloaded. The other method known is to shorten Pin5 of the GPIO to Ground.
So I constructed a very simple cicuit which is connected to the Gnd/5V wires of an USB connector at the NAS and will shorten Pin 5 of the Raspi to Gnd once the USB Voltage is applied - which happens when the UPS is restarted via WakeOn LAN.
Attached is the schematic - the component values are not very critical, but the transistor should be a medium/high gain type (beta~150+).
Of course this restarting of a Raspi which has been shutdown will work with any remote controlled device having an USB output.


Thank you for a good writeup, is there a way to even make it possible to shutdown the RPI when the 5 vilt is lost? I work in a project where rpis are mounted in busses and I have not yet tested to make a toggle function to boot rpi when ignition is on and shutdown when ignition is off.

There is goio pin for shutdown, but this was a neat finction.

Hi Magnus,
to solve your requirement for shutdown of the Pi when USB voltage goes to zero:
You would have to use a similar circuit like above, but for Q1 you would need a self-conducting (depletion mode) FET - so it will pull down (shorten to ground) the Raspi GPIO pin if the Gate voltage from the USB power is zero. A suitable type could be e.g. BSS159N.