Sammenligne to variabler

Litt stuck her…

Har noen en idé om hvordan (hvis mulig) å sammenligne to variabler (float)

Jeg tenker typ: IF {variabel1} < {variabel2} THEN…

Currently not possible using IF node but will be added in next release. In meantime, there is a workaround using Transform->Calculate (Data operations - docs), it allows compare operation between multiple variables and the result (true/false) can be assigned to another variable.

1 Like

Thanks for your answer.
I tried to work it out with transform node, but cannot find out how to add the second variable.

Only input variable and result variable

Variables can be used directly in expressions, for example :

{
  "Id": "NxOvbRR0iSwpj3i",
  "ClassId": "NxOvbRR0iSwpj3i",
  "Author": "",
  "Version": 0,
  "CreatedAt": "2021-02-28T18:54:49.008973141+01:00",
  "UpdatedAt": "2021-02-28T18:54:49.008973141+01:00",
  "Name": "Transform-calc-demo",
  "Group": "test",
  "Nodes": [
    {
      "Id": "1",
      "Type": "trigger",
      "Label": "Button",
      "SuccessTransition": "2",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "pt:j1/mt:evt/rt:dev/rn:zigbee/ad:1/sv:scene_ctrl/ad:9_1",
      "Service": "scene_ctrl",
      "ServiceInterface": "evt.scene.report",
      "Config": {
        "Timeout": 0,
        "ConnectorID": "",
        "ValueFilter": {
          "Value": null,
          "ValueType": "string"
        },
        "PropFilterName": "",
        "PropFilterValue": "",
        "ValueJPath": "",
        "ValueJPathResultType": "",
        "InputVariableType": "",
        "IsValueFilterEnabled": false,
        "RegisterAsVirtualService": false,
        "LookupServiceNameAndLocation": false,
        "VirtualServiceGroup": "",
        "VirtualServiceProps": null
      },
      "Ui": {
        "x": 319,
        "y": 213,
        "nodeType": ""
      },
      "TypeAlias": "Trigger",
      "LastValue": "toggle"
    },
    {
      "Id": "2",
      "Type": "set_variable",
      "Label": "Set counter1",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "SuccessTransition": "3",
      "ErrorTransition": "",
      "Config": {
        "Name": "counter1",
        "UpdateGlobal": false,
        "UpdateInputMsg": false,
        "DefaultValue": {
          "Value": "5",
          "ValueType": "int"
        }
      },
      "Ui": {
        "x": 295,
        "y": 423,
        "nodeType": ""
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "3",
      "Type": "set_variable",
      "Label": "Set counter2",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "SuccessTransition": "4",
      "ErrorTransition": "",
      "Config": {
        "Name": "counter2",
        "UpdateGlobal": false,
        "UpdateInputMsg": false,
        "DefaultValue": {
          "Value": 10,
          "ValueType": "int"
        }
      },
      "Ui": {
        "x": 277,
        "y": 606,
        "nodeType": ""
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "4",
      "Type": "transform",
      "Label": "Set result",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "SuccessTransition": "5",
      "ErrorTransition": "",
      "Config": {
        "TargetVariableName": "compResult",
        "TargetVariableType": "bool",
        "IsTargetVariableGlobal": false,
        "TransformType": "calc",
        "Rtype": "var",
        "IsRVariableGlobal": false,
        "IsLVariableGlobal": false,
        "Expression": "counter1<counter2",
        "RValue": {
          "ValueType": "int",
          "Value": 0
        },
        "RVariableName": "",
        "LVariableName": "",
        "ValueMapping": [],
        "XPathMapping": [],
        "Template": ""
      },
      "Ui": {
        "x": 269,
        "y": 840,
        "nodeType": ""
      },
      "TypeAlias": "Transform"
    },
    {
      "Id": "5",
      "Type": "log_action",
      "Label": "Log result",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "SuccessTransition": "",
      "ErrorTransition": "",
      "Config": {
        "VariableName": "compResult",
        "IsVariableGlobal": false,
        "LogLevel": "info",
        "Text": ""
      },
      "Ui": {
        "x": 256,
        "y": 1048,
        "nodeType": ""
      },
      "TypeAlias": "Log action"
    }
  ],
  "Settings": null,
  "IsDisabled": false,
  "IsDefault": false,
  "ParallelExecution": ""
}

1 Like

Great, thank you.

Worked as expected :slight_smile:

1 Like