Skip to main content

Overview

Variables in Centinela represent monitoring points in your water treatment system. They can be simple InfluxDB queries or calculated values based on formulas.

Variable Types

Simple Variables

Direct queries from InfluxDB with a single topic and field.

Calculated Variables

Computed from multiple InfluxDB variables using custom formulas (e.g., {var1} + {var2} * 0.5).

Binary Compressed Variables

Single byte values where individual bits represent different boolean states (up to 8 bits per variable).

List All Variables

Retrieve all configured InfluxDB variables:
cURL
curl -X GET "https://masagua.cooptech.com.ar/api/getVarsInflux" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json"
Response:
{
  "data": [
    {
      "id": 1,
      "name": "Caudal Entrada Planta",
      "unit": "m³/h",
      "type": "last",
      "calc": false,
      "process": "Captación",
      "binary_compressed": false,
      "varsInflux": {
        "Caudal Entrada Planta": {
          "calc_topic": "planta/caudal",
          "calc_field": "entrada",
          "calc_time": 30,
          "calc_unit": "s",
          "calc_period": 10,
          "calc_unit_period": "s",
          "calc_type_period": "last"
        }
      }
    },
    {
      "id": 2,
      "name": "Cloro Residual Calculado",
      "unit": "mg/L",
      "type": "last",
      "calc": true,
      "process": "Desinfección",
      "binary_compressed": false,
      "equation": [
        {"value": "Cloro_Total", "type": "variable"},
        {"value": "-", "type": "operator"},
        {"value": "Cloro_Consumido", "type": "variable"}
      ],
      "varsInflux": {
        "Cloro_Total": {
          "calc_topic": "laboratorio/cloro",
          "calc_field": "total",
          "calc_time": 1,
          "calc_unit_topic": "m",
          "calc_period": 30,
          "calc_unit_period": "s",
          "calc_type_period": "mean"
        },
        "Cloro_Consumido": {
          "calc_topic": "laboratorio/cloro",
          "calc_field": "consumido",
          "calc_time": 1,
          "calc_unit_topic": "m",
          "calc_period": 30,
          "calc_unit_period": "s",
          "calc_type_period": "mean"
        }
      }
    },
    {
      "id": 3,
      "name": "Estados Bombas",
      "unit": "bool",
      "type": "last",
      "calc": false,
      "process": "Bombeo",
      "binary_compressed": true,
      "bits": [
        {"id": 1, "name": "Bomba 1", "bit": 0},
        {"id": 2, "name": "Bomba 2", "bit": 1},
        {"id": 3, "name": "Bomba 3", "bit": 2}
      ],
      "varsInflux": {
        "Estados Bombas": {
          "calc_topic": "bombas/estados",
          "calc_field": "byte",
          "calc_time": 10,
          "calc_unit": "s",
          "calc_period": 5,
          "calc_unit_period": "s",
          "calc_type_period": "last"
        }
      }
    }
  ]
}
id
integer
Unique variable identifier
name
string
Variable display name
unit
string
Measurement unit (m³/h, mg/L, °C, etc.)
type
string
Data type: last (instantaneous) or history (historical)
calc
boolean
Whether this is a calculated variable
process
string
Process category (Captación, Filtración, Desinfección, etc.)
binary_compressed
boolean
Whether this variable uses bit compression
equation
array
Formula for calculated variables (array of operators and variable references)
bits
array
Bit definitions for binary compressed variables (max 8 bits)
varsInflux
object
InfluxDB query configuration for each variable used

Create or Update Variable

Create a new variable or update an existing one:
cURL
curl -X POST "https://masagua.cooptech.com.ar/api/saveVariable" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 0,
    "name": "Presión Salida Filtros",
    "unit": "bar",
    "type": "last",
    "calc": false,
    "process": "Filtración",
    "binary_compressed": false,
    "varsInflux": {
      "Presión Salida Filtros": {
        "calc_topic": "filtros/presion",
        "calc_field": "salida",
        "calc_time": 30,
        "calc_unit": "s",
        "calc_period": 10,
        "calc_unit_period": "s",
        "calc_type_period": "last"
      }
    }
  }'
