Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Meta point/ECMA script help

  • Hi,

    Quick/simple question, I hope.

    I have a data point which is a lifetime kWh counter. It does not reset to 0 or run backwards. It is an energy meter and I wish to record the total kWh consumed per day, updating every hour or so.

    I would like to create a meta data point which, when updated, shows the 'daily progress' of that counter.
    In other words, I want to subtract the latest reading from the first reading today (or last one yesterday).

    If I use this method:

    return p214.value - p214.ago(DAY);

    Then I get the consumption over the last 24 hours, which is not what I want.

    Any ideas?


    (Bonus second question - once the daily delta is calculated, only one record needs to be retained for that day - the last one. What would be the best way to accomplish that?)

  • OK, I think I have gotten it working using this:

    return (p214.value)-(p214.prev(DAY).lastValue);

    For some reason, value.prev(DAY) returns as NaN, when I think it should do the same thing.

  • Hi Jeremy,

    This is a pretty common use-case for Mango.

    To calculate a daily total you can use the exact script that you posted except only run it on the last second of the day with a cron patter like this: 0 59 23 * * ?

    To have a daily accumulation that starts as 0 every day and counts up you could use a script like this, which could run on context update:

    return (p.value - p.previous(DAY) .maximumValue)

    You could then set the above Meta Data Point to log on a 1 day interval the maximum value and I think this will accomplish what you want.

    I would recommend reading in the help popup for Meta Data Points about the difference between .ago and .previous as this might help explain it a bit further.

    Hope that helps.


  • Snap!
    Got it just as you were writing that post I think Joel. Thanks for the reply though.

    I've set it to run hourly, which for the time being is an acceptable tradeoff between logging loads of redundant points, and having the information available on the current day.

    Would it be possible to use the Scripting data source to delete all the points for the current or previous day, bar the last one?

  • I don't think the scripting data source could be used to delete past logged values but that's an interesting idea.

    I think it should work fine to just log the max once per day even if you are updating every hour. You could increase the default cache size for the point to 24 so then it will keep 24 hours of history in the cache so you can still chart it for that day.