{
  "ruleChain": {
    "name": "Equipment Health Analysis",
    "type": "CORE",
    "firstRuleNodeId": null,
    "root": false,
    "debugMode": false,
    "configuration": null,
    "additionalInfo": {
      "description": ""
    }
  },
  "metadata": {
    "version": 15,
    "firstNodeIndex": 6,
    "nodes": [
      {
        "type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode",
        "name": "Save Timeseries",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "defaultTTL": 0,
          "useServerTs": false,
          "processingSettings": {
            "type": "ON_EVERY_MESSAGE"
          }
        },
        "additionalInfo": {
          "layoutX": 991,
          "layoutY": 156
        }
      },
      {
        "type": "org.thingsboard.rule.engine.telemetry.TbMsgAttributesNode",
        "name": "Save Client Attributes",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 3,
        "configuration": {
          "processingSettings": {
            "type": "ON_EVERY_MESSAGE"
          },
          "scope": "CLIENT_SCOPE",
          "notifyDevice": false,
          "sendAttributesUpdatedNotification": false,
          "updateAttributesOnlyOnValueChange": true
        },
        "additionalInfo": {
          "layoutX": 710,
          "layoutY": 91
        }
      },
      {
        "type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode",
        "name": "Message Type Switch",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "version": 0
        },
        "additionalInfo": {
          "layoutX": 373,
          "layoutY": 311
        }
      },
      {
        "type": "org.thingsboard.rule.engine.action.TbLogNode",
        "name": "Log RPC from Device",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);",
          "tbelScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
        },
        "additionalInfo": {
          "layoutX": 703,
          "layoutY": 385
        }
      },
      {
        "type": "org.thingsboard.rule.engine.action.TbLogNode",
        "name": "Log Other",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "jsScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);",
          "tbelScript": "return '\\nIncoming message:\\n' + JSON.stringify(msg) + '\\nIncoming metadata:\\n' + JSON.stringify(metadata);"
        },
        "additionalInfo": {
          "layoutX": 702,
          "layoutY": 446
        }
      },
      {
        "type": "org.thingsboard.rule.engine.rpc.TbSendRPCRequestNode",
        "name": "RPC Call Request",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "timeoutInSeconds": 60
        },
        "additionalInfo": {
          "layoutX": 701,
          "layoutY": 509
        }
      },
      {
        "type": "org.thingsboard.rule.engine.profile.TbDeviceProfileNode",
        "name": "Device Profile Node",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "persistAlarmRulesState": false,
          "fetchAlarmRulesStateOnStart": false
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 73,
          "layoutY": 307
        }
      },
      {
        "type": "org.thingsboard.rule.engine.filter.TbCheckMessageNode",
        "name": "Rolling data present?",
        "debugSettings": null,
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "messageNames": ["vibrationRecords", "temperatureRecords", "acousticDevRecords"],
          "metadataNames": [],
          "checkAllKeys": true
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 703,
          "layoutY": 256
        }
      },
      {
        "type": "org.thingsboard.rule.engine.deduplication.TbMsgDeduplicationNode",
        "name": "Deduplicate API calls",
        "debugSettings": {
          "failuresEnabled": false,
          "allEnabled": false,
          "allEnabledUntil": 0
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 1,
        "configuration": {
          "interval": 5,
          "strategy": "LAST",
          "maxPendingMsgs": 100,
          "maxRetries": 3
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 990,
          "layoutY": 350
        }
      },
      {
        "type": "org.thingsboard.rule.engine.ai.TbAiNode",
        "name": "AI request",
        "debugSettings": {
          "failuresEnabled": false,
          "allEnabled": false,
          "allEnabledUntil": 0
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "modelId": {
            "entityType": "AI_MODEL",
            "id": "566500f0-7906-11f0-a9cd-c57747b49143"
          },
          "systemPrompt": "You are an AI-powered predictive maintenance assistant. \nYour task is to process raw sensor readings from industrial equipment, detect early signs of mechanical issues, and generate a concise, plain-language summary for maintenance teams. \n\n- Input data will include time-stamped readings for vibration (mm/s), temperature (°C), and acoustic signature (Hz spectrum).  \n- The AI should analyze the data against provided reference baselines and past incident patterns (included in this prompt).  \n- Detect anomalies such as bearing wear, misalignment, overheating, or imbalance.  \n- Provide a clear 2–3 sentence summary describing the detected condition, urgency, and recommended next step.  \n- Avoid raw data repetition; focus on actionable insights.  \n\nDo not include any text, explanations, or markdown formatting before or after the JSON output.",
          "userPrompt": "Here are the latest readings from ${deviceName}:\n\n$[*]\n\nAnalyze the data using the reference baselines and incident patterns, and provide a concise, plain-language maintenance summary.\n\nReference Baselines:  \n- Vibration: ≤ 4.5 mm/s is normal, 4.5–7.1 mm/s is warning, > 7.1 mm/s is critical.  \n- Temperature: ≤ 75°C normal, 75–85°C warning, > 85°C critical.  \n- Acoustic patterns: deviations > 15% from baseline frequencies indicate abnormal operation.  \n\nPast Incident Patterns:  \n1. Gradual increase in vibration + temperature spike → bearing wear.  \n2. Sudden vibration spike without temperature change → misalignment.  \n3. Irregular acoustic patterns + rising vibration → imbalance.\n4. Empty data arrays→ no data.\n\nIf no anomaly detected - return empty JSON object",
          "responseFormat": {
            "type": "JSON_SCHEMA",
            "schema": {
              "$schema": "http://json-schema.org/draft-07/schema#",
              "title": "IndustrialEquipmentHealthAnalysis",
              "type": "object",
              "properties": {
                "anomaly": {
                  "type": "string",
                  "description": "A short label or category for the detected anomaly, e.g., 'Bearing Wear' or 'Misalignment'."
                },
                "summary": {
                  "type": "string",
                  "description": "A human-readable summary describing the current equipment health and recommended actions."
                }
              },
              "additionalProperties": false
            }
          },
          "timeoutSeconds": 60,
          "forceAck": true
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 990,
          "layoutY": 436
        }
      },
      {
        "type": "org.thingsboard.rule.engine.filter.TbCheckMessageNode",
        "name": "Anomaly detected?",
        "debugSettings": {
          "failuresEnabled": false,
          "allEnabled": false,
          "allEnabledUntil": 0
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "messageNames": ["anomaly"],
          "metadataNames": [],
          "checkAllKeys": true
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 986,
          "layoutY": 515
        }
      },
      {
        "type": "org.thingsboard.rule.engine.action.TbCreateAlarmNode",
        "name": "Anomaly Alarm",
        "debugSettings": {
          "failuresEnabled": false,
          "allEnabled": false,
          "allEnabledUntil": 0
        },
        "singletonMode": false,
        "queueName": null,
        "configurationVersion": 0,
        "configuration": {
          "scriptLang": "TBEL",
          "alarmDetailsBuildJs": "var details = {};\nif (metadata.prevAlarmDetails) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    delete metadata.prevAlarmDetails;\n    //now metadata is the same as it comes IN this rule node\n}\n\n\nreturn details;",
          "alarmDetailsBuildTbel": "var details = {};\nif (metadata.prevAlarmDetails != null) {\n    details = JSON.parse(metadata.prevAlarmDetails);\n    //remove prevAlarmDetails from metadata\n    metadata.remove('prevAlarmDetails');\n    //now metadata is the same as it comes IN this rule node\n}\n\ndetails.msg = msg.summary;\n\nreturn details;",
          "useMessageAlarmData": false,
          "overwriteAlarmDetails": false,
          "alarmType": "$[anomaly]",
          "severity": "CRITICAL",
          "propagate": false,
          "relationTypes": [],
          "propagateToOwner": false,
          "propagateToTenant": false,
          "dynamicSeverity": false
        },
        "additionalInfo": {
          "description": "",
          "layoutX": 990,
          "layoutY": 588
        }
      }
    ],
    "connections": [
      {
        "fromIndex": 2,
        "toIndex": 1,
        "type": "Post attributes"
      },
      {
        "fromIndex": 2,
        "toIndex": 3,
        "type": "RPC Request from Device"
      },
      {
        "fromIndex": 2,
        "toIndex": 4,
        "type": "Other"
      },
      {
        "fromIndex": 2,
        "toIndex": 5,
        "type": "RPC Request to Device"
      },
      {
        "fromIndex": 2,
        "toIndex": 7,
        "type": "Post telemetry"
      },
      {
        "fromIndex": 6,
        "toIndex": 2,
        "type": "Success"
      },
      {
        "fromIndex": 7,
        "toIndex": 0,
        "type": "False"
      },
      {
        "fromIndex": 7,
        "toIndex": 8,
        "type": "True"
      },
      {
        "fromIndex": 8,
        "toIndex": 9,
        "type": "Success"
      },
      {
        "fromIndex": 9,
        "toIndex": 10,
        "type": "Success"
      },
      {
        "fromIndex": 10,
        "toIndex": 11,
        "type": "True"
      }
    ],
    "ruleChainConnections": null
  }
}
