Shutting down printer after print

So I have a TP link plug set up with my pi called pi

I have added the code in this link to my idle and end print

It doesn’t seem to work consistently, any suggestions?

My advice, don’t use it. When the first devices came up, I was playing a lot with those. You always get different results, when changing the electricity plugs in a house or changing houses. If you really want to use it, check the network for QoS. There are a lot of test tools in the www.

See Shutdown on Thermal Runaway

This is the actual code
[idle_timeout]
gcode:
M84
TURN_OFF_HEATERS
{% if printer[“gcode_macro TURNOFF_CHANGE”].turnoff|int > 0 %}
TEMPERATURE_WAIT SENSOR=extruder MAXIMUM=40 #Don’t switch off when hot
SEND_POWER_OFF
SHUTDOWN_MACHINE
{% endif %}

[gcode_macro TURNOFF_CHANGE]
variable_turnoff=0
gcode:
SET_GCODE_VARIABLE MACRO=TURNOFF_CHANGE VARIABLE=turnoff VALUE={params.S|default(1)|int}

[gcode_macro POWER_OFF_PI]
gcode:
TURNOFF_CHANGE S=1
set_idle_timeout timeout=10 #call idle_timeout after 10 seconds

[gcode_macro SHUTDOWN_MACHINE]
gcode:
{action_call_remote_method(“shutdown_machine”)}

{action_call_remote_method(“set_device_power”, device=“pi”, state=“off”)}

and in END_PRINT

[gcode_macro END_PRINT]
gcode:
# Turn off bed, extruder, and fan
M140 S0
M104 S0
M106 S0
# Move nozzle away from print while retracting
G91
G1 X-2 Y-2 E-3 F300
# Raise nozzle by 10mm
G1 Z10 F3000
G90
G1 X0 Y200 ;Present print
# Disable steppers
M84
{% if printer[“gcode_macro TURNOFF_CHANGE”].turnoff|int > 0 %}
POWER_OFF_PI
{% endif %}

A great option if you have a decent home automation hub, like Hubitat which has a Klipper / moonraker integration, is to automate a Zigbee or zwave smart plug.

Eg I have a rule for my AD3 like this:

And you can also setup push notifications or Alexa TTS notifications. I use this notifications rule for my MZ1: