# Save state Switch node

**URL:** <https://discourse.nodered.org/t/save-state-switch-node/66223>\
**Category:** General\
**Created:** [9 August 2022 13:04 UTC](https://discourse.nodered.org/t/save-state-switch-node/66223 "2022-08-09T13:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [9 August 2022 13:04 UTC](https://discourse.nodered.org/t/save-state-switch-node/66223/1 "2022-08-09T13:04:04Z")

</div>

Hi

I have a switch node that I set the the flow to port 1 or 2.  
After I restart my Raspberry PI the node reset to port 0.  
Is there a way to save the flow of the node?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [9 August 2022 13:28 UTC](https://discourse.nodered.org/t/save-state-switch-node/66223/2 "2022-08-09T13:28:09Z")

</div>

Switch is based on some variable. To make that persistent across restarts, you need a retained variable. You can change the settings for node-red to add retained variables as an option (the default is in-memory only) and use a change node in front of the switch to recover the variable onto the msg that gets passed to the switch.

If you re using MQTT, you can use a retained topic to similar effect execpt that you need an mqtt-in node set to the retained topic, that node will fire a msg if the topic value changes or if node-red restarts.

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [9 August 2022 13:29 UTC](https://discourse.nodered.org/t/save-state-switch-node/66223/3 "2022-08-09T13:29:42Z")

</div>

Thank you a lot.

---

<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:** [8 October 2022 13:29 UTC](https://discourse.nodered.org/t/save-state-switch-node/66223/4 "2022-10-08T13:29:53Z")

</div>

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