Device Metadata

In order to keep user-specific data stored on a device, it's possible to modify the device's metadata field. This is an object that can be used to stored whatever data you'd like to store about the device, as a map of string to string. For example, here's a device with some metadata indicating a battery status:

{
    "name": "Demo Temp Sensor - sensor_1",
    "unique_id": "sensor_1",
    "metadata": {
      "battery_status": "ok"
    }
  }

This field could be updated by a user of the API so that the battery_status data is stored on the device for others to see.

However another way to have this action taken automatically is to use a Policy. This type of policy only makes sense as a cloud (as opposed to edge) rule; thus the cloud_rule:true in the example below. This example would interpret the BatteryTemp field of an incoming report from a device into a metadata key/value of 'battery_status':'poor' and update the metadata on the device record.

{
   "active":true,
   "description":"Set Battery Status from Temp",
   "cloud_rule":true,
   "device_ids":[
		...
   ],
   "device_type_ids":[
		...
   ],
   "rule_condition":{
      "type":"greater_than_equal",
      "property":"BatteryTemp",
      "value":"35"
   },
   "then_actions":[
      {
         "type":"update_device_metadata",
         "metadata_key":"battery_status",
         "body_template":"poor"
      }
   ],
   "else_actions":[]
}