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?
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.
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?
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;