Skip to main content

Overview

Variables are InfluxDB metrics that serve as the foundation for dashboards and alarm systems in Mas Agua. Each variable can be:
  • Simple: Direct data from a single InfluxDB topic/field
  • Calculated: Derived from mathematical formulas combining multiple variables
  • Binary Compressed: Multiple boolean states packed into a single byte

Accessing Variables

Navigate to Configuration > Variables to manage your InfluxDB variables.

Variable Types

Instantaneous Variables

Capture the latest value from InfluxDB:
{
  "type": "last",
  "name": "Tank Level",
  "topic": "sensors/water_tank",
  "field": "level",
  "unit": "m"
}

Historical Variables

Store historical data over time:
{
  "type": "history",
  "name": "Daily Flow Rate",
  "topic": "sensors/flow",
  "field": "rate",
  "unit": "m³/h"
}

Creating a Variable

1

Open Variable Modal

Click Crear Variable to open the configuration form.
2

Configure Basic Properties

name_var
string
required
Variable name (e.g., “Pump 1 Pressure”)
process
string
required
Process category for filtering (e.g., “Water Treatment”, “Distribution”)
unit
string
required
Unit of measurement (e.g., “bar”, “°C”, “m³/h”)
type_var
select
required
Variable type:
  • last - Instantaneous (latest value)
  • history - Historical (time series data)
3

Configure Data Source

For simple variables:
topic
string
required
InfluxDB topic (measurement name)
field
string
required
Field name within the topic
time
number
required
Query time window (e.g., 5, 60, 3600)
unit_topic
select
required
Time unit:
  • ms - Milliseconds
  • s - Seconds
  • m - Minutes
  • h - Hours
  • d - Days
  • mo - Months
  • y - Years
period
number
required
Sampling period value
unit_period
select
required
Period time unit (same options as unit_topic)
type_period
select
required
Aggregation method:
  • last - Latest value
  • mean - Average value

Calculated Variables

Calculated variables combine multiple data sources using mathematical formulas.

Enabling Calculation Mode

  1. Toggle “¿La variable requiere un calculo?” switch
  2. The form switches to formula builder mode
  3. Define variables used in the formula
  4. Build the mathematical expression

Formula Builder

The calculator interface supports:
  • Operators: +, -, *, /, (, )
  • Variables: Reference other configured variables
  • Numbers: Constants in your formula

Example: Power Calculation

{
  "name": "Pump Power",
  "calc": true,
  "equation": ["voltage", "*", "current"],
  "varsInflux": {
    "voltage": {
      "calc_topic": "sensors/electrical",
      "calc_field": "voltage",
      "calc_time": 1,
      "calc_unit_topic": "s",
      "calc_period": 1,
      "calc_unit_period": "s",
      "calc_type_period": "last"
    },
    "current": {
      "calc_topic": "sensors/electrical",
      "calc_field": "current",
      "calc_time": 1,
      "calc_unit_topic": "s",
      "calc_period": 1,
      "calc_unit_period": "s",
      "calc_type_period": "last"
    }
  },
  "unit": "kW"
}

Binary Compressed Variables

Pack up to 8 boolean states into a single byte value.

Configuration

  1. Toggle “¿Variable binaria comprimida?” switch
  2. Click Agregar bit to add bit assignments (max 8)
  3. For each bit:
    • Nombre: Descriptive name (e.g., “Pump Running”)
    • Posición: Bit position (0-7)

Example: Equipment Status

{
  "name": "Equipment Status Byte",
  "binary_compressed": true,
  "bits": [
    {"id": 1, "name": "Pump 1 Running", "bit": 0},
    {"id": 2, "name": "Pump 2 Running", "bit": 1},
    {"id": 3, "name": "Valve Open", "bit": 2},
    {"id": 4, "name": "High Pressure Alarm", "bit": 3}
  ]
}
Binary compressed variables cannot use calculation mode simultaneously.

Filtering Variables

Use the filter panel to find variables:
unit
select
Filter by unit of measurement
calc
select
Filter by calculation status:
  • All variables
  • Only calculated (true)
  • Only direct (false)
process
select
Filter by process category

Managing Variables

Edit Variable

  1. Click Editar in the table row
  2. Modify configuration
  3. Click Guardar variable

Delete Variable

  1. Click Eliminar in the table row
  2. Confirm deletion in the dialog
Deleting a variable used in alarms or dashboards will break those configurations.

API Endpoints

Variables are managed through these backend routes:
EndpointMethodPurpose
/saveVariablePOSTCreate or update variable
/deleteVar/:idPOSTDelete variable by ID
/getVarsInfluxGETRetrieve all variables

Data Structure

The complete variable schema:
interface Variable {
  id: number;
  name: string;
  unit: string;
  type: 'last' | 'history';
  calc: boolean;
  process: string;
  binary_compressed?: boolean;
  bits?: Array<{id: number, name: string, bit: number}>;
  varsInflux: {
    [varName: string]: {
      calc_topic: string;
      calc_field: string;
      calc_time: number;
      calc_unit?: string;          // For simple vars
      calc_unit_topic?: string;    // For calc vars
      calc_period: number;
      calc_unit_period: string;
      calc_type_period: 'last' | 'mean';
    }
  };
  equation?: string[];  // For calculated variables
}

See Also