# Retain slider data

**URL:** <https://discourse.nodered.org/t/retain-slider-data/39098>\
**Category:** General\
**Created:** [13 January 2021 22:18 UTC](https://discourse.nodered.org/t/retain-slider-data/39098 "2021-01-13T22:18:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yawstick1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yawstick1/32/11419_2.png) [@yawstick1](https://discourse.nodered.org/u/yawstick1)\
**Post date:** [13 January 2021 22:18 UTC](https://discourse.nodered.org/t/retain-slider-data/39098/1 "2021-01-13T22:18:31Z")

</div>

I'm using the code below in a function to control heat on and heat off. It works for one on/off cycle but not a second one unless you move the slider input. I send a sync msg every 30 seconds that triggers the remote temperature sensors to report their temps. Is there a way to retain the set temperature or possibly trigger it with the sync pulse as well.

m = msg.payload;  
t = msg.topic;  
t2 = 'testTopic';  
if (t == 'set\_hi')  
{H = m;}  
{L = (m - 1.5)}  
if (t == 'temp\_fla')  
{temp\_fla = parseFloat(m)}  
if (temp\_fla \< L)  
{  
return {topic: t2, payload: "relay 6 on" };  
}  
else if (temp\_fla \> H )  
{  
return {topic: t2, payload: "relay 6 off"};  
}

```auto
[{"id":"fd273802.758b68","type":"function","z":"273f3321.930bdc","name":"","func":"m = msg.payload;\nt = msg.topic;\nt2 = 'testTopic';\nif (t == 'set_hi')\n{H = m;}\n{L = (m - 1.5)}\nif (t == 'temp_fla')\n{temp_fla = parseFloat(m)}\nif (temp_fla < L)\n{\nreturn {topic: t2, payload: \"relay 6 on\" };\n}\nelse if (temp_fla > H )\n{\nreturn {topic: t2, payload: \"relay 6 off\"};\n}","outputs":1,"noerr":0,"x":550,"y":860,"wires":[["73cbdf7c.a619a","30e07356.73b74c"]]},{"id":"30e07356.73b74c","type":"debug","z":"273f3321.930bdc","name":"test2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":820,"wires":[]},{"id":"73cbdf7c.a619a","type":"mqtt out","z":"273f3321.930bdc","name":"test","topic":"","qos":"","retain":"","broker":"a0daec91.c9a4e","x":750,"y":900,"wires":[]},{"id":"4a27bc0c.52da04","type":"debug","z":"273f3321.930bdc","name":"temps","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":370,"y":880,"wires":[]},{"id":"614af900.a64888","type":"ui_switch","z":"273f3321.930bdc","name":"","label":"Auto Heat","tooltip":"","group":"374e9b2e.f2f1a4","order":8,"width":"4","height":1,"passthru":true,"decouple":"false","topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":140,"y":700,"wires":[["d6576ffa.9e274","731c9867.c9b218"]]},{"id":"d6576ffa.9e274","type":"function","z":"273f3321.930bdc","name":"control","func":"if (msg.topic === \"gate\") {\n context.pass = (msg.payload === true) ? true : false;\n return null; // exit out early as it's just the control\n}\nif (context.pass) {\n return msg; // if enabled pass msg\n}\nreturn null; // or drop it","outputs":1,"noerr":0,"x":410,"y":780,"wires":[["85450665.2c5138","fd273802.758b68"]]},{"id":"85450665.2c5138","type":"debug","z":"273f3321.930bdc","name":"test1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":740,"wires":[]},{"id":"731c9867.c9b218","type":"debug","z":"273f3321.930bdc","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":490,"y":700,"wires":[]},{"id":"c5f7fa6f.63ad18","type":"mqtt in","z":"273f3321.930bdc","name":"","topic":"temp_fla","qos":"2","datatype":"auto","broker":"a0daec91.c9a4e","x":140,"y":880,"wires":[["d6576ffa.9e274","4a27bc0c.52da04"]]},{"id":"a95266e5.2f4048","type":"ui_slider","z":"273f3321.930bdc","name":"set high","label":"set high","tooltip":"","group":"c297bd45.20f95","order":1,"width":"6","height":"1","passthru":true,"outs":"end","topic":"set_hi","min":"65","max":"75","step":".1","x":140,"y":760,"wires":[["d6576ffa.9e274"]]},{"id":"cf0007a9.9b0568","type":"ui_slider","z":"273f3321.930bdc","name":"set low","label":"set low","tooltip":"","group":"c297bd45.20f95","order":1,"width":"6","height":"1","passthru":true,"outs":"end","topic":"set_lo","min":"65","max":"75","step":".1","x":140,"y":820,"wires":[["d6576ffa.9e274"]]},{"id":"a0daec91.c9a4e","type":"mqtt-broker","z":"","name":"pi4_mqtt","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"374e9b2e.f2f1a4","type":"ui_group","z":"","name":"Group 2","tab":"98d496.1ca73b68","order":2,"disp":true,"width":16,"collapse":false},{"id":"c297bd45.20f95","type":"ui_group","z":"","name":"Group 3","tab":"98d496.1ca73b68","order":3,"disp":true,"width":"9","collapse":false},{"id":"98d496.1ca73b68","type":"ui_tab","z":"273f3321.930bdc","name":"Tab 1","icon":"dashboard","order":2,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Bobo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bobo/32/8401_2.png) [@Bobo](https://discourse.nodered.org/u/Bobo)\
**Post date:** [14 January 2021 02:41 UTC](https://discourse.nodered.org/t/retain-slider-data/39098/2 "2021-01-14T02:41:22Z")

</div>

> [@yawstick1](#):
>
> Is there a way to retain the set temperature or possibly trigger it with the sync pulse as well

Have you looked at Context? [Working with context : Node-RED](https://nodered.org/docs/user-guide/context)

---

<div class="post-metadata">

**Author:** ![yawstick1](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/yawstick1/32/11419_2.png) [@yawstick1](https://discourse.nodered.org/u/yawstick1)\
**Post date:** [14 January 2021 09:35 UTC](https://discourse.nodered.org/t/retain-slider-data/39098/3 "2021-01-14T09:35:23Z")

</div>

Thanks... that did the trick

---

<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:** [28 January 2021 09:35 UTC](https://discourse.nodered.org/t/retain-slider-data/39098/4 "2021-01-28T09:35:29Z")

</div>

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