Sensor Data APIs provide comprehensive access to sensor readings, energy consumption data, and device analytics from IoT devices. These APIs enable real-time monitoring, historical analysis, and energy management for devices equipped with sensor capabilities.
Prerequisites: Device Sensor Capabilities
Before using sensor data APIs, devices must meet specific requirements:
1. Required Device Traits
Devices must include the Sensor trait in their supported traits list to provide sensor data.
2. Required Device Attributes
Devices must have a sensorProfile attribute that defines the types of sensors available and their configurations.
Available Sensor Types
The system supports a comprehensive range of sensor types as defined in the device's sensorProfile. Each sensor type has specific Min/Max ranges and units:
Environmental Sensors
temp- Temperature sensor (typically °C)rh- Relative humidity sensor (%)lux- Illumination/light sensor (lux)noise- Noise level sensor (dB)
Air Quality Sensors
pm2_5- PM2.5 particulate matter sensorpm1_0- PM1.0 particulate matter sensorpm10- PM10 particulate matter sensorco- Carbon monoxide sensorco2- Carbon dioxide sensorhcho- Formaldehyde sensorh2s- Hydrogen sulfide sensornh3- Ammonia sensoro2- Oxygen sensoro3- Ozone sensortvoc- Total volatile organic compounds sensor
Power and Electrical Sensors
watt- Power consumption sensor (Watts)watt_hour- Energy consumption sensor (kWh).watt_houris accumulated valuevoltage- Voltage sensor (V)current- Current sensor (mA or A)power- General power sensorapparent_power- Apparent power sensorreal_power- Real power sensorreactive_power- Reactive power sensor
Motion and Physical Sensors
mr- Magnetic reed sensorvib- Vibration sensor
Health and Biometric Sensors
sbp- Systolic blood pressuredbp- Diastolic blood pressuremap- Mean arterial pressurepulse- Pulse rate sensorglucose- Blood glucose sensorchol- Cholesterol sensorbody_temp- Body temperature sensorheight- Height measurementweight- Weight measurementbmi- Body mass indexbmr- Basal metabolic ratebf- Body fat percentagebm- Body muscle percentagebn- Body bone percentagebw- Body water percentagevfr- Visceral fat ratingamr- Active metabolic ratema- Metabolic agespo2- Blood oxygen saturation
System and Maintenance Sensors
fan_hour- Fan operation hours (for filter replacement indicators)bucket- Water bucket level sensorfilter- Filter status sensorfailed_sensors- Failed sensors indicatorrssi- Signal strength indicatortds- Total dissolved solids sensor
Device Discovery and Validation
Identifying Sensor-Capable Devices
Use the GetGroupDevices API to discover devices with sensor capabilities:
curl -X POST "https://api.ultroncloud.com/usr/v5/GetGroupDevices" \
-H "X-Api-Key: YOUR_API_KEY" \
-H "Ultron-Cloud-Appid: YOUR_APP_ID" \
-H "Content-Type: application/json" \
-d '{
"groupId": "YOUR_LOCATION_ID"
}'Response Analysis for Sensor Devices
{
"result": 0,
"devices": {
"SMART_PLUG_001": {
"sn": "SMART_PLUG_001",
"displayName": "Living Room Smart Plug",
"activated": true,
"models": {
"Ultron Device": {
"type": "ULTRON",
"traits": [
"UltronCommand", "BluetoothGateway", "ReportState",
"UltronConfig"
],
"disabled": false,
"attrs": [
{"name": "rebootTime", "value": 20},
{"value": 60, "name": "fwUpgradeTime"},
{"value": true, "name": "iotConfigurableIntervals"},
{
"value": { "1": ["OnOff"] },
"name": "schedulable"
},
{"name": "schedulableVersion", "value": 1},
{"name": "periodicity", "value": true},
{"name": "aperiodicity", "value": true},
{
"name": "supportDefaultActions",
"value": {
"1": {
"cmdNames" : ["OnOff" ],
"situations": ["power", "network"]
}
}
}
]
},
"1": {
"type": "SWITCH",
"traits": ["Sensor", "OnOff", "CustomModes"],
"disabled": false,
"attrs": [
{
"name": "sensorProfile", // target attribute, valid for all sensor data APIs
"value": {
"current" : {"Min": 0, "Max": 20000, "Unit": "mA" },
"voltage" : {"Min": 0, "Max": 240, "Unit": "V" },
"watt_hour" : {"Min": 0, "Max": 50000, "Unit": "kWh" },
"watt" : {"Min": 0, "Max": 4800, "Unit": "Watt"},
"apparent_power": {"Min": 0, "Max": 4800, "Unit": "VA" }
}
},
{"name": "intermittent", "value": true},
{
"name": "timeStepRange",
"value": {"max": 86400, "min": 0.1, "step": 0.1}
},
{
"name": "availableCustomModes",
"value": [
{ "name": "reset1", "settings": ["0"], "ordered": true }
]
}
]
}
},
"createdTime": "2023-01-01T00:00:00Z"
},
"TEMP_SENSOR_001": {
"sn": "TEMP_SENSOR_001",
"displayName": "Bedroom Temperature Sensor",
"activated": true,
"models": {
"temp_main": {
"type": "SENSOR",
"traits": ["Sensor", "TemperatureControl"],
"nickname": "Temperature Sensor",
"disabled": false,
"attrs": [
{
"name": "sensorProfile", // target attribute, valid for all sensor data APIs
"value": {
"temp": {"Min": -40, "Max": 85, "Unit": "°C"},
"rh" : {"Min": 0, "Max": 100, "Unit": "%" }
}
}
]
}
},
"createdTime": "2023-01-01T00:00:00Z"
}
}
}
Understanding Accumulated Values
Certain sensor types, such as watt_hour (Energy), provide accumulated values rather than instantaneous readings.
Energy Consumption (watt_hour)
The watt_hour sensor represents the total energy consumed by the device since its last internal reset or activation.
- Accumulated Total: The value returned is the current meter reading.
- Calculating Usage: To determine the energy used during a specific period, subtract the minimum value (start of period) from the maximum value (end of period):
Usage ≈ Max(Value) - Min(Value)
- Reset handling: If the device's internal counter resets (e.g., due to a factory reset or power cycle depending on hardware), the value will start from 0 again.