Variable Object

Describes the JSON object of a Variable.

A Variable in NanoView can store one or more data points. Variables are the most granular entity and can either be raw (sensor or manually sent data) or synthetic (computed from an expression using other variables).

PropertyTypeDescription
idStringID of Variable
labelStringLabel of Variable
nameStringName of Variable
descriptionStringDescription of Variable
deviceObjectThe Device this Variable belongs to. Contains id, label, name, url, and createdAt.
tagsString ArrayTags of Variable
propertiesObjectProperties of Variable. See Properties object below.
typeStringVariable type. Can be raw or synthetic. See Variable Types below.
unitStringUnit of measurement for the Variable (e.g. °C, m/s, %). Can be null.
syntheticExpressionStringMathematical expression used to compute the variable's value. Only applicable when type is synthetic. Empty string for raw variables.
createdAtStringDate the Variable was created (ISO 8601 format).
lastValueObjectThe most recent data point sent to the Variable. See lastValue object below.
lastActivityNumberUnix timestamp (ms) of the Variable's last recorded activity. Can be null if no data has been received.
urlStringURL of Variable
valuesUrlStringURL to access the Variable's historical data points via the v1.6 API.

Variable

{
    "url": "https://nanoview-api.wellairsolutions.com/api/v2.0/variables/67253b189bcbc904dc48cd4c",
    "id": "67253b189bcbc904dc48cd4c",
    "label": "temp",
    "name": "Temperature",
    "description": "",
    "device": {
        "url": "https://nanoview-api.wellairsolutions.com/api/v2.0/devices/67253b189bcbc904dc48cd4d",
        "id": "67253b189bcbc904dc48cd4d",
        "label": "614385e15e4b40df8ecba871629a3c08",
        "name": "Itagüí",
        "createdAt": "2024-11-01T20:33:28.202904Z"
    },
    "tags": [],
    "properties": {
        "_icon": "thermometer-half",
        "_color": "#e9c46a",
        "_previous_variable_label": "temp"
    },
    "type": "raw",
    "unit": "°C",
    "syntheticExpression": "",
    "createdAt": "2024-11-01T20:33:28.319179Z",
    "lastValue": {
        "value": 17.84,
        "timestamp": 1771878262000,
        "context": {},
        "created_at": 1771878563537
    },
    "lastActivity": 1771878563539,
    "valuesUrl": "https://nanoview-api.wellairsolutions.com/api/v1.6/variables/67253b189bcbc904dc48cd4e/values"
}

Variable Types

The type field determines how a variable receives its value:

  • raw: The variable stores data points sent directly from a device or external source (e.g. sensors, API calls). The syntheticExpression field will be an empty string.
  • synthetic: The variable's value is automatically computed from a mathematical expression referencing other variables (indicated by {{variable_id}} placeholders in syntheticExpression). Synthetic variables do not receive raw data.

Synthetic variable example:

{
    "type": "synthetic",
    "syntheticExpression": "{{67253b189bcbc904dc48cd51}} * {{67253b189bcbc904dc48cd4f}}"
}

Properties object

The properties key object describes the following about a Variable:

  • Color.
  • Icon.
  • Timezone for data aggregation.
PropertyTypeDescription
_iconStringFont Awesome v6.1.1 icon name assigned to the variable. For example, "thermometer-half".
_colorStringVariable color in hexadecimal format. For example, "#e9c46a".
timezoneStringTimezone used for data aggregation and display. Uses IANA timezone format. For example, "America/Bogota".
_scaleNumberFactor every new value is multiplied by before it is stored. See Scaling.
_offsetNumberAmount added to every new value (after _scale) before it is stored. See Scaling.
_input_rangeArrayTwo input reference points, [input_1, input_2], used to compute _scale and _offset.
_output_rangeArrayThe two values those inputs should become, [output_1, output_2].

Properties object example

{
    "properties": {
        "_icon": "thermometer-half",
        "_color": "#e9c46a",
        "timezone": "America/Bogota",
    }
}

Scaling (_scale and _offset)

Every new value the Variable receives is transformed before it is stored:

stored value = received value × _scale + _offset
  • Both keys are optional: with only _scale the value is multiplied, with only _offset it is shifted, and with neither (or null) it is stored as received.
  • It is applied at ingestion and is not retroactive: changing or removing _scale or _offset does not modify values already stored.
  • Values sent to POST /api/v1.6/devices/<device_label>/_/bulk/values are not scaled.

Instead of _scale and _offset you can set two reference points: with _input_range: [4, 20] and _output_range: [0, 100], NanoView computes _scale: 6.25 and _offset: -25 when the Variable is saved.

🚧

The ranges take precedence

While _input_range and _output_range are both set, they overwrite _scale and _offset on every save. To set _scale and _offset directly, set the ranges to null in the same request.

To set the scaling, update the Variable with PATCH. In a PATCH request the properties object is merged with the existing one: only the keys you send change and the rest are kept.

$ curl -X PATCH 'https://nanoview-api.wellairsolutions.com/api/v2.0/variables/67253b189bcbc904dc48cd4c/' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: oaXBo6ODhIjPsusNRPUGIK4d72bc73' \
 -d '{"properties": {"_scale": 1.8, "_offset": 32}}'

lastValue object

The lastValue object contains the most recent data point recorded for the Variable. It will be an empty object {} if no data has been received yet.

PropertyTypeDescription
valueNumberThe numeric value of the last data point.
timestampNumberUnix timestamp (ms) indicating when the value was measured or originated.
contextObjectArbitrary key-value pairs sent alongside the value for additional metadata (e.g. cardinal direction, icon URLs). Can be an empty object {}.
created_atNumberUnix timestamp (ms) indicating when the data point was stored in NanoView.

lastValue object example

{
    "lastValue": {
        "value": 10.0,
        "timestamp": 1771878262000,
        "context": {
            "cardinal_direction": "N"
        },
        "created_at": 1771878563540
    }
}