Overview
The math node performs mathematical operations on numeric message
values. Supports basic arithmetic, power and root functions, trigonometry, rounding, logarithms,
and random number generation. Ideal for unit conversions, sensor calibration, and computed metrics.
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| operation | string | "add" | add, subtract, multiply, divide, pow, sqrt, abs, ceil, floor, round, sin, cos, tan, log, exp, random |
| operand | number | 0 | Second operand for binary operations |
| property | string | "payload" | Message property to operate on |
| precision | number | 2 | Decimal places for result rounding |
| output | string | "payload" | Property to store the result |
Operations Reference
Arithmetic
Basic math with an operand
add: value + operand
subtract: value - operand
multiply: value * operand
divide: value / operand
pow: value ^ operand Unary
Single-value operations
sqrt: square root
abs: absolute value
ceil: round up
floor: round down
round: nearest integer Advanced
Trigonometric and logarithmic
sin: sine (radians)
cos: cosine (radians)
tan: tangent (radians)
log: natural logarithm
exp: e ^ value
random: 0.0 - 1.0 Example: Calculate Power Consumption
Compute wattage from voltage and current sensor readings (P = V * I).
// Math node configuration
{
"operation": "multiply",
"operand": 0, // Use msg.operand dynamically
"property": "payload.voltage",
"precision": 2,
"output": "payload.watts"
}
// Flow: batch (concat) → function → math
//
// Function node prepares:
msg.payload.voltage = msg.payload.voltage; // e.g., 230
msg.operand = msg.payload.current; // e.g., 4.5
return msg;
// Math node computes: 230 * 4.5 = 1035.00
//
// Output:
{
"payload": {
"voltage": 230,
"current": 4.5,
"watts": 1035.00
}
} Example: Convert Sensor Units
Convert temperature readings from Celsius to Fahrenheit using chained math operations.
// Step 1: Multiply node
{
"operation": "multiply",
"operand": 1.8,
"property": "payload",
"precision": 2
}
// Step 2: Add node
{
"operation": "add",
"operand": 32,
"property": "payload",
"precision": 1
}
// Flow: sensor (25.0 C) → multiply (45.0) → add (77.0 F)
//
// Formula: F = (C * 1.8) + 32
// Input: 25.0
// After multiply: 25.0 * 1.8 = 45.0
// After add: 45.0 + 32 = 77.0
// Also useful for:
// - hPa to inHg: multiply by 0.02953
// - meters to feet: multiply by 3.28084
// - ADC to voltage: multiply by (Vref / 1023) Example: ADC Sensor Calibration
Scale raw ADC readings to real-world units with offset correction.
// Step 1: Subtract zero-offset
{
"operation": "subtract",
"operand": 102, // Sensor reads 102 at zero
"property": "payload"
}
// Step 2: Scale to real units
{
"operation": "multiply",
"operand": 0.0489, // Scale factor for 0-50 PSI
"property": "payload",
"precision": 1
}
// Raw ADC: 614 → subtract → 512 → multiply → 25.0 PSI Common Use Cases
Unit Conversion
Celsius to Fahrenheit, meters to feet, PSI to bar
Sensor Calibration
Scale and offset raw ADC readings
Energy Monitoring
Calculate watts, kWh, and efficiency
Signal Processing
Trigonometric functions for waveform analysis