FUSION AUTOMATE
← All tools

FUSION AUTOMATE TOOLS / IIOT / NODE-RED TOOLS

Node-RED Function Generator

Generate ready-to-copy Function node code. Fast, browser-local and free to use.

Maps a raw input range to an output range that begins at zero. Use case: Convert a PLC analog count into an engineering value for a dashboard or control calculation. Example: 13,824 raw counts from a 0–27,648 transmitter range becomes 50 when the output range is 0–100%.

FUNCTION NODE CODE

const value = Number(msg.payload);
const inputMin = 0;
const inputMax = 10000;
const outputMax = 100;

if (![value, inputMin, inputMax, outputMax].every(Number.isFinite) || inputMin === inputMax) {
  node.error("Check the scale inputs", msg);
  return null;
}

msg.payload = (value - inputMin) * outputMax / (inputMax - inputMin);
return msg;

Paste this into a Node-RED Function node, then deploy. Invalid numeric input is reported through the Node-RED debug sidebar.