# Octoprint Safe Shutdown

**URL:** <https://discourse.nodered.org/t/octoprint-safe-shutdown/64760>\
**Category:** General\
**Created:** [6 July 2022 10:12 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760 "2022-07-06T10:12:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheSirSpence](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thesirspence/32/64243_2.png) [@TheSirSpence](https://discourse.nodered.org/u/TheSirSpence)\
**Post date:** [6 July 2022 10:12 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/1 "2022-07-06T10:12:19Z")

</div>

Hi all,

I am trying to create a safe shutdown sequence for my Octoprint running on a seperate Pi3b.

I am using Node-Red inside home assistant and I have an entity called "button.octoprint\_shutdown\_system" with a resting status of unknown.

What I would like to happen is on a button press to shutdown Octoprint wait one minute and then turn off the smart switch.

I just cant figureout the first part so any help would be appreciated.

Thanks!

EDIT: flow below:

```auto
[{"id":"7375360fe34b709d","type":"stoptimer","z":"ee46ed1da81de40d","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"shut down delay timer","x":600,"y":220,"wires":[["8af7efb5cf340ff9"],[]]},{"id":"8af7efb5cf340ff9","type":"api-call-service","z":"ee46ed1da81de40d","name":"Printer Power Off","server":"ad021f45.a359d","version":5,"debugenabled":false,"domain":"switch","service":"turn_off","areaId":[],"deviceId":[],"entityId":["switch.tuya_emswitch_1_shark_3dp_unassigned"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":870,"y":200,"wires":[[]]},{"id":"943def59d1f310a1","type":"server-state-changed","z":"ee46ed1da81de40d","name":"Printer Power","server":"ad021f45.a359d","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_button.3d_printer","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":220,"wires":[[],["bb8be3b366bd40dd"]]},{"id":"bb8be3b366bd40dd","type":"api-call-service","z":"ee46ed1da81de40d","name":"Printer Power Off","server":"ad021f45.a359d","version":5,"debugenabled":false,"domain":"script","service":"toggle","areaId":[],"deviceId":[],"entityId":["button.octoprint_shutdown_system"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":350,"y":220,"wires":[["7375360fe34b709d"]]},{"id":"ad021f45.a359d","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

```

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [6 July 2022 10:31 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/2 "2022-07-06T10:31:09Z")

</div>

You might get more responses if you posted your question on the HA forum (as very few people use HA on this forum).

If you can share your Node-RED flow I'm sure people (including myself) will take a look at it and see if we can help.

---

<div class="post-metadata">

**Author:** ![TheSirSpence](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thesirspence/32/64243_2.png) [@TheSirSpence](https://discourse.nodered.org/u/TheSirSpence)\
**Post date:** [6 July 2022 10:45 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/3 "2022-07-06T10:45:02Z")

</div>

Thanks for replying Dave,

I didnt have much of a flow, as I can't get this node working. I have edited the initial post with the flow. 🙂

I will try the HA forums too, but as I am using Node-Red and not YAML I assumed this would be the best place.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2022 10:51 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/4 "2022-07-06T10:51:56Z")

</div>

If what you want to do is to send a message to shutdown Octoprint then wait one minute and send another message to turn off the switch then you can do that with the Trigger node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 July 2022 11:40 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/5 "2022-07-06T11:40:26Z")

</div>

If you add the octoprint mqtt plugin you can communicate between NR and octoprint. You could wait for the print to finish and have Octoprint publish an mqtt msg. When NR receives it, wait another 10 minutes (in case you are setting up for another print) then send a shutoff command to the smart plug the printer is connected to. Then wait a bit longer and have NR (using an `exec` node) send a shutdown command to the Pi.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2022 12:41 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/6 "2022-07-06T12:41:41Z")

</div>

I did try the MQTT plugin and had some problems with it, I forget exactly what. I ended up using the http interface directly, which is not difficult.

---

<div class="post-metadata">

**Author:** ![TheSirSpence](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thesirspence/32/64243_2.png) [@TheSirSpence](https://discourse.nodered.org/u/TheSirSpence)\
**Post date:** [6 July 2022 14:41 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/7 "2022-07-06T14:41:29Z")

</div>

Thanks for the reply, are you talking the MQTT plug in Home Assistant? That is how my Octoprint is currently connected. If not I will take a look in NR.

---

<div class="post-metadata">

**Author:** ![TheSirSpence](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thesirspence/32/64243_2.png) [@TheSirSpence](https://discourse.nodered.org/u/TheSirSpence)\
**Post date:** [6 July 2022 14:42 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/8 "2022-07-06T14:42:09Z")

</div>

Thanks for the tip. I will take a look!

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 July 2022 15:14 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/9 "2022-07-06T15:14:49Z")

</div>

I mean the OctoPrint MQTT plugin

> **[GitHub - OctoPrint/OctoPrint-MQTT: An OctoPrint Plugin that adds support for...](https://github.com/OctoPrint/OctoPrint-MQTT)**
>
> An OctoPrint Plugin that adds support for MQTT. Contribute to OctoPrint/OctoPrint-MQTT development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 July 2022 15:16 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/10 "2022-07-06T15:16:27Z")

</div>

> [@TheSirSpence](#):
>
> are you talking the MQTT plug in Home Assistant

No, the mqtt plugin for Octoprint itself. That allows it to be controlled via mqtt. I don't use HA.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 September 2022 15:17 UTC](https://discourse.nodered.org/t/octoprint-safe-shutdown/64760/11 "2022-09-04T15:17:24Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
