Let me provide a complete solution addressing all three focus areas:
Device Shadow Attribute Mapping:
Your shadow structure must align with how the rule references attributes. Based on your JSON example, the correct path in rule conditions is state.reported.dataUsageMB. Update your device shadow mapping to ensure attributes are consistently placed under state.reported for all devices. You can verify this by checking a few device shadows in the console.
Rule Condition Syntax:
The complete rule condition should be:
state.reported.dataUsageMB > 1000
Make sure there are no extra spaces or special characters. Also verify the data type - if dataUsageMB is stored as a string instead of a number in the shadow, the comparison will fail. You may need to cast it: toNumber(state.reported.dataUsageMB) > 1000.
Billing Event Action Configuration:
Your action configuration needs these parameters:
{
"actionType": "GENERATE_BILLING_EVENT",
"eventType": "USAGE_EVENT",
"serviceId": "iot-data-service-01",
"quantityExpression": "state.reported.dataUsageMB",
"deviceIdExpression": "deviceId",
"metadataExpressions": {
"timestamp": "state.reported.timestamp",
"thresholdExceeded": "true"
}
}
The quantityExpression is critical - it tells the billing system how much to charge for. The serviceId must match an existing service definition in your monetization configuration that’s linked to your ERP billing module. The metadataExpressions are optional but useful for billing audit trails.
After making these changes, test with the rule simulator first, then enable the rule and trigger a device shadow update that exceeds the threshold. Check the monetization event log (not just the billing console) to see if events are being generated but failing at the ERP integration stage. If events appear in the log but not in billing, the issue is with the service definition or ERP connection, not the rule itself.
One more thing: if you’re using daily aggregation, make sure your rule evaluation window aligns with your billing period. Set the evaluation frequency to “On every shadow update” rather than scheduled intervals to catch threshold crossings immediately.