Skip to content

Formulas

There are three different types of formulas SUM, DIFF, and CUSTOM.

Available variables

There's one input variable available for each input meter: INPUT1, INPUT2, ..., INPUTN. Each input variable is an object containing the following properties:

Property Type Description
value number The current value of the input event

The formula is run in an environment which provides a couple of helper constants and functions.

Property Type Description
Year number The current year
Month number The current month of the year
Day number The current day in month
Hour number The current hour
Timestamp Date Equal to new Date(Year, Month, Day, Hour, 0, 0, 0)
Moment moment.Moment Moment.js1 moment() date object for the current timestamp
INPUT[1..N] Object The Input provided above

SUM

Will simply sum all the values for a certain timestamp and is equivalent to:

return INPUT1.value + INPUT2.value + ... + INPUTN.value

DIFF

Will subtract all subsequent values and is equivalent to:

return INPUT1.value - INPUT2.value - ... - INPUTN.value

CUSTOM

Allows for a custom formula to be written. The formula can be anything as long as it is valid javascript. The formula will be wrapped in a function before being executed and MUST end with a return statement.

Example valid formula

// We can get the day, month, and year, from variables always available to us.
let factor = 0;
if (Year > 2000) factor = 1;
if (Month > 5) factor = 2;
if (Day > 20) factor = 3;

return (INPUT1.value / INPUT2.value) * factor;

Example invalid formula

While the javascript is valid, it does not return anything and will yield a 0 value.

    function notvalid() {
      return INPUT1.value + INPUT2.value;
    }

Warning

Invalid formulas or formulas taking too long to execute will be terminated and yield a 0 value.lue.


  1. https://momentjs.com/