Shutdown on Thermal Runaway

I’ve been using octoprint for ages and have recently switched mainsail/moonraker. In Octoprint I used the tp smart link app to set my printer to switch off if there was thermal runaway as it was on a separate smartplug to my pi. Can I do this with klipper?

See Configuration reference - Klipper documentation and Configuration - Moonraker → search for TPLink Smartplug Configuration and Reboot / Shutdown from Klipper

inside moonraker.conf

[power {NAME_FOR_PLUG_DEVICE}]
type: tplink_smartplug
address: {IP_OF_PLUG}
off_when_shutdown: True
locked_while_printing: False
restart_klipper_when_powered: True
on_when_job_queued: True
restart_delay: 3

inside printer.cfg

[gcode_macro POWER_ON_PRINTER]
gcode:
  {action_call_remote_method("set_device_power",
                             device="{NAME_FOR_PLUG_DEVICE}",
                             state="on")}

[gcode_macro POWER_OFF_PRINTER]
gcode:
  {action_call_remote_method("set_device_power",
                             device="{NAME_FOR_PLUG_DEVICE}",
                             state="off")}

and then these for runaway

[respond]

[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 %}

Those two macros should trigger when we go past the defined maxes for the heaters, and a message so you can debug when it happens

Someone can tell me I’m doing it wrong but this works for me

1 Like

This looks interesting and very useful but could you explain the moonraker.conf statements? I’m guessing there for a shutdown relay?

Also, what are the units of “initial_duration”/“DURATION” - are they seconds or minutes?

Detailed instructions are here

Since both I and the OP use a TPLink the device, that is why the type is set to tplink_smartplug

off_when_shutdown, powers off the plug when klipper enters a shutdown state (like turning off a Pi running klipper)

restart_klipper_when_powered, triggers a FIRMWARE_RESTART after the plug turns on, so the printer can connect to klipper on powerup.

on_when_job_queued allows power on from slicer and when prints are sent to klipper

restart_delay delays the restart in seconds, gives the mainboard of the printer a bit of time to get ready.

As for the delayed gcode

DURATION is in seconds, more info here

Thank you for the detailed reply.

Now, I’m guessing your rPi (or whatever system controller you’re using) is powered separately - correct?

It looks like you are also waiting for Klipper to connect with the controller board when you power up. It doesn’t look like there’s any timeout - so if there is no connection, things just wait indefinitely? How do you reset in this case?

Yes it is powered separately,

I open Fluidd in my case and monitor what is happening, once I send something from my slicer, the printer powers up and usually connects.

Sometimes I just do a firmware_restart and that sorts out any problems

1 Like

Nice write-up. :+1:
You could add this to the “Config” section as an own thread for later reference.

1 Like

One more thing, if you want to turn off the printer after idling for a bit you can like so

in printer.cfg or dedicated macro.cfg

[delayed_gcode delayed_printer_off]
initial_duration: 0.
gcode:
  {% if printer.idle_timeout.state == "Idle" %}
    POWER_OFF_PRINTER
  {% endif %}

[idle_timeout]
gcode:
  M84
  TURN_OFF_HEATERS
  UPDATE_DELAYED_GCODE ID=delayed_printer_off DURATION=60

two minutes of idle state powers off the printer

Thanks for the help. I’ve copied them into the right places and will let you know how I go

A little more searching found this on github - TPLink power off delay doesn't work correct · Issue #366 · Arksine/moonraker · GitHub
Not thermal runaway but adds to the idle macro