Set range on slider

Hi - is there a way to pass a max and min value to the dashboard slider?

Best place to check what can be send to the code dashboard nodes it at


OK... this is not a "good" solution (people are going to cringe reading this), but I had to solve this the other day to be able to dynamically set the max on a gauge. It works if you only have to do it once, or very rarely.

Set your "max" value in the slider to something very easy to find, like "12345.6789" and deploy. Read the /.node-red/flows file with a file input node - don't bother parsing it. First, for safety, use a change node to set up a new filename for the backup, like "flows1.bak" (or a timestamped backup). Write what you have to file (ideally next to the original). Then, run the whole flows file as a string into a Function node, and just find and replace the unique number you put in. Note that you can't use a change node for this replacement because this has to be a concatenated string representing the unique value, or else you'll replace the value in the function node itself, as well. For example, you could use something like msg.payload.replace("12345." + "6789",otherValue);

Once that's done, you'll do two things: overwrite your existing flows file with the new one you just made in the Function node, and then also (maybe on a few ms delay just in case) send the message to an exec node, and in it, run "node-red-restart". Deploy all that, cross your fingers really hard, run it, and see if Node Red comes back after a few seconds.

Like I said, this isn't the right answer - I'm sure somebody else can give you the "right" way to do this by writing your own node or something. But that's how I solved it.

Here's a flow that does approximately what I described:

[{"id":"3afbbd46.fced72","type":"file","z":"7d3bd692.2ce928","name":"","filename":".node-red/flows_raspberrypi.json","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":850,"y":160,"wires":[["bbb391ea.31f71"]]},{"id":"bbb391ea.31f71","type":"delay","z":"7d3bd692.2ce928","name":"","pauseType":"delay","timeout":"50","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":930,"y":200,"wires":[["dc4362e.030d0a"]]},{"id":"982b097e.ba3ef8","type":"function","z":"7d3bd692.2ce928","name":"replace \"12345.6789\"","func":"var flows = msg.payload;\nvar newFlows = flows.replace(\"12345.\"+\"6789\",\"Configured :-)\");\nmsg.payload = newFlows;\n\nreturn msg;","outputs":1,"noerr":0,"x":780,"y":120,"wires":[["3afbbd46.fced72"]]},{"id":"dc4362e.030d0a","type":"exec","z":"7d3bd692.2ce928","command":"node-red-restart","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":1140,"y":200,"wires":[[],[],[]]},{"id":"64239f0c.a40f4","type":"file in","z":"7d3bd692.2ce928","name":"","filename":".node-red/flows_raspberrypi.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":430,"y":120,"wires":[["86246221.86a8c","982b097e.ba3ef8"]]},{"id":"5e5b0816.08b088","type":"inject","z":"7d3bd692.2ce928","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":120,"wires":[["64239f0c.a40f4"]]},{"id":"86246221.86a8c","type":"change","z":"7d3bd692.2ce928","name":"","rules":[{"t":"set","p":"time","pt":"msg","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":160,"wires":[["48a9306f.7e75a"]]},{"id":"48a9306f.7e75a","type":"function","z":"7d3bd692.2ce928","name":"timestamped backup","func":"msg.filename = \".node-red/flows_backup_\" + msg.time + \".json\";\n\nreturn msg;","outputs":1,"noerr":0,"x":560,"y":200,"wires":[["325ee017.868d6"]]},{"id":"325ee017.868d6","type":"file","z":"7d3bd692.2ce928","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"true","encoding":"none","x":600,"y":240,"wires":[[]]}]

By the way, I did have success sending this whole mess through an MQTT node to another computer, having it send it all back, and then installing/deploying it, just to see if it would work. It did! Not sure why you'd want to do that - updating your flows on another computer to match the ones you're working on, I guess?

@tymarbut or you could read the information in the link I shared and use msg.ui-control to change the values.

1 Like

Well, I probably could have, and it probably would have been so much easier! But that was then, and this is now. :upside_down_face:

The only upside is I got to learn to do some very meta things with Node Red, which was fun and may yet be useful someday. Thanks for sharing the better method!

1 Like

Thanks for the replies. Much appreciated!

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