• header.categories
    • header.recent
    • header.tags
    • header.popular
    • register
    • login

    Temperature MIN/MAX/AVG

    scheduled pinned locked moved Scripts
    scriptmetrics
    3 posts 2 posters 2.7k views 1 watching
    loading-more-posts
    • oldest-to-newest
    • newest-to-oldest
    • most-votes
    reply
    • reply-as-topic
    guest-login-reply
    deleted-message
    • T offline
      Tetnobic
      global: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 one-reply-to-this-post last-reply-time reply quote 0
      • jkandasaJ offline
        jkandasa @Tetnobic
        global: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.

        one-reply-to-this-post last-reply-time reply quote 0
        • T offline
          Tetnobic
          global:last-edited-by,

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

          Many thanks, MyController is the best 😉

          one-reply-to-this-post last-reply-time reply quote 1
          • first-post
            last-post

          0

          online

          644

          users

          532

          topics

          3.4k

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