id
integer
required
Variable ID (0 for new variables)
name
string
required
Variable name
unit
string
required
Measurement unit
type
string
required
Variable type: last or history
calc
boolean
required
Whether this is a calculated variable
process
string
required
Process category name
binary_compressed
boolean
Enable bit compression (default: false)
bits
array
Array of bit definitions (required if binary_compressed is true)
equation
array
Formula array (required if calc is true)
varsInflux
object
required
InfluxDB query configuration

Creating a Calculated Variable

cURL
curl -X POST "https://masagua.cooptech.com.ar/api/saveVariable" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 0,
    "name": "Eficiencia Filtración",
    "unit": "%",
    "type": "last",
    "calc": true,
    "process": "Filtración",
    "equation": [
      {"value": "(", "type": "operator"},
      {"value": "Turbiedad_Entrada", "type": "variable"},
      {"value": "-", "type": "operator"},
      {"value": "Turbiedad_Salida", "type": "variable"},
      {"value": ")", "type": "operator"},
      {"value": "/", "type": "operator"},
      {"value": "Turbiedad_Entrada", "type": "variable"},
      {"value": "*", "type": "operator"},
      {"value": "100", "type": "number"}
    ],
    "varsInflux": {
      "Turbiedad_Entrada": {
        "calc_topic": "filtros/turbiedad",
        "calc_field": "entrada",
        "calc_time": 1,
        "calc_unit_topic": "m",
        "calc_period": 30,
        "calc_unit_period": "s",
        "calc_type_period": "mean"
      },
      "Turbiedad_Salida": {
        "calc_topic": "filtros/turbiedad",
        "calc_field": "salida",
        "calc_time": 1,
        "calc_unit_topic": "m",
        "calc_period": 30,
        "calc_unit_period": "s",
        "calc_type_period": "mean"
      }
    }
  }'

Creating a Binary Compressed Variable

cURL
curl -X POST "https://masagua.cooptech.com.ar/api/saveVariable" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{
    "id": 0,
    "name": "Estados Válvulas Entrada",
    "unit": "bool",
    "type": "last",
    "calc": false,
    "process": "Captación",
    "binary_compressed": true,
    "bits": [
      {"id": 1, "name": "Válvula Principal", "bit": 0},
      {"id": 2, "name": "Válvula Secundaria", "bit": 1},
      {"id": 3, "name": "Válvula Purga", "bit": 2}
    ],
    "varsInflux": {
      "Estados Válvulas Entrada": {
        "calc_topic": "valvulas/estados",
        "calc_field": "entrada_byte",
        "calc_time": 10,
        "calc_unit": "s",
        "calc_period": 5,
        "calc_unit_period": "s",
        "calc_type_period": "last"
      }
    }
  }'

Delete Variable

Delete a variable by ID:
cURL
curl -X POST "https://masagua.cooptech.com.ar/api/deleteVar/{id}" \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json"
Response:
{
  "data": {
    "influxVar": true
  }
}
Deleting a variable will remove it from all charts, diagrams, and alarms that reference it.

InfluxDB Configuration

Time Units

calc_unit
string
  • ms - Milliseconds
  • s - Seconds
  • m - Minutes
  • h - Hours
  • d - Days
  • mo - Months
  • y - Years

Period Types

calc_type_period
string
  • last - Last value in the period (instantaneous)
  • mean - Average value over the period

Example Use Cases

Simple Flow Meter

{
  "name": "Caudal Principal",
  "unit": "m³/h",
  "type": "last",
  "calc": false,
  "process": "Distribución",
  "varsInflux": {
    "Caudal Principal": {
      "calc_topic": "caudalimetros/principal",
      "calc_field": "value",
      "calc_time": 30,
      "calc_unit": "s",
      "calc_period": 10,
      "calc_unit_period": "s",
      "calc_type_period": "last"
    }
  }
}

Daily Average Temperature

{
  "name": "Temperatura Promedio Diaria",
  "unit": "°C",
  "type": "history",
  "calc": false,
  "process": "Monitoreo Ambiental",
  "varsInflux": {
    "Temperatura Promedio Diaria": {
      "calc_topic": "sensores/temperatura",
      "calc_field": "ambiente",
      "calc_time": 24,
      "calc_unit": "h",
      "calc_period": 1,
      "calc_unit_period": "h",
      "calc_type_period": "mean"
    }
  }
}

Next Steps

Alarms

Configure alarms based on variables

Charts

Visualize variables in charts