Grab the IP address for your EZPlug that you want to use with the Klipper printer and put its IP address in below replacing 1.1.1.1 with your plugs IP.
This code goes at the END of your moonraker.cfg file:
[power EZPlug]
type: tasmota
address: 1.1.1.1
Save and restart to apply the changes.
Next, add the below code to your Printer.cfg file:
#EZPlug Stuff
[gcode_macro POWER_OFF_PRINTER]
gcode:
{action_call_remote_method("set_device_power",
device="EZPlug",
state="off")}
[gcode_macro POWER_ON_PRINTER]
gcode:
{action_call_remote_method("set_device_power",
device="EZPlug",
state="on")}
[delayed_gcode POWER_OFF_PRINTER_CHECK]
gcode:
{% if printer.idle_timeout.state == "Idle" or printer.idle_timeout.state == "Ready" %}
{% if printer.extruder.temperature < 50.0 and printer.heater_bed.temperature < 50.0 %}
{% if printer.extruder.target == 0.0 and printer.heater_bed.target == 0.0 %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=0
POWER_OFF_PRINTER
{% else %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=2
{% endif %}
{% else %}
{% if printer.idle_timeout.state == "Printing" %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=0
{% else %}
{% if printer.extruder.target == 0.0 and printer.heater_bed.target == 0.0 %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=2
{% else %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=0
{% endif %}
{% endif %}
{% endif %}
{% endif %}
[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
# Disable steppers
M84
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=30
[gcode_macro ACTIVATE_POWER_OFF]
gcode:
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK_ACT DURATION=60
[gcode_macro DEACTIVATE_POWER_OFF]
gcode:
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK_ACT DURATION=0
[delayed_gcode POWER_OFF_PRINTER_CHECK_ACT]
gcode:
{% if printer.idle_timeout.state == "Idle" or printer.idle_timeout.state == "Ready" %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK DURATION=30
{% else %}
UPDATE_DELAYED_GCODE ID=POWER_OFF_PRINTER_CHECK_ACT DURATION=60
{% endif %}
#End EZPlug Stuff
Now save and restart. You will have multiple printer macros to control the plug. Please note that this will also auto shut down the printer after the printer is idle and all temps are below 50C.