Here is what I did. I have a mushroom button type of E Stop button, that is a single normally closed switch. I have a relay that is controlled by the Atx on /off in DWC.
I used e1stop pin to act as a trigger. I do not use the M112 command., I use the M999 command.
Here is the entry in the config.g file
M81 C"pson" ; allocate the PS_ON pin to power control but leave power off
M950 J1 C"^e1stop" ; Assign Pin1 to e1stop the terminals on the E stop switch is wired to the GND and E1 stop pin on the Duet board
M581 P1 T10 S1 R0 ; Enable Emergency Stop
M582 T10 ; when triggered run trigger10.g

Here is the contents of the trigger file.;testing the trigger system
M81 ; SHUT THE POWER OFF
M291 P"E STOP ACTIVATED" S1 T5 ;Lets me know something happened
G4 S2 ;This give the power supply time to drop and stops the error messages as the VIN drops
M999 ; reboots the duet board
;END
It stays in a loop until the E stop switch is reset. Hope this helps.