# Dashboard Switch node value persistance

**URL:** <https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995>\
**Category:** Dashboard\
**Created:** [23 December 2023 20:15 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995 "2023-12-23T20:15:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [23 December 2023 20:15 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/1 "2023-12-23T20:15:06Z")

</div>

Is there a version of the Dashboard Switch node which can store it's value for when the RPi or a flow is restarted?

I've had a situation where a timer module (with switch input for pause/resume) started up again, presumably after a system reboot.

Anyone found a solution to this and are happy to share it, please?

All the best,  
Dax.

---

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [23 December 2023 20:26 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/2 "2023-12-23T20:26:38Z")

</div>

Hmm, interesting! It seems like the switch value _is_ persistent, at least when re-deploying flows _ **but** _ this saved value isn't sent to its output (which kinda results in the same thing as not being stored at all.)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 December 2023 20:34 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/3 "2023-12-23T20:34:47Z")

</div>

What settings does your switch node have?

You can save the switch output to a persistent context variable and inject that value at startup with an inject node.  
I think the switch has to be setup to pass valid messages through.

---

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [23 December 2023 20:48 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/4 "2023-12-23T20:48:56Z")

</div>

Thanks @jbudd for the reply!

Below are the dashboard switch node settings. I could pass a signal to the switch's input, but that input would need to be a disk-stored copy of the switch's last output, rather than a static value as is possible with the Inject node using "Inject once after..".

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/c/1cfb17ffd1d22740a2d975efda980385b9af0dfe.png)

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [23 December 2023 21:02 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/5 "2023-12-23T21:02:06Z")

</div>

> [@daxliniere](#):
>
> I could pass a signal to the switch's input, but that input would need to be a disk-stored copy of the switch's last output,

Yes indeed, stored to persistent context so it survives a reboot.  
So that would require a) a change node, and "localfilesystem" as the default context store  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/18956cb40fd03ffdfdbe379ef17fb6bad88f1d2b.png)

or b) a function node and "localfilesystem" as an optional context store.

---

<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:** [23 December 2023 22:00 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/6 "2023-12-23T22:00:34Z")

</div>

Note that there are still some confusing issues with switch nodes configured to send text strings. See [Switch with string output payloads gets confused when driven by input messages. · Issue #457 · FlowFuse/node-red-dashboard · GitHub](https://github.com/FlowFuse/node-red-dashboard/issues/457). Whether this is part of your issue I don't know.

---

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [24 December 2023 01:44 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/7 "2023-12-24T01:44:35Z")

</div>

Thanks @jbudd. I already have localfilesystem enabled. How would this work with a Change node?  
Or the Function node you suggested?

Thanks @Colin, that is good to know.

It would be nice if the Dashboard Switch node would get a function to transmit stored context upon startup. @joepavitt is this something you would consider? It's great that the Dashboard Switch retains it's setting, but far more useful if it transmits it on startup as well.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [24 December 2023 01:58 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/8 "2023-12-24T01:58:58Z")

</div>

I think this works

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/1/b168e741ebdc5b33d95f42e937e8d0a7ca358582.png)

```auto
[{"id":"521a8221d629d6e9","type":"ui_switch","z":"4b211f23c08b43f4","name":"","label":"switch","tooltip":"","group":"bd5694e58bd4943e","order":7,"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":370,"y":100,"wires":[["954eef0c78c00eaf","7c6bb2e9aac46b6b"]]},{"id":"7e8e32f10acdba8d","type":"inject","z":"4b211f23c08b43f4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"lastvalue","payloadType":"flow","x":180,"y":100,"wires":[["521a8221d629d6e9"]]},{"id":"954eef0c78c00eaf","type":"change","z":"4b211f23c08b43f4","name":"","rules":[{"t":"set","p":"lastvalue","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":100,"wires":[[]]},{"id":"7c6bb2e9aac46b6b","type":"debug","z":"4b211f23c08b43f4","name":"debug 2461","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":160,"wires":[]},{"id":"bd5694e58bd4943e","type":"ui_group","name":"This Pi","tab":"9611f8e5805241b9","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"9611f8e5805241b9","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

My settings.js has

```auto
contextStorage: {
    default: {
        module:"localfilesystem"
    },
},

```

Note that the switch node will only accept the value from msg.payload if it's set to pass through a payload which is a valid state. So if the last value was eg true, if Node-red restarts, true will be sent to your timer once more as well as showing on the dashboard. I'm not sure if this is desirable behaviour.

There is an alternative setup if pass-through is not selected, for the switch to "show the state of the input". _Maybe_ this could be used to sync the dashboard without re-sending the last message to the timer.

---

<div class="post-metadata">

**Author:** ![joepavitt](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/joepavitt/32/59722_2.png) [@joepavitt](https://discourse.nodered.org/u/joepavitt)\
**Post date:** [24 December 2023 08:55 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/9 "2023-12-24T08:55:17Z")

</div>

Just checking if you're talking/using Dashboard 2.0 here?

We have a new "dashboard-2" tag if so to help differentiate 😁

---

<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:** [23 January 2024 08:55 UTC](https://discourse.nodered.org/t/dashboard-switch-node-value-persistance/83995/10 "2024-01-23T08:55:22Z")

</div>

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