# Save dashboard switch node state to file

**URL:** https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851
**Category:** Dashboard
**Created:** [5 April 2022 20:53 UTC](https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851 "2022-04-05T20:53:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)
#### Post date: [5 April 2022 20:53 UTC](https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851/1 "2022-04-05T20:53:21Z")

</div>

Hi,

Is it possible to store the state of a dashboard switch node in a context [file] and restore the state after a reset/deploy with an injector node?

---

<div class="post-metadata">

### Author: ![MountainKing91](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mountainking91/32/59516_2.png) [@MountainKing91](https://discourse.nodered.org/u/MountainKing91)
#### Post date: [9 April 2022 21:08 UTC](https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851/2 "2022-04-09T21:08:00Z")

</div>

Hi,  
in you settings.js file enable storing context in a file ([Working with context : Node-RED](https://nodered.org/docs/user-guide/context)), then try this:

````auto
[{"id":"0c8265f37d6d6231","type":"inject","z":"3ee8efab.e6694","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"#:(storeInFile)::lastSwitchState","payloadType":"flow","x":160,"y":580,"wires":[["b9bcda0a2aa16907"]]},{"id":"b9bcda0a2aa16907","type":"ui_switch","z":"3ee8efab.e6694","name":"","label":"switch","tooltip":"","group":"7d65a5299b5721bf","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":330,"y":580,"wires":[["209e7c0d8ab556d6"]]},{"id":"209e7c0d8ab556d6","type":"change","z":"3ee8efab.e6694","name":"","rules":[{"t":"set","p":"#:(storeInFile)::lastSwitchState","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":580,"wires":[[]]},{"id":"7d65a5299b5721bf","type":"ui_group","name":"Retentive switch","tab":"cc16d42c.cb9c08","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"cc16d42c.cb9c08","type":"ui_tab","name":"Test","icon":"fa-lightbulb-o","order":1,"disabled":false,"hidden":false}]```
````

---

<div class="post-metadata">

### Author: ![gschmidt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gschmidt/32/60349_2.png) [@gschmidt](https://discourse.nodered.org/u/gschmidt)
#### Post date: [11 April 2022 21:12 UTC](https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851/3 "2022-04-11T21:12:51Z")

</div>

> [@MountainKing91](#):
>
> Hi,  
> in you settings.js file enable storing context in a file ([Working with context : Node-RED](https://nodered.org/docs/user-guide/context)), then try this:
> 
> ```auto
> [{"id":"0c8265f37d6d6231","type":"inject","z":"3ee8efab.e6694","name":"","props":[{
> 
> ```

Yes got it, I also use injectors to restore the switch from the stored context value

---

<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: [11 May 2022 21:13 UTC](https://discourse.nodered.org/t/save-dashboard-switch-node-state-to-file/60851/4 "2022-05-11T21:13:44Z")

</div>

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