Consider implementing PSON and PSOFF functions using a relay/SSR. This way you begin a print with M80 in your start Gcode this connects the mains (the duet is being powered from a USB 5v supply). Then you print. In the end gcode you shut off the bed heater, and set to cool the hotend to below glass transition temp for any filament so 50 deg C, and wait for temps M116. Then you send M81 - machine turns off. But duet is still active.
Its not all gravy, if you have to hit the software stop button, it automatically disconnects the mains power, so fans turn off including hotend, and it takes about 20-30 seconds to reboot and for them to come back on, which might lead to heat creep and a jam.