update_sensor
To create, edit, or delete sensors, use the unit/update_sensor method.
Endpoint
svc=unit/update_sensor¶ms={
"itemId": <long>,
"id": <long>,
"callMode": <text>,
"unlink": <uint>,
"n": <text>,
"t": <text>,
"d": <text>,
"m": <text>,
"p": <text>,
"f": <uint>,
"c": <text>,
"vt": <uint>,
"vs": <long>,
"tbl": [
{
"x": <double>,
"a": <double>,
"b": <double>
}
]
}
Parameters
The request must contain the following parameters:
| Parameter | Description |
|---|---|
| itemId | Unit ID. |
| id | Sensor ID. Pass 0 if you want to create a sensor. |
| callMode | Action: create, update, delete. |
| unlink | Delete links with other sensors and unit parameters: 1 (yes, default), 0 (no). |
To create or update a sensor, the following parameters are also required:
| Parameter | Description |
|---|---|
| n | Name. |
| t | Type (see Sensor types). |
| d | Description. |
| m | Unit of measurement. |
| p | Parameter. |
| f | Sensor flags (see Sensor flags). |
| c | Configuration (see Sensor configuration parameters). |
| vt | Validation type (see Validation types). |
| vs | Validating sensor ID. |
| tbl | Calculation table. |
Sensor flags
| Flag | Description |
|---|---|
| 0x01 | Sensor type: instant. |
| 0x02 | Sensor type: differential. |
| 0x03 | Sensor type: differential with overflow (2 bytes). |
| 0x04 | Sensor type: switch from off to on. |
| 0x05 | Sensor type: switch from on to off. |
| 0x20 | Activate the With overflow option. Can be used for the following sensors:
If flag 0x20 isn’t set, the change delta is calculated as the absolute difference between the current and previous values. If the flag is set and the current value is lower than the previous one, the delta is equal to the current value (that is, the previous value is assumed to be 0). This flag applies to the sensor value calculation. Overflow handling for differential sensor events is set separately in overflow_limit, regardless of this flag. |
| 0x40 | Apply the lower and upper bounds after calculation. If the flag isn’t set, then each bound is applied to raw data (in the case of FLS, there are difficulties with setting lower and upper bounds for raw data). If the flag is set, then each bound is applied to calculated (processed) data. |
Sensor types
| Value | Sensor type |
|---|---|
| absolute fuel consumption | Absolute fuel consumption sensor |
| accelerometer | Accelerometer |
| alarm trigger | Alarm trigger |
| battery level | Battery level sensor |
| counter | Counter sensor |
| custom | Custom sensor |
| digital | Custom digital sensor |
| driver | Driver assignment |
| engine efficiency | Engine efficiency sensor |
| engine hours | Absolute engine hours |
| engine operation | Engine ignition sensor |
| engine rpm | Engine revolutions sensor |
| fuel level | Fuel level sensor |
| fuel level impulse sensor | Impulse fuel level sensor |
| impulse fuel consumption | Impulse fuel consumption sensor |
| instant fuel consumption | Instant fuel consumption sensor |
| mileage | Mileage sensor |
| odometer | Relative odometer |
| private mode | Private mode |
| relative engine hours | Relative engine hours |
| temperature | Temperature sensor |
| temperature coefficient | Temperature coefficient |
| trailer | Trailer assignment |
| voltage | Voltage sensor |
| weight | Weight sensor |
For further information about sensor types, see Sensor types.
Sensor configuration parameters
The following parameters are used to configure a sensor:
"{
\"act\": <bool>,
\"appear_in_popup\": <bool>,
\"battery_capacity\": <double>,
\"ci\": <object>,
\"calc_fuel\": <uint>,
\"engine_efficiency\": <array>,
\"engine_sensors\": <array>,
\"filter\": <long>,
\"fuel_params\": <object>,
\"mu\": <uint>,
\"pos\": <uint>,
\"show_time\": <bool>,
\"unbound_code\": <text>,
\"validate_driver_unbound\": <bool>,
\"do_not_show\": <bool>,
\"timeout\": <uint>,
\"uct\": <bool>,
\"lower_bound\": <double>,
\"upper_bound\": <double>,
\"overflow_limit\": <double>,
\"text_params\": <uint>,
\"show_as_percentage\": <uint>
}"
The c parameter is sent as a string containing a JSON object. Enclose the object in double quotes and escape the double quotes in its keys and values ("). See the configuration examples below.
Set sensor flags in the top-level f parameter. Don’t set c.flags directly.
| Parameter | Description |
|---|---|
| act | Sensor value calculation: 0 (based on the last unit message), 1 (based on the last unit parameters). This option uses inverted logic:
|
| appear_in_popup | Pass true to enable the Visible option, or false to disable it. |
| battery_capacity | Battery capacity of a battery level sensor, in kWh. Used together with show_as_percentage to display the battery level as a percentage. |
| ci | Custom value intervals. See the configuration examples. |
| calc_fuel | Specify a nonzero value to enable data calculation by the sensor, or 0 to disable it. For a battery level sensor, this enables battery level and charge calculation when the sensor is used with the battery_level, charge, or ev detector. |
| engine_efficiency | Array of engine efficiency sensor IDs used by an engine sensor. |
| engine_sensors | Array of engine sensor IDs used by a fuel level sensor to calculate fuel consumption. |
| filter | Redefines the filtering level for the sensor. Integer from 0 to 255. Applies a smoothing filter to the sensor value. Valid for the following sensors:
fuel_params in the configuration examples. |
| fuel_params | Settings of a fuel level or battery level sensor. See the configuration examples. |
| mu | Measurement system:
|
| pos | Sensor position in the list (count from 1). |
| show_time | Pass true to display the sensor value with the time since which this value was received, or false to hide the time. For further information, read about the Time option on the Sensors page. |
| unbound_code | For the driver or trailer assignment sensors, you can specify a custom separation code. |
| validate_driver_unbound | Validate separation: 0 (no), 1 (yes). |
| do_not_show | This parameter is used to configure the Private mode sensor. Set it to 1 to prevent the unit location data from being transmitted when the sensor is on, or 0 to allow this data to be received. |
| timeout | Timeout, seconds. |
| uct | Pass 0 to enable the Overflow by raw data option. Pass 1 to disable it. The option is available only for differential counter sensors with overflow. The option changes the order in which the calculation table is applied in reports. It doesn’t affect how overflow_limit is applied to differential sensor events. |
| lower_bound | Lower bound of valid sensor values for the calculation table. |
| upper_bound | Upper bound of valid sensor values for the calculation table. |
| overflow_limit | Value at which the sensor counter resets to zero. The system uses it to calculate differential sensor events for the following sensors:
(overflow_limit - previous value) + current value. If the limit is 0 or isn’t set, the delta is equal to the current value. The system applies this key regardless of the 0x20 flag, which controls overflow handling in the sensor value calculation. Specify the limit in processed values, that is, in the values obtained after the calculation table is applied. The uct key doesn’t affect this behavior. For impulse fuel consumption sensors, this key affects events only. To set the overflow value for fuel consumption calculation in reports, use fuel_params.maxImpulses, which corresponds to the Maximum impulses option. Unlike overflow_limit, maxImpulses is applied to raw values, before the calculation table. |
| text_params | Pass 1 to enable the Text parameters option, or 0 to disable it. |
| show_as_percentage | Pass 1 to display the battery level as a percentage of the value specified in battery_capacity, or 0 to display the value in kWh. If battery_capacity is missing or isn’t a positive number, the value is displayed in kWh. See the Convert values to % option. |
Configuration examples
In the ci parameter, each key is the lower bound of an interval, and each value describes how the sensor value is displayed in this interval:
"c":"{\"ci\":{\"0\":{\"t\":\"Off\",\"c\":16711680},\"50\":{\"t\":\"On\"}}}"
| Key | Description |
|---|---|
| t | Text displayed instead of the sensor value. |
| c | Optional text color, specified as an integer in decimal format. |
To set an interval without a lower bound, use the "-Infinity" key.
Example of passing fuel_params of a fuel level sensor:
"c":"{\"fuel_params\":{\"flags\":1728,\"ignoreStayTimeout\":20,\"minFillingVolume\":21,\"minTheftTimeout\":0,\"minTheftVolume\":15,\"filterQuality\":0,\"fillingsJoinInterval\":300,\"theftsJoinInterval\":300,\"extraFillingTimeout\":0}}"
Example of passing fuel_params of an impulse fuel consumption sensor:
"c":"{\"fuel_params\":{\"maxImpulses\":10,\"skipZero\":0}}"
Example of passing fuel_params of a battery level sensor:
"c":"{\"fuel_params\":{\"flags\":16387,\"filterQuality\":0,\"minFillingVolume\":10,\"fillingsJoinInterval\":300}}"
For a battery level sensor, the system uses the settings listed below. If you don’t pass the fuel_params object at all, the system uses the fuel settings of the unit. If you pass the object without some of the keys, the system uses the values from the table.
| Key | Description |
|---|---|
| flags | Flags of charge detection and filtering. The values are the same as for a fuel level sensor. For the list, see unit/get_fuel_settings. If you don’t specify this key, the system uses 1, which merges the values of sensors with the same name. To turn the merging off, specify a value without the 0x01 flag. If the value includes the 0x2000 flag, the merging stays on regardless of the other flags you pass. |
| filterQuality | Median filtering level (0-255). Applied when median filtering is enabled in flags. Ignored when adaptive filtering is enabled. If you don’t specify this key, the system uses 0. |
| minFillingVolume | Minimum charge volume, in kWh. If you don’t specify this key, the system uses 20 kWh. The default value in the Minimum charge volume field of the interface is 10 kWh. To apply the same threshold through the API, specify this key explicitly. |
| fillingsJoinInterval | Timeout to separate consecutive charges, in seconds. If you don’t specify this key, the system uses 300 seconds. |
The system uses these settings only when data calculation by the sensor is enabled in calc_fuel. This setting corresponds to the Calculate data by the sensor option. The calculated values are returned by the battery_level, charge, and ev detectors. For details, see the Event detector types section.
The show_as_percentage key affects display only. Always specify battery_capacity and charge detection settings in kWh.
Example of a c string for a battery level sensor that sets both charge detection and percentage display:
"c":"{\"fuel_params\":{\"flags\":16387,\"filterQuality\":0,\"minFillingVolume\":10,\"fillingsJoinInterval\":300},\"show_as_percentage\":1,\"battery_capacity\":64.5,\"calc_fuel\":2,\"act\":1,\"mu\":0,\"appear_in_popup\":true}"
Pass show_as_percentage and battery_capacity inside the c string, next to fuel_params, and keep the m parameter of the sensor set to kWh.
The filtering type is set in flags: use 0x02 to enable filtering and add 0x4000 for adaptive median filtering. If you set the 0x2000 flag, the system uses only the filtering flags and the filterQuality value of the sensor.
For battery level sensors, the
0x2000flag works in the opposite way to its description on the unit/get_fuel_settings page: it doesn’t apply the default fuel settings of the unit.
The system always adds the calculation-by-time mode (0x10) for battery level sensors. You can’t disable it through this method.
For battery level sensors, the system resets the ignoreStayTimeout, minTheftVolume, and extraFillingTimeout keys to 0, even if you specify other values. The minTheftTimeout and theftsJoinInterval keys have no effect because drain detection isn’t available for these sensors.
Validation types
| Validation type flag | Description |
|---|---|
| 0x01 | Logical AND |
| 0x02 | Logical OR |
| 0x03 | Math AND |
| 0x04 | Math OR |
| 0x05 | Sum up |
| 0x06 | Subtract validator from sensor |
| 0x07 | Subtract sensor from validator |
| 0x08 | Multiply |
| 0x09 | Divide sensor by validator |
| 0x0A | Divide validator by sensor |
| 0x0B | Not-null check |
| 0x0C | Replace sensor with validator in case of error |
Response
If the request to create or update a sensor is completed successfully, a response in the following format is returned:
[
<long>, /* Sensor ID */
{
"id": <long>, /* Sensor ID */
"n": "<text>", /* Name */
"t": "<text>", /* Type */
"d": "<text>", /* Description */
"m": "<text>", /* Unit of measurement */
"p": "<text>", /* Parameter */
"f": <uint>, /* Sensor flags */
"c": <text>, /* Configuration, sent and returned as a JSON string */
"vt": <int>, /* Validation type */
"vs": <long>, /* Validating sensor ID */
"tbl": [ /* Calculation table */
{
"x": <double>,
"a": <double>,
"b": <double>
}
]
}
]
If the request to delete a sensor is completed successfully, a response in the following format is returned:
[
<long>, /* Sensor ID */
null
]
If the request fails, an error code is returned.
Error codes
| Error code | Description |
|---|---|
| 4 | Wrong input parameters. |
| 6 | Failed to update a parameter from the params section. |
| 7 | No Create, edit, and delete sensors access right to the unit. |
| 2015 | Unable to delete the sensor because it is used in the advanced properties of the unit or in the properties of another sensor. |