Maybe
[delayed_gcode shutdown_machine]
gcode:
{action_call_remote_method("shutdown_machine")}
initial_duration: 0.0
[menu __main __poweroff]
type: command
enable: {printer.idle_timeout.state != "Printing"}
name: Turn off Pi
gcode:
M117 Shutdown_RPI
M118 Shutdown_RPI
{ menu.exit() }
UPDATE_DELAYED_GCODE ID=shutdown_machine DURATION=1