• Recent
    • Tags
    • Popular
    • Register
    • Login

    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 support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Implement Hour Meter function from Modbus Inputs

    How-To
    2
    4
    1.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fylarxos
      last edited by

      Hello,

      I would like to implement a hour counter functionality to my project.
      More specifically, I have 4 digital inputs (modbus RTU) which will have to be monitored of how many hours they are "on".

      I suppose a script with a timer to add "1" to a data point after the passing of 1 hour is the way to go, any ideas?

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by

        Hi fylarxos, welcome to the forum!

        A script is definitely the way to go. Regardless of the script logic, I would do this with four meta points.

        Then I would wonder how exacting you're looking to be. Yes, a script on a timer totaling the elapsed time since last run is one perfectly valid solution, that is responsive at the rate you set the cron pattern. That might look like a meta point like this,

        var stats = di.past(MINUTE, 6).getStartsAndRuntime();
        if(my.value === null)
          return stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0;
        return my.value + (stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0);
        

        on a cron like 0 0/6 * * * ? or perhaps six minutes is not a frequent enough update (your counter would go up by .1 if it didn't go false. You could change this to update as soon as the point went false, but we'll simplify the first value. In this next script, the context point di updates the context...

        if(my.value === null)
          return 0;
        //if(my.time > CONTEXT.getTimestamp())
        //  throw "Timestamps are backward, something is off."; //Possible, but would take some action by user
        var stats = di.getStats(my.time, CONTEXT.getTimestamp()).getStartsAndRuntime();
        return my.value + (stats.containsKey(true) ? stats.get(true).runtime/3600000 : 0);
        

        Which we could also run on the six minute cron to ensure it gets some sort of update even if the point stays true.

        Thanks for asking the question! You may have seen the JavaScript help either in the contextual help or on our https://help.infiniteautomation.com/about-mango-java-script/ page, and in the 3.4.x series both will lead you astray! This thread goes into why a little: https://forum.infiniteautomation.com/topic/3627/not-a-function

        I am going to resolve the discrepancies and post in this and perhaps that thread when I do.

        1 Reply Last reply Reply Quote 0
        • F
          fylarxos
          last edited by

          Dear phildunlap

          Thank you for your reply, I will try out your proposed solution.
          Thanks again!

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by phildunlap

            We resolved after some discussion to bring back the .get() function as used on the help page linked to in my last post. Thanks again for bringing this to the fore! This will be the case in the production 3.5 release.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post