Attributes are properties of a device that define the data that can be reported as state against that device. State data cannot be reported against the device unless the values in the state report have first been defined as attributes. Furthermore, the format of the data per attribute must conform to the data type for the attribute.
A device’s attributes can be viewed and modified under the “Attributes” tab of a device’s configuration page.
To add new attributes to your device, scroll to the “Add Attributes” section of your device configuration page. Each attribute requires two properties (though system devices require some additional per-attribute properties not described here):
- Attribute Name must contain only uppercase and lowercase letters, numbers, and hyphens (-) and underscores (_). Attribute names must also be unique per device; however, many applications will use the same attribute name (such as “temperature”) across multiple devices. If the values are related, and you wish to perform aggregations against the data for this attribute across multiple devices, the attribute names must match across the devices.
- Data Type refers to the type of data that will be reported against the device. The default value is ”Number“.
Once your new attributes are entered, click “Update Attributes” to save the changes. Each device may have a maximum of 256 attributes.
Optionally, you may choose to include an attribute’s description and tag fields when creating new attributes by checking “Include optional description fields” beneath the rows of new attributes. (This checkbox is not present - and the optional fields are always visible - for system devices.)
When this option is checked, each new attribute you wish to add requires clicking the “Add Attribute” button above the checkbox. Selecting this option can make the act of creating new attributes a bit more tedious, so if you are creating a large number of attributes at one time and you do not intend to use the optional fields, it is best to leave this option unchecked.
When creating an attribute, you must choose a data type. The type should be determined both by the expected format of the data you will report against the attribute and how you wish to utilize and visualize that data.
Number attributes will only accept integers or floating points, positive or negative (or zero). This is the most commonly used attribute data type within the platform; number attributes can be used to store, for example, temperature and pressure information; voltage and amperage; vibration and noise; and many other types of data common to an IoT application.
Boolean attributes accept
false values in their state reports; however, Losant will accept values in other types and cast them as either truthy or falsy. Booleans are best used to answer yes or no questions, such as whether a machine is running or if a room is occupied.
GPS attributes are used specifically for tracking the position of resources in the physical world. While the raw data is reported as a string, it must adhere to one of four strict formats to be accepted as a state report:
- Decimal Degrees (latitude, longitude)
- Degrees Minutes Seconds (also known as Sexagesimal)
- NMEA GLL
- NMEA GGA
String attributes are for reporting arbitrary data whose format does not fit one of the data types described above. State reports are typically in alphanumeric characters and symbols that cannot be cast as numbers, booleans, or GPS coordinates.
After creation, you cannot change an attribute’s name or data type; if you must change an attribute’s name or data type, you must first delete the existing attribute and recreate it with the new settings.
You may, however, change an attribute’s description or tags - and for system devices, you may change its attribute calculation methods such as aggregation and child attributes. To change these properties, expand the attribute’s detail panel and make the necessary edits. Then click “Update Attributes” to save your changes.
Warning: Deleting an attribute from a device will remove all data that has been reported against that attribute for the device.
To delete an attribute, first click the “Remove” icon within the header of an existing attribute’s panel. This will display a checkbox near the form’s submission button asking you to acknowledge that this will also delete state data, which must be checked in order to proceed. Then, click the “Update Attributes” button.
System device attributes are also configured the same way as described above - each containing a unique name per device, a data type described above, and some optional descriptive information - but data is reported against those attributes in a much different manner. That calculation method is described in more detail on the Systems page.
When utilizing state data for visualization and analysis, there are a number of aggregation methods that can be applied to your raw data. However, not all aggregation methods are available for all attribute data types.
These methods can be applied to all data types:
- First: Returns the first received (oldest) data point within the aggregation bucket
- Last: Returns the last received (most recent) data point within the aggregation bucket
- Count: Returns the total number of data points within the aggregation bucket
The methods below are only available for number and boolean data types. Note that, for booleans,
true values will be cast to the number
false values will be cast to
0 when calculating these results:
- Max: Returns the maximum (highest) value of all points within the aggregation bucket
- Min: Returns the minimum (lowest) value of all points within the aggregation bucket
- Median: Returns the median (middlemost) value of all points within the aggregation bucket
- Mean: Returns the mean, or average, of all values within the aggregation bucket
- Sum: Returns the summation of all values within the aggregation bucket
- Standard Deviation: Returns the standard deviation of the aggregation bucket