Before reading this document it may be preferable to read about the routes in general and their parameters: Routing documentation.
This document describes how to use the Blockly editor in order to fulfill custom routing use cases. The advantage of using Blockly is the ease of use for technicians unfamiliar with programming languages. It gives anyone the opportunity to build, export, import custom blocks and use those across different projects / sites.
Each built-in block is described, with its inputs, defaults and examples, on the Routing blocks reference.
The first section describes how to get started with the blockly editor.
The second section explains the basics about the blocks.
The third section delves into the creation and edition of custom blocks.
The fourth and fifth section are more advanced and require basic skills in the JavaScript programming language.
The fourth section shows how to use pure Javascript functions for routing.
The fifth section describes the script block.
In order to open the editor, you first have to create a route and then edit the "Source value" column. This column is used to modify / apply custom functions to the source value before it gets written to the route destination address.

New blocks are inserted from the menu on the left by drag & dropping it in the editing area. In the screenshot below, a scale block is added. This block allows to multiply the routed value and can be used to apply basic unit conversions.

The Blockly editor is divided in 3 main parts, the Blocks menu on the top left, the block editor on the top right, and the code editor on the bottom left.
The Block editor content and the Code editor content are automatically synchronized to match each other. When one is modified, the other gets updated.

Each block has a single output on its left side and has a variable number of inputs (ranging from 0 to n) on its right . The blocks are organized by colours. The block colour is indicative of the block output type. Regarding the inputs, their type is indicated by the colour of the input text label.
There is 6 different types possible for outputs and inputs:
{
"humidity" : {
"value" : 70,
"unit" : "%"
},
"temperature" : {
"value" : 22,
"unit" : "°C"
}
}
{
"id" : 123213, //numerical unique id
"name" : "%bac:local/outputValue:2/presentValue", //the string identifier
"gateway_id" : 3, //specifies the gateway driver id
"value" : 33, //last known value
"value_string" : "33", //serialized last known value
"value_date" : 1692272239308, //last known value date time
"json" : {/* ... protocol / driver specific ... */},
/** ... and some other properties ... **/
}
When you connect different blocks together, the blockly editor makes sure that their respective output and input types are matching. As an example, a green block with an output of type number can only be connected to another block's input of type number or any.

The example above showcases block connections. This block diagram takes the value being routed (the value of the source address), adds 100 to it, and then multiplies the result by 0.01. The final number returned by the scale block is then written on the destination address defined in the route. Note that the same computation can be done with a single JavaScript function block such as below.

Blocks have tooltip documentation, the text appears by pointing the mouse cursor on the block and keeping the cursor immobile for few seconds.

