# Slider goes to off after refresh

**URL:** <https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036>\
**Category:** Dashboard\
**Created:** [24 June 2018 11:39 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036 "2018-06-24T11:39:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paulb/32/789_2.png) [@paulb](https://discourse.nodered.org/u/paulb)\
**Post date:** [24 June 2018 11:39 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/1 "2018-06-24T11:39:02Z")

</div>

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

Paul

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 June 2018 18:47 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/2 "2018-06-24T18:47:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paulb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paulb/32/789_2.png) [@paulb](https://discourse.nodered.org/u/paulb)\
**Post date:** [24 June 2018 22:26 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/3 "2018-06-24T22:26:16Z")

</div>

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

Paul

---

<div class="post-metadata">

**Author:** ![davidcgu](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@davidcgu](https://discourse.nodered.org/u/davidcgu)\
**Post date:** [24 June 2018 22:31 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/4 "2018-06-24T22:31:02Z")

</div>

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.

Regards

---

<div class="post-metadata">

**Author:** ![paulb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paulb/32/789_2.png) [@paulb](https://discourse.nodered.org/u/paulb)\
**Post date:** [24 June 2018 22:36 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/5 "2018-06-24T22:36:12Z")

</div>

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

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 June 2018 00:27 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/6 "2018-06-25T00:27:11Z")

</div>

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

---

<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:** [25 June 2018 07:12 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/7 "2018-06-25T07:12:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ianszh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianszh/32/8897_2.png) [@Ianszh](https://discourse.nodered.org/u/Ianszh)\
**Post date:** [28 April 2019 11:53 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/8 "2019-04-28T11:53:58Z")

</div>

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

---

<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:** [29 April 2019 07:49 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/9 "2019-04-29T07:49:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ianszh](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ianszh/32/8897_2.png) [@Ianszh](https://discourse.nodered.org/u/Ianszh)\
**Post date:** [29 April 2019 19:43 UTC](https://discourse.nodered.org/t/slider-goes-to-off-after-refresh/1036/10 "2019-04-29T19:43:45Z")

</div>

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

I did mean to say a node not flow.

Anyway thanks again
