Let me address all three aspects of your rules engine challenge systematically:
Logical Grouping in Rule Conditions:
Your condition syntax has a subtle precedence issue. The rules engine evaluates left-to-right with AND taking precedence over OR. Your current rule:
(temperature > 85 AND vibration > 7.5) OR (pressure < 20 AND temperature > 80)
This is actually parsed as:
((temperature > 85 AND vibration > 7.5) OR pressure < 20) AND temperature > 80
To fix the logical grouping, be explicit with your parentheses and consider breaking complex rules into stages. Use this corrected syntax:
rule_stage_1: (temperature > 85 AND vibration > 7.5)
rule_stage_2: (pressure < 20 AND temperature > 80)
final_rule: (rule_stage_1 OR rule_stage_2)
This creates a rule chain where each stage evaluates cleanly and you avoid precedence ambiguity.
Attribute Presence in Event Payload:
As others noted, your sensors send separate payloads. The rules engine requires all referenced attributes to be present in a single event. You have two solutions:
- Edge aggregation (recommended): Implement a 10-second collection window on your gateway:
aggregation.window.seconds=10
aggregation.strategy=last_value
emit.on.window.close=true
- Cloud-side stateful rules: Use the enrichment feature to maintain device state. Create a virtual attribute that tracks the last known value of each sensor:
virtual.temperature.ttl=15000
virtual.vibration.ttl=15000
virtual.pressure.ttl=15000
This keeps a 15-second memory of each reading. Your rule then evaluates against these virtual attributes which are always present.
Testing with Rules-Engine Utility:
Always validate rules before deployment. In Rules Designer, use the test payload feature:
- Navigate to Rules Designer → Your Rule → Test
- Construct a complete test payload with all attributes:
{
"temperature": 86,
"vibration": 8.2,
"pressure": 18,
"timestamp": "2025-03-05T16:00:00Z"
}
- Click “Evaluate Rule” and check the execution trace
- The trace shows you exactly which conditions passed/failed and why
In your case, I suspect you’ll find that when you test with a complete payload, the rule fires correctly. This confirms the issue is payload completeness, not rule logic.
For your specific use case (equipment failure detection), I strongly recommend the edge aggregation approach. It’s more deterministic, reduces cloud processing costs, and ensures you never miss correlated conditions due to timing issues. The 5-10 second latency is negligible for predictive maintenance scenarios.