This page describes the built-in blocks of the Blockly editor used to write route functions without programming: what each block expects, what it returns, and a typical use. How to open the editor, connect blocks and create your own blocks is explained on Route functions (Blockly). The routing table and the route parameters are described on Routes.
The Blocks menu of the editor sorts the blocks by the type of value they return:
| Menu | Blocks that return |
|---|---|
| any | a value of any type (number, text, object…) |
| boolean | true / false |
| number | a number |
| string | a text |
| object | an object |
| address | an address object |
| block | your custom blocks, and Create New Block |
An input accepts a block of the same type, or of type any. The editor refuses the other connections.
Every diagram has a text equivalent, shown in the code editor below the blocks: the name of the block followed by its inputs in order, for example scale(v,0.01) or covOverTime(v,"hour"). You can also type this text in the code editor: the diagram is updated. All the inputs must be given in order: scale(0.01) sets the number input, not the factor, and the block returns nothing.
A block that returns nothing (null) cancels the routing: nothing is written to the destination for this execution. This is how the filter blocks work (filter, triggered_by), and also what happens at the first execution of the blocks that compare with the previous value (last, cov, covOverTime).
| Block | Menu | Inputs | Returns |
|---|---|---|---|
v |
any | – | The value being routed (after the transformations placed before, in a chain). |
source_value |
any | – | Current value of the source address of the route. |
dest_value |
any | – | Value of the destination address before this routing. |
source |
address | – | The source address object (name, id, gateway_id, value, status…). |
dest |
address | – | The destination address object. |
source_status |
string | – | Status of the source address: online, offline, pending, or an error message of the driver. Useful in status routes. |
dest_status |
string | – | Status of the destination address. |
address |
address | address name | The object of any address of the device. |
address_value |
any | address | The current value of any address. |
address_status |
string | address | The status of any address. |
The address inputs take a name, an alias or an id. When the name exists on several gateways, write gatewayName¬address.
Example: write the value of another address instead of the routed value: address_value($setpoint).
| Block | Menu | Inputs (defaults) | Returns |
|---|---|---|---|
filter |
any | value (v), condition | The value when the condition is true; otherwise nothing, and the routing stops. |
triggered_by |
any | value (v), trigger | The value only when the execution was started by the selected event: value (new value of the source), status (status change), refresh (start of the route), gateway (reconnection of a gateway). Otherwise nothing. |
trigger |
string | – | The event that started the execution: value, status, refresh or gateway. |
if_else |
any | condition, if_true, else | The if_true input when the condition is true, otherwise the else input. Only the selected input is computed. |
compare |
boolean | number (v), operator (>), operand (0) |
The comparison of the two numbers: >, <, <=, >=, =, ≠. |
or |
boolean | 2 to 10 inputs | 1 when at least one input is true, otherwise 0. |
not |
boolean | value | The boolean inverse of the value. |
some |
any | 2 to 10 inputs | The result of the first input that returns a value (not null). The inputs are computed in order. |
each |
any | 2 to 10 inputs | Computes the inputs in order, each one receiving the result of the previous one as its routed value, and returns the last result. |
Examples
>, 0)).value). Unticking refresh and gateway in the Trigger column of the route does the same for the whole route (section 2.3 of Routes).To know whether an execution is a periodic repeat or a retry, test options.reprod in a JavaScript function (section 2.6.1 of Routes).
| Block | Inputs (defaults) | Returns |
|---|---|---|
scale |
number (v), factor (1) | number × factor |
linear |
number (v), factor (1), offset (0) | number × factor + offset |
calculate |
number (v), operator (+), operand (1) |
+, -, *, /, max, min, or avg (average of the two numbers) |
round |
number (v), decimals (0), method (round) |
The rounded number. decimals: 0 = integer, -1 = one decimal (0.1), -2 = two decimals (0.01), 1 = tens, 2 = hundreds. method: round (closest), floor (down), ceil (up). |
abs |
number (v) | The absolute value. |
to_number |
value | The value converted to a number ("21.5 °C" gives 21.5). |
Examples
scale(v,0.1).linear(v,1.8,32).round).These blocks remember a value between two executions of the route, separately for each source → destination pair.
| Block | Menu | Inputs (defaults) | Returns |
|---|---|---|---|
last |
any | value (v) | The value of the previous execution. Nothing at the first execution. |
cov |
number | number (v) | The difference with the value of the previous execution (change of value). Nothing at the first execution. |
covOverTime |
number | number (v), unit (millisecond) |
The difference with the previous value divided by the time elapsed, per millisecond, second, minute, hour or day. Nothing at the first execution. |
cov_passed |
boolean | number (v), cov (0.1); advanced: down | True when the value rose by at least cov, or fell by at least down, since the last value that passed; true at the first execution. Without down, a decrease never returns true. |
Examples
covOverTime(v,"hour"). An index in m³ gives m³/h with the same unit. See the article Counter to instantaneous.| Inputs (defaults) | Description |
|---|---|
| value (v) | The value returned at the end of the delay. |
| ms (100) | The delay, in milliseconds. |
concurrent (ignore old) |
What happens when a new value arrives while a delay is running (see below). |
scope (destination), advanced |
One delay per destination address (default), per source, per source and destination pair, or a single delay for the whole route. |
| skip_delay, advanced | When true, the running delay is cancelled and the value is returned immediately. |
| concurrent | Behaviour |
|---|---|
ignore old |
The running delay continues; at its end, the latest value is written. The older values are not written. |
ignore old and reset |
The delay restarts with the new value: a value is written only after ms without any new value (debounce). |
ignore new |
The new value is dropped; the running delay writes the first value. |
parallel |
Each value has its own delay and is written at its end. |
delay block or Disable Delay? The Disable Delay parameter of the route (section 2.12 of Routes) writes the first value at once and then limits the rate. The delay block always waits before writing. Use the block to wait until a value is stable (ignore old and reset), and Disable Delay to protect a slow bus from bursts.
| Block | Menu | Inputs (defaults) | Returns |
|---|---|---|---|
get |
any | value (v), property (k) |
A property of an object. A path with dots reads nested objects: humidity.value. |
set |
object | object, key, value | The object, with the property key set to value (a path with dots is accepted). Nothing if the object is missing. |
wrap |
object | value, property | A new object { <property> : value }. |
to_string |
string | value | The value converted to text. |
to_boolean |
boolean | value | The value converted to true / false. |
substring |
string | start (0), end | The part of the routed text from start up to (not including) end, or to the end when end is empty. Nothing if the routed value is not a text. |
indexOf |
number | text; hidden: position | The position of the first occurrence of the text in the routed text, -1 when absent. |
lastIndexOf |
number | text; hidden: position | The position of the last occurrence. |
Example: an MQTT payload {"temperature":{"value":22,"unit":"°C"}} to a BACnet analog value: get(v, temperature.value).
variable reads a named value kept in memory between the executions of the route, one per source → destination pair. Show its hidden input set (right click on the block) and connect a block to it to store a new value: the block then returns the value stored.
stream returns a stream object instead of a value. Written to a destination address that accepts streams, it starts the transfer of large data (for example a file) from the address input (the source address of the route when empty). The options input ({"source":{},"destination":{}}) passes options specific to the source and destination drivers; see the page of the driver concerned.
this.<name> and the gateways API as this.gateways. See section 5 of Route functions (Blockly).options argument are described in section 2.6 of Routes.input_any, input_boolean, input_number, input_string, input_enum (a drop-down list; tick options and type the choices separated by commas), input_address, input_object, and input_array (a list of inputs). See Custom blocks.Block scripts and JavaScript functions run on the device with the rights of the gateway software. Import block files only from a source you trust.