• Categories
    • Recent
    • Tags
    • Popular
    • Register
    • Login

    Temperature MIN/MAX/AVG

    Scheduled Pinned Locked Moved Scripts
    scriptmetrics
    3 Posts 2 Posters 2.4k Views 1 Watching
    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.
    • T Offline
      Tetnobic
      last edited by Tetnobic

      Hello,
      How can I get MIN/MAX/AVG informations about temperature variable ?
      I see in ScriptAPI about metrics, method : getSensorVariableMetricsDouble
      it's the right way ?

      When I try this on my sensor variable :
      var list = mcApi.metric().getSensorVariableMetricsDouble(1,0,1479823903);
      list is empty 😞

      Can you help me ?
      Thanks

      jkandasaJ 1 Reply Last reply Reply Quote 0
      • jkandasaJ Offline
        jkandasa @Tetnobic
        last edited by jkandasa

        @Tetnobic You can get it on two ways,

        Option 1:

        Assign uidTag for your temperature variable, and use it on the script. In this method it will return single object. You will not get list.

        var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
        
        with(myImports) {
        var sVar = mcApi.uidTag().getByUid("temp-outside").getResource(); // Get sensor variable object with UidTag api
        var minMaxData = mcApi.metric().getSensorVariableMetricDouble(sVar, 0,1479833863195); //(sensor-variable-object, from-timestamp, to-timestamp)
        }
        

        on minMaxData object will be as follows,

        "minMaxData": {
            "minimum": 0,
            "average": 73.51,
            "maximum": 115.4,
            "current": 34.9,
            "previous": 34.9,
            "variable": {....}
        }
        
        Option 2:

        You can call list of metrics range with timestamp and bucket-duration. BucketDuration is nothing but interval between metric values.

        var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
        
        with(myImports) {
        var sVar = mcApi.uidTag().getByUid("temp-outside").getResource(); // Get sensor variable object with UidTag api
        var listOfData = mcApi.metric().getMetricData(sVar.id, "Sensor variable", 1479733863195, 1479833863195, "6h", true); //(sensor-variable-id, from-timestamp, to-timestamp, bucket-duration, boolean-get-generic), here the bucket duration is 6 hours
        }
        

        Output as follows,

          "listOfData": [
            {
              "start": 1479755463195,
              "end": 1479777063195,
              "empty": false,
              "min": 40.5,
              "max": 43.3,
              "avg": 42.672998137802615,
              "samples": 537
            },
            {
              "start": 1479777063195,
              "end": 1479798663195,
              "empty": false,
              "min": 37.7,
              "max": 42.6,
              "avg": 40.97185185185186,
              "samples": 540
            },
            {
              "start": 1479798663195,
              "end": 1479820263195,
              "empty": false,
              "min": 34.9,
              "max": 38.4,
              "avg": 37.71923076923077,
              "samples": 546
            },
            {
              "start": 1479820263195,
              "end": 1479841863195,
              "empty": false,
              "min": 34.9,
              "max": 35.6,
              "avg": 34.96143617021263,
              "samples": 376
            }
          ]
        

        hope this example will help you.

        1 Reply Last reply Reply Quote 0
        • T Offline
          Tetnobic
          last edited by

          Wonderful !!!
          Option 1 works for me like a charm !

          Many thanks, MyController is the best 😉

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

          0

          Online

          587

          Users

          529

          Topics

          3.4k

          Posts
          Copyright © 2015-2025 MyController.org | Contributors | Localization