Slider goes to off after refresh

Hello All, i am new to Nodered and i can manage it a bit but now i haver a question is use the dasboard and on it i have a switch the problem is that when the browser refresh the switsh state on the screen is off but in the flow it is stil on. how doe i get it to stay on after a refresh


So you go to the dashboard and flip the switch so it is on. You then refresh the browser without doing anything else and the switch is now off. Is that correct?

Do you have other nodes attached to the ui-switch node? if so what?

When i fire a flow en return to the ui the ui refresh end the switch is set to off when i go back to the tab in the browser to see what node red say’s the switch is still on

I have no other switches i wan’t to start simpel


Export & paste your flow here, maybe some screenshots are also welcome, otherwise is going to be difficult to understand what is exactly happening and what you expect.


I had made it simpel to test, after a deploy and a refresh it lose the settings in de ui not in node red

[{"id":"1bb80372.f1731d","type":"ui_switch","z":"acb0cd80.a8968","name":"","label":"switch1","group":"3428f0c.0c67d1","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":189,"y":32,"wires":[["37d34de3.f01fd2"]]},{"id":"37d34de3.f01fd2","type":"debug","z":"acb0cd80.a8968","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":508,"y":37,"wires":[]},{"id":"3428f0c.0c67d1","type":"ui_group","z":"","name":"Online Overzicht","tab":"1b85579e.135968","order":1,"disp":true,"width":"7","collapse":false},{"id":"1b85579e.135968","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]

First off, when ever adding code to a thread, start by adding three backticks, then the code, then three more backticks. It will prevent 'smart quotes".

Ok, I can not reproduce your issue, it works for me.

What platform are you running Node Red on?
What versions of NR and node.js are you running?
Please list a step by step what you do to cause the issue and be detailed

It is still not clear to me at what point the switch state is being lost. Is it after a refresh or only if you deploy and then refresh?

If it is after a deploy then that is expected. How would the switch know which state to be in after the deploy as you have nothing in the flow to initialise it? You need a mechanism to save the state and restore it on restart.

The solution I use for this is to feed the output from the switch into a Retained topic in MQTT and then also have an MQTT In node subscribed to that topic and feeding the input back into the front of the switch. Make sure the Message Pass Through is not enabled in the switch or you will get an infinite MQTT loop. This method has the additional advantage that you can separate the UI flow from the action flow. The UI flow just consists of MQTT In >> Switch >> MQTT Out. The action flow has an MQTT In and feeds that into the nodes to take appropriate action when the switch changes. By separating like this you can make your flows simpler to understand.

1 Like

I'm also searching for a solution to retain a (slider) value after deploying, would you have a MQTT action flow example?

There is nothing to put in a flow really, MQTT In picking up the retained current slider value -> Slider (with If msg arrives on input, pass through to output: not selected) -> MQTT Out with appropriate topic and set to Retain. Then where you want to use the slider value I would pick it up from MQTT rather than the slider. That means that if you write that value from somewhere else it will still get actioned.

Hey Colin, thanks that's perfect works a treat!!

I did mean to say a node not flow.

Anyway thanks again