Skip to content

const

Description

The const block stores one constant value and sends it to its output when it is triggered by an input event or by the set command from the command block. It also supports the reset command from the command block, which causes the block to send the null value.

The block has one input and one output. It does not require the use of inputs labeled with the tag block.

The constant value may have one of the following types:

  • boolean
  • numeric
  • text

If no other source is connected to the block input, then after the project starts the block sends the configured value once on its own.

Configuration parameters

Parameter name Value
Name (name) Name displayed on the block in the editor. If the field is left empty, const is displayed.
Value (value, value_type) Constant value sent to the output together with its type selection: boolean (bool), numeric (num), or text (str). Both the value and its type are required. The ordinary control is available when “Use color” is disabled.
Use color (useColor) Enables configuring the transmitted value using a color picker. Selecting it shows “Color” and “Brightness” and hides the ordinary “Value” control. Disabling it restores ordinary value entry. This option does not change the color of the block tile in the editor.
Color (color) Selection of the color sent by the block, available when “Use color” is enabled. On save, it is combined with the selected brightness into one text value.
Brightness (brightness) Slider for the selected color's brightness from 0 to 100%, available when “Use color” is enabled. The selected brightness is appended to the text value of the color.
Input edge (input_edge) Required parameter that defines which ordinary input event should cause the constant value to be sent again. Available values: rising, falling, both, true, false, null.

Meaning of the “Input edge” setting:

  • rising: react to a change interpreted as false -> true
  • falling: react to a change interpreted as true -> false
  • both: react to every change between logical states
  • true: react to every input event whose new value can be interpreted as logical true
  • false: react to every input event whose new value can be interpreted as logical false
  • null: react to every input event whose new value is null

Meaning of the type selected in the “Value” control:

  • bool: the block stores the logical value true or false
  • num: the block stores an integer or a fractional number; enter only the number without a unit, for example 21.5
  • str: the block stores a text value

With “Use color” enabled, saving the form prepares a text value: it removes the # from the selected color and appends two hexadecimal digits for brightness. Brightness is converted from 0–100% to 0–255 and rounded down. For example, “Color” #ff0000 and “Brightness” 50% produce the transmitted text ff00007f.

Input handling

The block reacts to ordinary events delivered to its only input and to the set and reset commands sent from the command block.

The block does not require any tag inputs.

Detailed operating rules:

  • if no other block is connected to the input, const sends the configured value by itself after initialization is finished
  • an ordinary input event that matches the “Input edge” setting causes the configured value to be sent again
  • the set command from the command block causes the configured value to be sent again regardless of the “Input edge” setting
  • the reset command from the command block causes the block to send the null value of the same type as the configured value
  • after the reset command, the next set command or the next valid input trigger sends the configured value again

Additional input interpretation rules:

  • for rising, falling, and both, the block requires values that can be interpreted logically
  • for true and false, the block reacts to every input event whose new value is interpreted respectively as true or false, even if the previous value was the same
  • for null, the block reacts only to input events whose new value is null

Block outputs

The block has one output.

The output always carries the value configured in the block parameters, unless the block receives the reset command, which sends the null value.

The way the value is emitted depends on the configured type:

  • for the text type (str) in the “Value” control, every emission has the form null -> text
  • for the numeric type (num) in the “Value” control, every emission has the form null -> number
  • for the boolean type (bool) in the “Value” control, every emission has the form of a change from the opposite logical state to the configured value, that is false -> true or true -> false

The description visible below the block shows the value currently prepared to be sent in text form, for example:

  • true
  • false
  • 25
  • 21.5
  • hello

After the reset command, the block description changes to null. After the configured value is sent again, the description returns to its text representation.

Errors returned by the block

The block can show the following error messages:

Error code Error description
Invalid input edge configuration. The “Input edge” setting is invalid or was not selected.
Missing value type configuration. The type selection is missing from the “Value” control's configuration.
Invalid value type configuration. The type in the “Value” control is outside the supported list: bool, num, str.
Missing value configuration. The “Value” setting is missing in the configuration.
Invalid value configuration. “Value” has an invalid form for the selected type. This includes, among others, the case when bool is given a value other than true or false, or when a valid numeric value cannot be read for num.
Expected numeric value configuration. The numeric type (num) is selected in the “Value” control, but the supplied value is not numeric.
Set description failed. The configured value could not be displayed in the block description. Check the “Value” setting and its selected type.

Usage examples

  • If the text type (str) is selected and hello is entered in the “Value” control, and no other block is connected to the input, then after the project starts const sends the value hello to the output by itself.
  • To set a thermostat's reference temperature, select the numeric type (num) in “Value” and enter 21.5, then set “Input edge” to rising. Connect the output through tag1 to an app-thermo block. Each rising edge sends the number 21.5, which the thermostat accepts as a reference temperature of 21.5°C if it is within its configured range.
  • If the boolean type (bool) and true are selected in the “Value” control, then the set command from the command block causes the change false -> true to be sent, regardless of the “Input edge” setting.
  • If the boolean type (bool) and false are selected in the “Value” control, then every valid trigger causes the change true -> false.
  • If the block receives the reset command, null appears at the output and the block description changes to null.