The blocks of the Blocks menu are organized by output type. The table below lists the built-in blocks; the Routing blocks reference gives the details and examples of each block.
| Menu | Block | Inputs | Result |
|---|---|---|---|
| any | v |
– | The value being routed. |
| any | source_value, dest_value |
– | Current value of the route source / destination address. |
| any | address_value |
address | Current value of any address. |
| any | filter |
value, condition | The value when the condition is true, otherwise nothing: the routing stops. |
| any | triggered_by |
value, trigger | The value, only when the execution was triggered by the selected event (value, status, refresh, gateway). |
| any | if_else |
condition, if_true, else | One of the two values, depending on the condition. |
| any | get |
value, property | A sub-property of an object (a.b.c). |
| any | last |
value | The value of the previous execution (nothing on the first execution: the routing stops). |
| any | delay |
value, ms, concurrent (advanced: scope, skip_delay) | The value, after the delay. concurrent tells what happens when a new value arrives before the end of the delay: ignore old (default), ignore old and reset, ignore new, parallel. |
| any | some |
list of inputs | The first input that returns a value. |
| any | each |
list of inputs | Executes all the inputs in order and returns the last result. |
| any | variable |
name (hidden input: set) | Reads a variable kept between executions, one per source → destination pair; writes it when set is connected. |
| any | script |
function, named inputs | A JavaScript function with named inputs (section 5). |
| number | scale |
number, factor | number × factor |
| number | linear |
number, factor, offset | number × factor + offset |
| number | calculate |
number, operator, operand | +, -, *, /, max, min, avg |
| number | round |
number, decimals, method | round, floor or ceil. decimals 0 = integer, -1 = 0.1, -2 = 0.01, 2 = 100. |
| number | abs |
number | Absolute value. |
| number | cov |
number | Difference with the value of the previous execution (nothing on the first execution). |
| number | covOverTime |
number, unit | Difference with the previous execution divided by the elapsed time, per millisecond (default), second, minute, hour or day. Turns a meter index (kWh, m³) into a rate (kW, m³/h). Nothing on the first execution. |
| number | to_number, indexOf, lastIndexOf |
value / text | Conversion to a number; position of a text inside a string. |
| boolean | compare |
number, operator, operand | >, <, <=, >=, =, ≠ |
| boolean | cov_passed |
number, cov (advanced: down) | True when the value rose by at least cov, or fell by at least down, since the last routed value; true on the first execution. Without down, a decrease never returns true. |
| boolean | or, not, to_boolean |
list of inputs / value | Logic. |
| string | trigger |
– | The event that triggered the execution. |
| string | source_status, dest_status, address_status |
– / address | Status of an address (online, offline, pending, or an error). |
| string | to_string, substring |
value / start, end | Conversion to text; part of a string. |
| object | wrap |
value, property | A new object holding the value under the given key. |
| object | set |
object, key, value | The object, with one property changed. |
| object | stream |
address, options | A stream object, to transfer large data to a streamable destination address. |
| address | source, dest, address |
– / name | The address object of the route source, of its destination, or of any address. |
Inputs marked advanced are shown with the advanced entry of the block context menu. Hidden inputs (for example set on the variable block, or position on indexOf) are shown by ticking their name in the same menu.
This section describes the step by step procedure to create a new custom block. The main advantage of custom blocks is the ability to import/export blocks and use those on different devices / sites / projects.
The new block is created by drag & dropping the Create New Block block. Once created, the new block is automatically renamed to new_block_#.

A custom block can be edited either by double clicking on it or using the right click context menu as shown below. After clicking Edit, a new tab with the name of the custom block is added and opened.

When the tab title of the block is clicked, a popup windows opens. From that window, the block can be renamed. Here it is named F_to_C as it will be used to demonstrate a temperature unit conversion from Fahrenheit degrees to Celsius degrees.

The edition of custom blocks follows the same principle as seen before. You can drag & drop blocks from the left menu and combine those together. In the example below, the block calculate is used to subtract 32 and then divide by 1.8 for the unit conversion. Custom blocks have special blocks to define their inputs. Custom blocks can have any number of inputs. Here the block has one input of type number, named F for Fahrenheit. Once saved with the save button on the tab title, the custom block can be used in the routing function diagram (here Example route).

Customs block can be documented by adding a comment to its output block (first block on the top left). To do so, right click on the block and then select Add Comment. Once saved, the comment is shown as a block tooltip documentation for the technicians / users.

Custom blocks can be duplicated using the context menu. It is a convenient way to create a new custom block without starting it from scratch. This is shown in the screenshot below.

Custom blocks can be organized in a folders / subfolders hierarchy. To do so you can simply rename the block and separate each hierarchy folder with a dot such as renaming F_to_C into units.F_to_C. There is no hard limit in the number of hierarchical levels but in practice it is better to limit oneself to maximum 1 or 2 dots. The example below shows a 3 level category.

It is easy to import / export blocks from one category, as show in the example below, here the category units has 2 blocks (units.F_to_C and units.MS_to_KMH). The blocks can be exported to a file by right-clicking the given category (here units).

Custom blocks that have no categories appear in the generic block section. In the example below, you can see that there is only one custom block without categories named F_to_C. By right-clicking on the block section, you can import blocks from a file, export all Blocks (independently of their categories or absence of categories), or export solely blocks that have no categories (here the F_to_C block).

