Let’s there is a device that sends an alarm like this:
POST /alarm/alarms
{
"source": {
"id": "12345"
},
"type": "c8y_HighTemperatureAlarm",
"text": "Machine temperature too high",
"severity": "MAJOR",
"time": "2022-05-18T12:00:00.000Z",
"c8y_TemperatureInfo": {
"currentValue": 90,
"thresholdValue": 70
}
}
The HTTP response when creating this alarm contains the created object including its ID. The device records this ID of later usage. Once the alarm state is resolved the device should clear the alarm it raised earlier like so using the remembered alarm ID from earlier.
PUT /alarm/alarms/<alarmID>
{
"status": "CLEARED"
}
In order to achieve the same flow using SmartREST 1 the device requires a template collection with at least 3 templates like this:
10,100,POST,/alarm/alarms,application/json,application/json,%%,UNSIGNED NOW UNSIGNED,"{""source"":{""id"":""%%""},""type"":""c8y_HighTemperatureAlarm"",""text"":""Machine temperature too high"",""severity"":""MAJOR"",""time"":""%%"",""c8y_TemperatureInfo"":{""currentValue"":%%,""thresholdValue"":70}}"
10,101,PUT,/alarm/alarms/%%,application/json,,%%,UNSIGNED,"{""status"":""CLEARED""}"
11,1000,,$.c8y_TemperatureInfo,id
Then the device may create the alarm using the 100 template like this:
100,12345,,90
Creating this object will trigger the response template 1000 because it matches the response of created data. Then the device will receive back this message:
1000,1,23456
I’m using ‘23456’ here as example for the returned alarm ID that the 1000 response template extracts from the alarm creation response. As described in the REST API example the device records this alarm ID for later usage when the alarm state is resolved. Then it can use the 101 template to clear the alarm like so:
101,23456