GCode Safe Shutdown


I have my printer connected through a Tasmota smart plug and want to setup a macro that safely turns off the printer (trigger Tasmota off with delay, then shutdown the PI).

I tried all different options without success:
MQTT Plugin: If I'm not mistaken there's no way to send a mqtt message without furhter plugins?
MQTT Publish & GCODE System Commands: System Command for PI Shutdown works. The spaces in the message break the MQTT message. I can't figure out a syntax with quotes or braces to fix it: @MQTTPublish tasmota/cmnd/BACKLOG Delay 50; Power OFF
Tasmota Plugin: Triggering the switch works here but the system ignores the system command: sudo shutdown -h now. Also the delays are not properly processed, if I set the shutdown timer to 60 s it still shuts down much quicker.

How did you guys solve this?