Each blocks file is in fact a JavaScript object. Each key of the object is the name of the block and the corresponding value is a function containing the block code. Below is an example of a blocks file (named allBlocks.js) obtained by exporting all Blocks from our device.
{
"F_to_C" : () => {
calculate(calculate(input_number("F"),"-",32),"/",1.8)
},
"F_to_C_2" : () => {
calculate(calculate(input_number("F"),"-",32),"/",1.8)
},
"units.A.MS_to_KMH" : () => {
scale(3.6,v)
},
"units.A.Z.MS_to_KMH" : () => {
scale(3.6,v)
},
"units.B.MS_to_KMH" : () => {
scale(3.6,v)
},
"units.F_to_C" : () => {
calculate(calculate(input_number("F"),"-",32),"/",1.8)
},
"units.MS_to_KMH" : () => {
scale(3.6,v)
}
}
_ and $, and does not start with a digit. Dots separate the categories (units.F_to_C) and each part follows the same rule. Spaces are replaced by _. JavaScript reserved words (double, int, class, default, …) are refused.any, boolean, number, string, object and address inputs, a custom block can declare an enum input (a drop-down list) and a list of inputs (input array, 1 to 20 inputs). Right-click an input block and tick default value to give the input a default value; for an enum input, tick options and type the choices separated by commas.Programmers can directly write code in JavaScript for their routing functions. In fact each block is a JavaScript function and block diagrams are combinations of JavaScript functions. JavaScript function can be written directly in the code editor and are translated to a constant value block of return type any. This is shown below in a function that converts Fahrenheit degrees to Celsius degrees.

The routing function receives the following arguments (all optional):
v: the value being routed (a number, a string, an object…).
src: the source address object.
dst: the destination address object.
options: the execution context: the trigger of the execution, the route, a context object shared by the blocks of the route and a functionContext object private to this function, callId (incremented at each call), and the runtime controls. This argument is described once, with all its properties, in section 2.6.1 of the Routes page. Older examples name it info: it is the same object.
callback (optional). If the function has an argument named callback, then the function becomes asynchronous (which means the result of the function doesn't need to be returned directly, but can be returned later by calling the callback function). This permits to use JavaScript async functions, such as setTimeout calls for adding a delay, or calls to other APIs. The callback must be called within 30 seconds; after this delay the execution is cancelled with a timeout error. The example below shows a function called temporize which adds a 1 second delay and in case of parallel executions only keeps the last execution. The built-in delay block, with concurrent set to ignore old and reset, does the same without code.
function temporize(v, src, dst, options, callback){
var myCallId = options.callId //store the call id in a local variable.
options.functionContext.lastCallId = myCallId //store it in the functionContext.
//wait 1000 ms
setTimeout(function(){
if(myCallId == options.functionContext.lastCallId){
// There is no other parallel executions, return the value to be routed.
callback(null,v)
}else{
// There is another later execution of this block,
// returns the null value which cancels this execution of the route.
callback(null,null)
}
},1000)
}
It shall be noted for advanced users that the this JavaScript keyword in all routing functions refers to the gateways API object, making it possible to make API calls inside the routing functions like this.getAddress(...), this.readValue(...), this.writeValue(...), etc...
The limitation of using direct JavaScript functions lies on the fact that their corresponding block in the diagram does not have any inputs, making it hard to combine those with other existing blocks. The script block solves this problem by providing any number of named inputs and making those inputs accessible from its code. This permits to use the results of other blocks in our JavaScript code. The script block first and main parameter is its JavaScript function. It can be edited by clicking on its name on the block (in screenshot below the name is filter). Once clicked, it opens the code editor. The function arguments are optional and the same as described in the previous section. Usually the function arguments are not used and left empty, using instead solely the script block named inputs. The named input are accessible from the this keyword and the given input name. It shall also be noted that the gateways API object can be accessed with this.gateways. In the example below, the script block filters out values bigger or equal to the value stored in the $temperature internal address.
