Last active
June 7, 2024 13:07
-
-
Save ashvayka/f67f9415c625e8a2d12340e18248111f to your computer and use it in GitHub Desktop.
Rule Chain examples for Rule Node documentation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ruleChain": { | |
"additionalInfo": { | |
"description": "" | |
}, | |
"name": "Asset profile switch example", | |
"type": "CORE", | |
"firstRuleNodeId": null, | |
"root": false, | |
"debugMode": false, | |
"configuration": null, | |
"externalId": null | |
}, | |
"metadata": { | |
"firstNodeIndex": 0, | |
"nodes": [ | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 332, | |
"layoutY": 149 | |
}, | |
"type": "org.thingsboard.rule.engine.transform.TbChangeOriginatorNode", | |
"name": "To Related Asset", | |
"debugMode": true, | |
"configuration": { | |
"originatorSource": "RELATED", | |
"entityType": null, | |
"entityNamePattern": null, | |
"relationsQuery": { | |
"fetchLastLevelOnly": false, | |
"direction": "TO", | |
"maxLevel": 1, | |
"filters": [ | |
{ | |
"relationType": "Contains", | |
"entityTypes": [ | |
"ASSET" | |
] | |
} | |
] | |
} | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 653, | |
"layoutY": 150 | |
}, | |
"type": "org.thingsboard.rule.engine.filter.TbAssetTypeSwitchNode", | |
"name": "to asset rule chain", | |
"debugMode": true, | |
"configuration": { | |
"version": 0 | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 957, | |
"layoutY": 79 | |
}, | |
"type": "org.thingsboard.rule.engine.flow.TbRuleChainInputNode", | |
"name": "Freezer Room", | |
"debugMode": true, | |
"configuration": { | |
"ruleChainId": "6fe3cd50-3fc9-11ed-91a9-b9b7b84ed435" | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 957, | |
"layoutY": 234 | |
}, | |
"type": "org.thingsboard.rule.engine.flow.TbRuleChainInputNode", | |
"name": "Boiler Room", | |
"debugMode": true, | |
"configuration": { | |
"ruleChainId": "6fe3cd50-3fc9-11ed-91a9-b9b7b84ed435" | |
}, | |
"externalId": null | |
} | |
], | |
"connections": [ | |
{ | |
"fromIndex": 0, | |
"toIndex": 1, | |
"type": "Success" | |
}, | |
{ | |
"fromIndex": 1, | |
"toIndex": 2, | |
"type": "Freezer Room" | |
}, | |
{ | |
"fromIndex": 1, | |
"toIndex": 3, | |
"type": "Boiler Room" | |
} | |
], | |
"ruleChainConnections": null | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ruleChain": { | |
"additionalInfo": { | |
"description": "" | |
}, | |
"name": "Calculate Delta", | |
"type": "CORE", | |
"firstRuleNodeId": null, | |
"root": false, | |
"debugMode": false, | |
"configuration": null, | |
"externalId": null | |
}, | |
"metadata": { | |
"firstNodeIndex": null, | |
"nodes": [ | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 645, | |
"layoutY": 155 | |
}, | |
"type": "org.thingsboard.rule.engine.metadata.CalculateDeltaNode", | |
"name": "Calculate delta", | |
"debugMode": true, | |
"configuration": { | |
"inputValueKey": "pulseCounter", | |
"outputValueKey": "delta", | |
"useCache": true, | |
"addPeriodBetweenMsgs": true, | |
"periodValueKey": "periodInMs", | |
"round": 2, | |
"tellFailureIfDeltaIsNegative": true | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 313, | |
"layoutY": 154 | |
}, | |
"type": "org.thingsboard.rule.engine.debug.TbMsgGeneratorNode", | |
"name": "Generate events", | |
"debugMode": true, | |
"configuration": { | |
"msgCount": 0, | |
"periodInSeconds": 1, | |
"scriptLang": "TBEL", | |
"jsScript": "var msg = { temp: 42, humidity: 77 };\nvar metadata = { data: 40 };\nvar msgType = \"POST_TELEMETRY_REQUEST\";\n\nreturn { msg: msg, metadata: metadata, msgType: msgType };", | |
"tbelScript": "var pulseCounter = prevMsg.pulseCounter != null ? (prevMsg.pulseCounter + 10) : 100500;\nvar msg = { pulseCounter: pulseCounter};\nvar metadata = { data: 40 };\nvar msgType = \"POST_TELEMETRY_REQUEST\";\n\nreturn { msg: msg, metadata: metadata, msgType: msgType };", | |
"originatorId": null, | |
"originatorType": null | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 993, | |
"layoutY": 155 | |
}, | |
"type": "org.thingsboard.rule.engine.telemetry.TbMsgTimeseriesNode", | |
"name": "Save delta", | |
"debugMode": true, | |
"configuration": { | |
"defaultTTL": 0, | |
"skipLatestPersistence": false, | |
"useServerTs": false | |
}, | |
"externalId": null | |
} | |
], | |
"connections": [ | |
{ | |
"fromIndex": 0, | |
"toIndex": 2, | |
"type": "Other" | |
}, | |
{ | |
"fromIndex": 0, | |
"toIndex": 2, | |
"type": "Success" | |
}, | |
{ | |
"fromIndex": 1, | |
"toIndex": 0, | |
"type": "Success" | |
} | |
], | |
"ruleChainConnections": null | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ruleChain": { | |
"additionalInfo": { | |
"description": "" | |
}, | |
"name": "check alarm status example", | |
"type": "CORE", | |
"firstRuleNodeId": null, | |
"root": false, | |
"debugMode": false, | |
"configuration": null, | |
"externalId": null | |
}, | |
"metadata": { | |
"firstNodeIndex": 1, | |
"nodes": [ | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 756, | |
"layoutY": 151 | |
}, | |
"type": "org.thingsboard.rule.engine.filter.TbCheckAlarmStatusNode", | |
"name": "Is Alarm Active", | |
"debugMode": true, | |
"configuration": { | |
"alarmStatusList": [ | |
"ACTIVE_ACK", | |
"ACTIVE_UNACK" | |
] | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 360, | |
"layoutY": 150 | |
}, | |
"type": "org.thingsboard.rule.engine.filter.TbMsgTypeSwitchNode", | |
"name": "switch by message type", | |
"debugMode": true, | |
"configuration": { | |
"version": 0 | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 1097, | |
"layoutY": 104 | |
}, | |
"type": "org.thingsboard.rule.engine.action.TbLogNode", | |
"name": "Alarm Active", | |
"debugMode": false, | |
"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);" | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 1098, | |
"layoutY": 200 | |
}, | |
"type": "org.thingsboard.rule.engine.action.TbLogNode", | |
"name": "Alarm Cleared", | |
"debugMode": false, | |
"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);" | |
}, | |
"externalId": null | |
} | |
], | |
"connections": [ | |
{ | |
"fromIndex": 0, | |
"toIndex": 2, | |
"type": "True" | |
}, | |
{ | |
"fromIndex": 0, | |
"toIndex": 3, | |
"type": "False" | |
}, | |
{ | |
"fromIndex": 1, | |
"toIndex": 0, | |
"type": "Alarm Acknowledged" | |
} | |
], | |
"ruleChainConnections": null | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ruleChain": { | |
"additionalInfo": { | |
"description": "" | |
}, | |
"name": "device profile switch example", | |
"type": "CORE", | |
"firstRuleNodeId": null, | |
"root": false, | |
"debugMode": false, | |
"configuration": null, | |
"externalId": null | |
}, | |
"metadata": { | |
"firstNodeIndex": 1, | |
"nodes": [ | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 680, | |
"layoutY": 150 | |
}, | |
"type": "org.thingsboard.rule.engine.filter.TbDeviceTypeSwitchNode", | |
"name": "to device rule chain", | |
"debugMode": true, | |
"configuration": { | |
"version": 0 | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 367, | |
"layoutY": 150 | |
}, | |
"type": "org.thingsboard.rule.engine.transform.TbChangeOriginatorNode", | |
"name": "gateway to device", | |
"debugMode": false, | |
"configuration": { | |
"originatorSource": "ENTITY", | |
"entityType": "DEVICE", | |
"entityNamePattern": "$[mac]", | |
"relationsQuery": { | |
"direction": "FROM", | |
"maxLevel": 1, | |
"filters": [ | |
{ | |
"relationType": "Contains", | |
"entityTypes": [] | |
} | |
], | |
"fetchLastLevelOnly": false | |
} | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 1003, | |
"layoutY": 93 | |
}, | |
"type": "org.thingsboard.rule.engine.flow.TbRuleChainInputNode", | |
"name": "IAQ rule chain", | |
"debugMode": true, | |
"configuration": { | |
"ruleChainId": "e9c29d80-a320-11ed-9cbb-3ba3cd7edcd1" | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 1001, | |
"layoutY": 232 | |
}, | |
"type": "org.thingsboard.rule.engine.flow.TbRuleChainInputNode", | |
"name": "leak rule chain", | |
"debugMode": true, | |
"configuration": { | |
"ruleChainId": "e9c29d80-a320-11ed-9cbb-3ba3cd7edcd1" | |
}, | |
"externalId": null | |
} | |
], | |
"connections": [ | |
{ | |
"fromIndex": 0, | |
"toIndex": 2, | |
"type": "IAQ sensor" | |
}, | |
{ | |
"fromIndex": 0, | |
"toIndex": 3, | |
"type": "Leak sensor" | |
}, | |
{ | |
"fromIndex": 1, | |
"toIndex": 0, | |
"type": "Success" | |
} | |
], | |
"ruleChainConnections": null | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"ruleChain": { | |
"additionalInfo": { | |
"description": "" | |
}, | |
"name": "GPS geofencing filter", | |
"type": "CORE", | |
"firstRuleNodeId": null, | |
"root": false, | |
"debugMode": false, | |
"configuration": null, | |
"externalId": null | |
}, | |
"metadata": { | |
"firstNodeIndex": 2, | |
"nodes": [ | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 848, | |
"layoutY": 199 | |
}, | |
"type": "org.thingsboard.rule.engine.geo.TbGpsGeofencingFilterNode", | |
"name": "Close to \"Polonyna Bukov'yen\"?", | |
"debugMode": true, | |
"configuration": { | |
"latitudeKeyName": "latitude", | |
"longitudeKeyName": "longitude", | |
"perimeterType": "POLYGON", | |
"fetchPerimeterInfoFromMessageMetadata": true, | |
"perimeterKeyName": "perimeter", | |
"centerLatitude": 50.4515652, | |
"centerLongitude": 0.5236963, | |
"range": 100, | |
"rangeUnit": "METER" | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 51, | |
"layoutY": 237 | |
}, | |
"type": "org.thingsboard.rule.engine.debug.TbMsgGeneratorNode", | |
"name": "Sheep Tracker Generator", | |
"debugMode": false, | |
"configuration": { | |
"msgCount": 0, | |
"periodInSeconds": 1, | |
"scriptLang": "TBEL", | |
"jsScript": "var msg = { temp: 42, humidity: 77 };\nvar metadata = { data: 40 };\nvar msgType = \"POST_TELEMETRY_REQUEST\";\n\nreturn { msg: msg, metadata: metadata, msgType: msgType };", | |
"tbelScript": "var msg = { latitude: 48.198618758582384, longitude: 24.65322245153503 };\nvar metadata = {};\nvar msgType = \"POST_TELEMETRY_REQUEST\";\n\nreturn { msg: msg, metadata: metadata, msgType: msgType };\n", | |
"originatorId": "9a4f4bd0-a63c-11ed-9e67-a5d1e16b2fdc", | |
"originatorType": "DEVICE" | |
}, | |
"externalId": null | |
}, | |
{ | |
"additionalInfo": { | |
"description": "", | |
"layoutX": 418, | |
"layoutY": 200 | |
}, | |
"type": "org.thingsboard.rule.engine.metadata.TbGetRelatedAttributeNode", | |
"name": "Fetch Farm Attributes", | |
"debugMode": true, | |
"configuration": { | |
"relationsQuery": { | |
"fetchLastLevelOnly": false, | |
"direction": "TO", | |
"maxLevel": 1, | |
"filters": [ | |
{ | |
"relationType": "Contains", | |
"entityTypes": [ | |
"ASSET" | |
] | |
} | |
] | |
}, | |
"telemetry": false, | |
"attrMapping": { | |
"perimeter": "perimeter" | |
} | |
}, | |
"externalId": null | |
} | |
], | |
"connections": [ | |
{ | |
"fromIndex": 1, | |
"toIndex": 2, | |
"type": "Success" | |
}, | |
{ | |
"fromIndex": 2, | |
"toIndex": 0, | |
"type": "Success" | |
} | |
], | |
"ruleChainConnections": null | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment