20,919,685Total Points24,106Total Sites23,382Cell Towers69,500Racks Monitored56,753HVAC Units Monitored31,322UPS Units Monitored24,788Generators Monitored20,919,685Total Points24,106Total Sites23,382Cell Towers69,500Racks Monitored56,753HVAC Units Monitored31,322UPS Units Monitored24,788Generators Monitored20,919,685Total Points24,106Total Sites23,382Cell Towers69,500Racks Monitored56,753HVAC Units Monitored31,322UPS Units Monitored24,788Generators Monitored

Chapter 4: Meta Points & ConversionsLesson 22 of 65

How to Create Unit Conversions with Meta Points

Use meta data source scripts to convert engineering units, calculate derived values, and create virtual data points from existing measurements.

  • 8 min read
  • Intermediate
  • Mango 4.x / 5.x

Overview

When devices report values in units that differ from what your dashboards or reports require, meta data source points provide the solution. A meta point runs a script that reads source point values, applies a formula, and produces a new virtual data point with the converted value.

How Meta Points Work

  1. Create a meta data source (or use an existing one)
  2. Add a meta point to the data source
  3. Add the source points under External context points and give each one a Key — the key is the name your script uses to read that point
  4. Write a script that reads context point values, performs the calculation, and returns the result
  5. The returned value becomes the meta point's current value, logged and available like any other data point

Common Unit Conversions

Temperature: Celsius to Fahrenheit

// Context key: p1 = temperature in Celsius
return p1.value * 9/5 + 32;

Temperature: Fahrenheit to Celsius

// Context key: p1 = temperature in Fahrenheit
return (p1.value - 32) * 5/9;

Pressure: PSI to Bar

// Context key: p1 = pressure in PSI
return p1.value * 0.0689476;

Power: Watts to Kilowatts

// Context key: p1 = power in watts
return p1.value / 1000;

Flow: Gallons per Minute to Liters per Minute

// Context key: p1 = flow in GPM
return p1.value * 3.78541;

Step-by-Step: Creating a Unit Conversion Point

  1. Go to Data integration > Data sources and open (or create) a Meta Data Source
  2. On the Data points tab, click Add
  3. Name the point descriptively (e.g., "RTU-01 Temperature (F)")
  4. Set the Export ID (XID) (e.g., DP_BLDG_A_RTU_01_TEMP_F)
  5. On the Meta data point tab, set Data type to Numeric. This is the type your script's return value gets converted to
  6. Under External context points, add the source point and give it a Key (e.g., a). Keys must be valid ECMAScript identifiers: start with a letter or underscore, and no spaces
  7. Tick Updates context on that row, so the script runs when the source updates. It starts unticked on every new row, and with Timer update event at its default of None, a point with nothing ticked never runs
  8. Write the conversion formula in the script editor, referring to the source by its key
  9. Leave Context event type at Update (the default)
  10. Save the point and enable it, then click Validate to test the script. Validation reports the computed result, and it needs the point saved and enabled first
  11. On Point properties, set Unit to the target unit. Mango by Radix IoT validates this string and rejects an unrecognised one, so stick to known symbols. Then, on Text renderer properties, tick Use unit symbol as suffix so the unit is shown with the value
  12. On Logging properties, set Logging type — usually All data for converted points

Warning

Key and Variable name are different fields and it is easy to confuse them. The Key column, on each row of External context points, is how your script refers to a source point. Variable name, higher up the same tab, is the name by which this meta point refers to itself in its own script context — useful for reading the point’s previous value, and not what you set to name a source.

Beyond Simple Conversions

Calculated Totals

// Sum power across three generators
// Context keys: gen1, gen2, gen3 = power points
return gen1.value + gen2.value + gen3.value;

Efficiency Calculation

// Context keys: output = output power, input = input power
// A context point with no value reads as null, and null is cast to 0 when used,
// so guard for both. Returning UNCHANGED leaves the point alone; returning 0
// would log a real reading of zero.
if (input.value === null || Number(input.value) === 0) return UNCHANGED;
return (output.value / input.value) * 100;

Running Average

// Context key: p1 = source point, which must be NUMERIC
// past() returns a statistics object — use .average (do not loop it like an array)
return p1.past(MINUTE, 10).average;

On a numeric point past() returns an AnalogStatistics object, which carries average, minimumValue, maximumValue, sum, integral, delta and count. On a binary or multistate point it returns a StartsAndRuntimeList instead, which has no average — so the same line silently yields undefined. Period constants are SECOND, MINUTE, HOUR, DAY, WEEK, MONTH and YEAR.

Conditional Status

// Context keys: temp = temperature, pressure = pressure
// Return alarm level: 0=OK, 1=Warning, 2=Critical
if (temp.value > 200 || pressure.value > 150) return 2;
if (temp.value > 180 || pressure.value > 130) return 1;
return 0;

Backfilling a New Conversion Point

A new meta point starts empty and only gains values as its context updates. To fill in the past, use the meta data source's Generate history tab: choose the From and To dates and times (they default to the last month), and Mango replays the context points' stored values in that range through your script and saves the results. A context-triggered point gets no values where its source points have no stored history. On an SQL point value store a second run over the same range can store duplicates, so tick Delete existing data in range when the range already holds values.

Performance Tips

  • Leave Context event type at "Update" for most conversions — it recalculates on every new value from a context row that has Updates context ticked. Change runs only when that value differs from the last one, and Logged only when it is logged
  • Use Timer update event only when you need a fixed calculation interval regardless of source updates. Its options are None, start of minute, hour, day, week, month or year, and Cron pattern, which reveals a required Cron pattern field
  • Avoid heavy operations in meta point scripts — HTTP calls, large historical queries, or complex iterations slow down the system
  • Move slow work off the context trigger. With Execution delay(seconds) at 0 the script runs on the thread that delivered the source value, so a slow script delays that data source. Give it a delay, or run it on a Timer update event. A global script is a shared function, not a schedule: it runs only when another script calls it

Troubleshooting

IssueCauseFix
Meta point shows no valueScript error, or no context point set to update contextClick Validate on the script — a failing script also raises a "Script error in point" event. Confirm at least one context row has Updates context ticked, and that the source points are enabled
Value is NaN or undefinedContext point has no value, division by zero, treating past() like an array, or calling .average on a non-numeric pointCheck for null as well as zero — a null value is cast to 0 when used, so a zero-only guard misses it. Use past(...).average (stats object), not a loop
Conversion seems wrongFormula error or wrong context point assignedVerify formula independently; check context point mapping
Meta point updates too slowlyNo context row has Updates context ticked, so only the Timer update event runs itTick Updates context on the source's row and leave Context event type at Update; set Timer update event to None unless you need a fixed interval
Nothing appears in the script logLog Level on the meta data point defaults to NoneRaise Log Level. Script output goes to that point's own script log file, which the editor links; ma.log carries general Mango logging

Summary

Meta points are the simplest way to create unit conversions and calculated values in Mango. Add context points, write a formula, and the meta point produces a new data point with converted values. Beyond simple conversions, meta points handle totals, averages, efficiency calculations, and conditional logic — all without external scripting tools.

Get free access to all 65 Mango by Radix IoT training lessons

One short form unlocks every lesson and its video in this browser.

This form is hosted by Zoho. It loads only after you enable support cookies or choose to load it below.

We honored your browser’s Global Privacy Control signal — optional cookies are off and nothing is tracked.