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")}

[gcode_macro SEND_POWER_OFF]:
gcode:
  {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:


@doormat1
Hello. I am working on klipper firmware for my printer. I want my printer will automatic shutdown after completing the print. I didnt get any information regarding this on the internet. I do not want to use any device e.g TPLink devices or Tsamota Devices for this. I need any programm or macro for this so that the printer will shutdown directly.

i have come through your programm but i am not understanding it weather it will work directly writing it in printer.cfg.
Please help.

[idle_timeout]
gcode:
{% if printer.pause_resume.is_paused %}
{% set TARGET_TEMP = params.TARGET | default(220) | float %}
SET_GCODE_VARIABLE MACRO=IDLE_TIMEOUT VARIABLE=temp_target VALUE={ TARGET_TEMP }
M117 Idle but paused, maintaining bed temp.
SET_HEATER_TEMPERATURE HEATER=extruder TARGET=0
{% else %}
M118 IDLE_TRIGGERED
M84
TURN_OFF_HEATERS
TEMPERATURE_WAIT SENSOR=extruder MAXIMUM=40 #Don't switch off when hot
POWER_OFF_PRINTER
SEND_POWER_OFF

{% endif %}
SHUTDOWN_MACHINE

[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")}

[gcode_macro SEND_POWER_OFF]:
gcode:
M118 Turning_power_off
{action_call_remote_method("set_device_power", device="pi", state="off")}

[delayed_gcode bed_safety]
initial_duration: 2.
gcode:
{% if printer.heater_bed.temperature >= settings.heater_bed.max_temp %}
M118 EXCEED_THERMAL_LIMIT_BED
POWER_OFF_PRINTER
{% else %}
UPDATE_DELAYED_GCODE ID=bed_safety DURATION=2
{% endif %}

[delayed_gcode extruder_safety]
initial_duration: 2.
gcode:
{% if printer.extruder0.temperature >= settings.extruder.max_temp %}
M118 EXCEED_THERMAL_LIMIT_EXTRUDER
POWER_OFF_PRINTER
{% else %}
UPDATE_DELAYED_GCODE ID=extruder_safety DURATION=2
{% endif %}

[gcode_macro END_PRINT]
gcode:
M117 Print Finished
M118 PRINT_FINISHED
# 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 %}

These are by my macros directly from my printer.cfg

@doormat1 :
Please, when you upload code as text and not as file, use the Preformatted Text feature of the forum editor. Else the upload is useless because characters and spaces are deleted.

Format

1 Like
[delayed_gcode bed_safety]
initial_duration: 2.
gcode:
  {% if printer.heater_bed.temperature >= settings.heater_bed.max_temp %}
    M118 EXCEED_THERMAL_LIMIT_BED
    POWER_OFF_PRINTER
  {% else %}
    UPDATE_DELAYED_GCODE ID=bed_safety DURATION=2
  {% endif %}

[delayed_gcode extruder_safety]
initial_duration: 2.
gcode:
  {% if printer.extruder0.temperature >= settings.extruder.max_temp %}
    M118 EXCEED_THERMAL_LIMIT_EXTRUDER
    POWER_OFF_PRINTER
  {% else %}
    UPDATE_DELAYED_GCODE ID=extruder_safety DURATION=2
  {% endif %}


[gcode_macro END_PRINT]
gcode:
    M117 Print Finished
    M118 PRINT_FINISHED
    # 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 %}
1 Like

Could you do that for your previous post too? Thank you.

Its the same code I think

Not quite.
The previous post has some lines before

BTW: You could have edited that post instead of posting it anew…

I’ve edited my first post, hope it helps

Actually I meant post #7

@doormat1 Thank you for taking your valuable time to reply.

I tried your given code. I write it down in my printer.cfg as it is. As i save and restart it i got the error. Kindly check and suggest what should be done next.
I just Copy paste the error here in the quote. i am trying to put the screen shot of the error but it is showing some error in uploading it.

"Klipper reports: SHUTDOWN

Shutdown due to required printer.cfg section(s) missing: Missing _KM_IDLE_TIMEOUT in gcode for [idle_timeout] section. See readme: GitHub - jschuh/klipper-macros: A collection of useful macros for the Klipper 3D printer firmware Once the underlying issue is corrected, use the “FIRMWARE_RESTART” command to reset the firmware, reload the config, and restart the host software. Printer is shutdown


RESTARTFIRMWARE RESTART"

KLIPPER LOGMOONRAKER LOG