{
  "ruleChain": {
    "name": "Rotating System Controller",
    "type": "CORE",
    "firstRuleNodeId": null,
    "root": false,
    "debugMode": false,
    "configuration": null,
    "additionalInfo": null
  },
  "metadata": {
    "version": 8,
    "firstNodeIndex": 0,
    "nodes": [
      {
        "type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode",
        "name": "Message Type Switch",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "version": 0
        },
        "additionalInfo": {
          "layoutX": 255,
          "layoutY": 50
        }
      },
      {
        "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
        "name": "Save Time Series",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "defaultTTL": 0,
          "processingSettings": {
            "type": "ON_EVERY_MESSAGE"
          }
        },
        "additionalInfo": {
          "layoutX": 477,
          "layoutY": 150
        }
      },
      {
        "type": "org.thingsboard.rule.engine.metadata.TbGetRelatedAttributeNode",
        "name": "Fetch Wind Sensor Telemetry",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "relationsQuery": {
            "direction": "FROM",
            "maxLevel": 1,
            "filters": [
              {
                "relationType": "Uses",
                "entityTypes": [
                  "DEVICE"
                ]
              }
            ]
          },
          "dataMapping": {
            "windDirection": "windDirection"
          },
          "dataToFetch": "LATEST_TELEMETRY",
          "fetchTo": "METADATA"
        },
        "additionalInfo": {
          "layoutX": 277,
          "layoutY": 277
        }
      },
      {
        "type": "org.thingsboard.rule.engine.transform.TbTransformMsgNode",
        "name": "New RPC Message",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "var newMsg = {};\nvar value = Math.abs(msg.turbineDirection - metadata.windDirection);\nif ((value < 180 && msg.turbineDirection < metadata.windDirection)||\n    (value > 180 && msg.turbineDirection > metadata.windDirection)) {\n    newMsg.method = 'spinLeft';\n}\n\nif ((value < 180 && msg.turbineDirection > metadata.windDirection)||\n    (value > 180 && msg.turbineDirection < metadata.windDirection)) {\n    newMsg.method = 'spinRight';\n\n}\nnewMsg.params = Math.round(value * 100) / 100;\nreturn {msg: newMsg, metadata: metadata, msgType: msgType};",
          "tbelScript": "newMsg = {};\n\nif (msg.containsKey(\"turbineDirection\") && metadata.containsKey(\"windDirection\")) {\n    value = msg.turbineDirection - metadata.windDirection;\n\n    if (value < 0) {\n        value = -value;\n    }\n\n    if ((value < 180 && msg.turbineDirection < metadata.windDirection) ||\n        (value > 180 && msg.turbineDirection > metadata.windDirection)) {\n        newMsg.method = \"spinLeft\";\n    }\n\n    if ((value < 180 && msg.turbineDirection > metadata.windDirection) ||\n        (value > 180 && msg.turbineDirection < metadata.windDirection)) {\n        newMsg.method = \"spinRight\";\n    }\n\n    newMsg.params = value;\n}\n\nreturn {msg: newMsg, metadata: metadata, msgType: msgType};"
        },
        "additionalInfo": {
          "description": null,
          "layoutX": 276,
          "layoutY": 376
        }
      },
      {
        "type": "org.thingsboard.rule.engine.filter.TbJsFilterNode",
        "name": "Check Request Validity",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "return typeof msg.method !== 'undefined';",
          "tbelScript": "return msg.containsKey(\"method\") && msg.method != null;"
        },
        "additionalInfo": {
          "description": null,
          "layoutX": 275,
          "layoutY": 477
        }
      },
      {
        "type": "org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode",
        "name": "Rotating System",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "timeoutInSeconds": 60
        },
        "additionalInfo": {
          "layoutX": 276,
          "layoutY": 576
        }
      },
      {
        "type": "org.thingsboard.rule.engine.transform.TbChangeOriginatorNode",
        "name": "Change Originator to Wind Turbine",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "originatorSource": "RELATED",
          "relationsQuery": {
            "direction": "TO",
            "maxLevel": 1,
            "filters": [
              {
                "relationType": "Contains",
                "entityTypes": [
                  "ASSET"
                ]
              }
            ]
          },
          "preserveOriginatorIfCustomer": true
        },
        "additionalInfo": {
          "description": null,
          "layoutX": 678,
          "layoutY": 277
        }
      },
      {
        "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
        "name": "Save to Wind Turbine",
        "debugSettings": {
          "failuresEnabled": true,
          "allEnabled": false,
          "allEnabledUntil": 1776178803731
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "defaultTTL": 0,
          "processingSettings": {
            "type": "ON_EVERY_MESSAGE"
          }
        },
        "additionalInfo": {
          "description": null,
          "layoutX": 677,
          "layoutY": 378
        }
      }
    ],
    "connections": [
      {
        "fromIndex": 0,
        "toIndex": 1,
        "type": "Post telemetry"
      },
      {
        "fromIndex": 1,
        "toIndex": 2,
        "type": "Success"
      },
      {
        "fromIndex": 1,
        "toIndex": 6,
        "type": "Success"
      },
      {
        "fromIndex": 2,
        "toIndex": 3,
        "type": "Success"
      },
      {
        "fromIndex": 3,
        "toIndex": 4,
        "type": "Success"
      },
      {
        "fromIndex": 4,
        "toIndex": 5,
        "type": "True"
      },
      {
        "fromIndex": 6,
        "toIndex": 7,
        "type": "Success"
      }
    ],
    "ruleChainConnections": null
  }
}