Math Expression
The Math Expression node evaluates a mathematical or logical expression defined through the Expression property.
For general information about the expression editor, refer to Configuring an expression.
After the expression has been defined, every variable used inside it automatically becomes an input connector of the node.
Whenever the expression is evaluated, the calculated result is sent to the output connector.
Each input connector provides a Trigger property that determines whether receiving a new value on that connector causes the expression to be recalculated. By default, Trigger is enabled.
The Trigger property must be disabled when an input connector and the output connector are linked to the same source, for example the same KNX group address.
Otherwise, the output update could trigger the input again and generate an infinite loop.
Connectors
The input connectors are generated dynamically according to the variables used in the configured expression.
For example:
temperature - setpoint
automatically creates:
- temperature
- setpoint
| Connector | Type | Description |
|---|---|---|
| Variables | Input | Dynamic input connectors created from the variables used in the expression. |
| Output | Output | Result obtained after evaluating the expression. |
Main properties
| Property | Description |
|---|---|
| Expression | Defines the mathematical or logical expression evaluated by the node. |
Each generated input connector also provides:
| Connector property | Description |
|---|---|
| Trigger | Determines whether receiving a new value on this input causes the expression to be recalculated. Enabled by default. |
Operation
The node works as follows:
- configure an expression in Expression;
- the variables become input connectors;
- values are received through those connectors;
- when an input with Trigger enabled receives a new value, the expression is evaluated;
- the result is sent to Output.
Example:
temperature - setpoint
with:
temperature = 24
setpoint = 21
returns:
3
Trigger property
When Trigger is enabled, every new value received by the connector causes the expression to be evaluated again.
When Trigger is disabled, the connector value can still be used in the expression, but receiving a new value on that connector does not itself start a new calculation.
Avoiding infinite loops
If an input and the output use the same source, for example the same KNX group address, an output update could be read again by the input and trigger another calculation.
When an input and the output refer to the same source, disable Trigger on that input unless the specific logic explicitly requires another behaviour.
Functions
| Function | Purpose |
|---|---|
| abs | Absolute value |
| avg | Average |
| between | Inclusive range check |
| cos | Cosine |
| daysinmonth | Days in current month |
| deg | Radians to degrees |
| exp | Natural exponential |
| floatto2bytes | Float to KNX 2-byte raw representation |
| getbytes | Extract bytes |
| iif | Inline conditional |
| inttodouble | Raw 8-byte value to double |
| isbitclear | Checks whether a bit is 0 |
| isbitset | Checks whether a bit is 1 |
| isfalseornull | Checks false or null |
| isnullorempty | Checks null or empty |
| istrueornull | Checks true or null |
| ln | Natural logarithm |
| log | Logarithm with configurable base |
| mid | Median |
| not | Boolean NOT |
| numericmax | Maximum value |
| numericmin | Minimum value |
| pow | Power |
| rad | Degrees to radians |
| random | Random value in a range |
| regulator | Binary regulator with hysteresis |
| round | Numeric rounding |
| shiftbitleft | Bit shift left |
| shiftbitright | Bit shift right |
| sin | Sine |
| sqrt | Square root |
Typical applications
- mathematical calculations;
- conditional logic;
- comparisons and range verification;
- statistical calculations;
- logarithmic, exponential and trigonometric calculations;
- bit manipulation and status extraction;
- conversion of raw KNX values;
- random value generation;
- binary regulation with hysteresis;
- combining multiple input variables into a calculated result.
Configuration notes
- Variables used in the expression automatically become input connectors.
- Each input connector provides its own Trigger property.
- Trigger is enabled by default.
- Disable Trigger when an input and the output are connected to the same source and an update loop could occur.
- Verify the expected input type of each function.
- Pay particular attention to byte and bit functions when working with raw KNX data.