Dynamic input for Range node


I found that it might be useful if Range node had option to set input range values dynamically.
Why? For example I have a set of numeric data and it changes daily. So min and max are different for each day.

For graphical representation I range that data into proper scale. But data can have anomalies. High peaks happen and so.

For me the graphical representation talks about relativity of current set of the values. Min is at low edge and max is at the top and there will be no need to show any reference line.

So it will be handy if I could feed in the payload together with input range values.
Is it reasonable enough?



Probably easier to just write it as a function :slight_smile:


I already did that :slight_smile: But I just found that it might be useful for other cases too. Not only mine. And that other -- Node-RED and less coding -- thing :wink:


Our default behaviour on nodes is that a value can only be overridden if the field is left blank - at which point you then need to pass in the override value on every msg. - and in this case you would need 4 extra properties - minIn maxIn minOut maxOut etc... which just makes the node info messy, and just feels clunky to have to pass in so much for something so simple.


Well comparing with Chart node to show historic data ....
OK they are different enough things for sure
Let it be :slight_smile:


I realize this is an old topic, but for me too it would be very helpful to be able to use a numeric input to feed the input range from and to fields.
I'm building yet another plant watering system and I'm using the range node to reverse and calibrate a capacitive moisture sensor (1600, 3500, 100, 0) and it would be great to be able to adjust the input range for calibrating without delving into the flow panel.

Or maybe somebody could suggest a different method, please?


All that range node does can be achieved with function also. It can be then adjusted and optimized by your specific needs.

See https://stackoverflow.com/questions/10756313/javascript-jquery-map-a-range-of-numbers-to-another-range-of-numbers


Thanks for the link, I'm afraid I'm not to hot in javascript. Would that be a variation of:

Could you explain how to incorporate numeric inputs to the in_min / in_max, please?


This is pseudo code to explain how this can be used in function node. Do not expect it to work out of box. You will need to make many adjustments before it actually does the trick. But basics here.

var value = msg.payload;//value to be ranged

//range limits
var inputrange = msg.inputrange || [0,100];//expected range of input value. an array containing min and max 
var outputrange = msg.outputrange || [0,1000] // range into the value to be converted. an array containing min and max 

// range limits can also be represented as Object if you like. 
// var ranges = {mininput:0,maxinput:100,minoutput:50,maxoutput:50000};

//you should store input and output ranges into context memory 
//so you don't need to send them with every message but only when needed
// see https://nodered.org/docs/writing-functions#storing-data

//brain of the whole thing. hard work is done here
const mapNumber = (number, in_min, in_max, out_min, out_max) => {
  return (number - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;

// here how the brain is used
var output = mapNumber(value,inputrange[0],inputrange[1],outputrange[0],outputrange[1]);

// hard work is done, place the ranged number into outgoing msg payload
msg.payload = output;

return msg;

Ok thanks, I'll give it a try.