Dashboard Switch node value persistance

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.

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.)

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.

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..".

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

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

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. Whether this is part of your issue I don't know.

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.

I think this works

[{"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

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.

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

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

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