Forum Discussion

marting's avatar
marting
Icon for Neophyte rankNeophyte
5 months ago

Complex Datapoints - Nested if / elseif possible w/o scripting?

Setting up some monitoring for an HVAC device and there is a request to track / alert on the current state/mode of HVAC zones (i.e. when they're not at the expected state).

There is an HTTP interface that I'm using to get data.  For the mode, the device returns that data in plaintext.  Example:  

mode: Cool

I've created normal "binary" Datapoints that do a text match to account for all the mode options and this is working as expected.  So, for example, I have a ZoneModeCool datapoint that is 1 when that mode is active.

I was then hoping to have a complex datapoint that looks at these and returns a single value that represents the mode (e.g. 1 for Auto, 2 for Cool, etc.).

Problem I'm running into: groovy script can't access the normal datapoints (right?) and I can't figure out a way to do what I'm doing via RPN expressions.  Wondering if those support nested if statements or elseif statements?

Was trying something like this where I "nest" if statements, but LM tells me that's incorrect syntax:

if(eq(ZoneModeHeat,1),5, if(eq(ZoneModeDry,1),4, [...]

I know I can pull the raw data into groovy script...  Was hoping to avoid that since I already have the normal datapoints but maybe that's the answer anyways?

  • Anonymous's avatar
    Anonymous
    5 months ago

    Groovy can't access the normal datapoints, but it has the output of the script. So you could use Groovy to loop through all the lines, splitting on the ":" and grabbing the datapoint name and value into a map. 

    Nested if statements are definitely possible. Most likely there's a problem with opening/closing parenthesis.

    However, I wonder if you can do this with a script pretty easily.

    statusMap = [
      "Heat": 1,
      "Cool": 2,
      "Vent": 3,
      "On Fire": 4,
      "This is OK": 5,
      "Batman riding an elephant": 6,
      "Day after tomorrow": 7
    ]
    data = new URL("https://myACunit/metrics").getText()
    value = data.tokenize(":")[1]
    println("mode: ${statusMap[value]")

    Then you'd only have one datapoint and that one datapoint would have an integer value depending on the mode returned.

  • Anonymous's avatar
    Anonymous

    Groovy can't access the normal datapoints, but it has the output of the script. So you could use Groovy to loop through all the lines, splitting on the ":" and grabbing the datapoint name and value into a map. 

    Nested if statements are definitely possible. Most likely there's a problem with opening/closing parenthesis.

    However, I wonder if you can do this with a script pretty easily.

    statusMap = [
      "Heat": 1,
      "Cool": 2,
      "Vent": 3,
      "On Fire": 4,
      "This is OK": 5,
      "Batman riding an elephant": 6,
      "Day after tomorrow": 7
    ]
    data = new URL("https://myACunit/metrics").getText()
    value = data.tokenize(":")[1]
    println("mode: ${statusMap[value]")

    Then you'd only have one datapoint and that one datapoint would have an integer value depending on the mode returned.

    • marting's avatar
      marting
      Icon for Neophyte rankNeophyte

      Thanks Stuart!  You were right: I must've had one too many/few parentheses/commas sprinkled in...  Got the expression to work by doing the following:

      if(eq(ZoneModeHeat,1),5,  if(eq(ZoneModeDry,1),4,  if(eq(ZoneModeFan,1),3,  if(eq(ZoneModeCool,1),2,  if(eq(ZoneModeAuto,1),1,0)  )  )  )  )

      If I get the time, might look at converting to groovy as that would be significantly easier to read.