comparator
Description
The comparator block compares two values and returns a boolean result true or false at the output.
The block can operate in two modes:
- comparing values from the
tag1andtag2inputs - comparing each received value with one constant value stored in the configuration
The block supports three comparison groups:
- boolean
boolvalues with otherboolvalues - text
textvalues with othertextvalues - all numeric values with each other:
integer,float,temperature,percent
If the comparison cannot be performed, the output becomes null and the block description shows the reason for the error.
The block does not support group control. It is not available as a target block type in the group-broadcast block.
Configuration parameters
| Parameter name | Value |
|---|---|
Name (name) |
Name displayed on the block in the editor. Enter a name that helps identify the block; if left empty, comparator is displayed. |
If state (operator, compare_with_const_value) |
Select the comparison operator and its right side: Tag: 2 or “Constant value”. Selecting “Constant value” enables comparison of each received value with a constant and shows its control; Tag: 2 restores comparison of tag1 with tag2 and hides that control. Available operators are >, <, ==, and <> (inequality, referred to below as !=). The operator is required; for bool and text values, only == and != are valid. |
Hysteresis (hysteresis) |
Required numeric parameter. It affects numeric comparisons only. The available range is from 0 to 10000 with a step of 0.1. The parameter defines the full width of the deadband, and the block uses half of that value on each side of the switching point. For example, setting “Hysteresis” to 2 means a +-1 band. |
Constant value (const_value, const_value_type) |
Control visible and required after selecting “Constant value” in “If state”. Choose a boolean (bool), numeric (num), or text (str) type and set the value. For a boolean, select true or false; for a number, provide a non-empty numeric value different from null; for text, enter a non-empty text value. |
Block duplicated value (filter_duplicated_values) |
Required boolean value true or false. When set to true, the block does not emit the same true or false result again. When set to false, each subsequent successful recalculation is emitted even if the result does not change. This parameter does not block repeated error emissions that end with the null value. |
Input handling
The operating mode depends on the right side of the comparison selected in “If state”. The default selection is Tag: 2.
tag1 versus tag2 comparison mode
In this mode, the block requires exactly one tag1 connection and exactly one tag2 connection. No blocks other than tag may be connected to the input.
Operating rules:
- when a change arrives from
tag1, it is compared with the last known value fromtag2 - when a change arrives from
tag2, it is compared with the last known value fromtag1 - if the other side does not yet have a last known value, the output becomes
null
Constant-value comparison mode
In this mode, each received input change is compared with the “Constant value” setting.
Operating rules:
tag2must not be connectedtag1may be used as the named data input, but it is not required- each received change is treated as the left side of the comparison, and the configured constant is treated as the right side
Input lines labeled with the tag block
| Input number and name | Description |
|---|---|
tag1: First comparison value |
In two-input mode, this connection is required and provides the first compared value. In constant-value mode, it may be used as the data input, but it is not required. |
tag2: Second comparison value |
In two-input mode, this connection is required and provides the second compared value. In constant-value mode, it must not be connected. |
Supported types and operators
boolcan be compared only with the==and!=operatorstextcan be compared only with the==and!=operatorsinteger,float,temperature, andpercentcan be compared with all operators- different numeric types may be mixed; the block treats them simply as numeric values and does not verify unit compatibility
Ignored cases:
- receiving the same
trueorfalseresult again when “Block duplicated value” is checked - in numeric comparisons with the
>and<operators, small changes that stay inside the hysteresis band when the block already has a previously established result
Hysteresis and numeric comparisons
Hysteresis is used only for numeric comparisons.
The block calculates the absolute difference between two values and compares it with half of the “Hysteresis” setting.
Operating rules:
- for
==, the result is true when the difference is less than or equal to half of the hysteresis - for
!=, the result is true when the difference is greater than half of the hysteresis - for
>and<, entering the hysteresis band does not force an immediate result change; the block keeps the previous state until the difference leaves the hysteresis band - if
>or<is evaluated for the first time and the block does not yet have a previous result, the result is calculated from a normal comparison of both values
Block outputs
The block has one output.
The output becomes:
- boolean true or false if the comparison was performed successfully
nullif the comparison cannot be performed because of a configuration error, a missing second value,nullat the input, or incompatible types
Block status description
The description shown below the block takes one of the following forms:
nullbefore the first successful comparisontrueorfalseafter a successful comparison- an error message if the last comparison attempt ended with an error
Errors visible to the user
The block can show the following error messages:
| Error code | Error description |
|---|---|
Missing operator configuration. |
The operator in “If state” is missing or cannot be read as non-empty text. |
Invalid operator configuration. |
The operator in “If state” has a value outside the supported list. |
Invalid hysteresis configuration. |
The “Hysteresis” setting is not a valid numeric value. |
Missing filter_duplicated_values configuration. |
The “Block duplicated value” setting is missing in the configuration or cannot be read as a boolean value. |
Missing const_value_type configuration. |
In constant-value comparison mode, the type selection in “Constant value” is missing. |
Missing constant value configuration. |
In constant-value comparison mode, “Constant value” was not filled in or an empty text was provided where a non-empty text is required. |
Invalid constant value configuration. |
The “Constant value” setting has an invalid value for the type selected in that control. This includes null and an unsupported boolean value. |
Expected numeric constant value configuration. |
A numeric type was selected in “Constant value”, but a non-numeric value was provided. |
Invalid constant value type configuration. |
The type configured in “Constant value” is other than boolean (bool), numeric (num), or text (str). |
Non-tag block connected. |
In tag1 versus tag2 mode, a block other than tag is connected to the input. |
Multiple tag1 blocks connected. |
More than one tag1 line is connected to the block. |
Multiple tag2 blocks connected. |
More than one tag2 line is connected to the block. |
Only tag1 and tag2 blocks supported. |
A tag line other than tag1 or tag2 is connected to the block. |
Missing tag1 block connection. |
In two-input mode, tag1 is not connected. |
Missing tag2 block connection. |
In two-input mode, tag2 is not connected. |
Invalid tag2 connection with constant value enabled. |
In constant-value comparison mode, tag2 is connected, which is not allowed. |
Missing value from tag1. |
A change arrived from tag2, but the block does not yet know the last value from tag1. |
Missing value from tag2. |
A change arrived from tag1, but the block does not yet know the last value from tag2. |
Invalid tag1 value. |
The first compared value is invalid. |
Invalid tag2 value. |
The second compared value is invalid. |
Null tag1 value. |
The first compared value is null. |
Null tag2 value. |
The second compared value is null. |
Invalid operator for bool value. |
An operator other than == or != was selected in “If state” while both compared values are boolean. |
Invalid operator for text value. |
An operator other than == or != was selected in “If state” while both compared values are text values. |
Can't compare <typ1> with <typ2> |
The block received two incompatible types, for example bool and text or integer and text. |
For the Missing tag1 or tag2 block connection. message, check both tag connections. Messages starting with Failed to get ... value. mean that a value could not be read for comparison; check the data supplied by the connected blocks.
Examples
- If “If state” selects the
>operator andTag: 2, “Hysteresis” is set to 0,tag1 = 23, andtag2 = 20, the output becomes true. - If “If state” selects the
==operator andTag: 2, “Hysteresis” is set to 1.0,tag1 = 20.0, andtag2 = 20.4, the output becomes true because the difference0.4is inside the+-0.5band. - If “If state” selects the
>operator, “Hysteresis” is set to 2, and the previous result was already true for the values22and20, then a later change to21and20.4does not switch the result because the difference still stays inside the+-1band. - If “If state” selects the
==operator and “Constant value”, and the “Constant value” control is set to text with the valueauto, receiving the textautomakes the comparison result true. - To detect a high temperature, select the
>operator and “Constant value” in “If state”, set a numeric constant of25, and set “Hysteresis” to1. Connect the temperature reading to the input. At26°C, the result is true; after a drop to25°C, it stays true, and after a drop to24°C, it changes to false.