2022-02-20 09:21:55 +00:00
---
layout: documentation
2022-05-30 20:04:44 +00:00
title: Rules Blockly - Run & Process and Transformations
2022-02-20 09:21:55 +00:00
---
<!-- markdownlint - disable MD036 -->
# Run & Process (Rules and Scripts)
[return to Blockly Reference ](index.html#run-process-rules-and-scripts )
## Introduction
This section contains several possibilities
- Calling Rules or other scripts either located as files on the server or provided via the UI
- Retrieving attributes provided by the rule context or from the own caller rule.
- Transforming values via different conversion methods (map, regex, jsonpath)
**A note about Rules and Scripts**
2022-11-03 17:43:14 +00:00
A Script _is_ a Rule too. It’ s just a special type of rule that only has a single script action and a “Script” tag.
2022-02-20 09:21:55 +00:00
2022-11-24 17:35:16 +00:00
[[toc]]
2022-02-20 09:21:55 +00:00
## Overview of the Run & Process blocks

## Run & Process Blocks
2022-09-10 16:05:57 +00:00
See also the short video part about  [Run & Process blocks, transform ](https://youtu.be/KwhYKy1_qVk?t=2110 )
2022-02-20 09:21:55 +00:00
### Call Script File

2022-11-03 17:43:14 +00:00
_Function:_ Calls a script file with the given name which must be located in the _$OPENHAB_CONF/scripts/_ folder.
2022-02-20 09:21:55 +00:00
- No parameters can be provided
2022-03-09 20:58:42 +00:00
See [openHAB Call-Script ](https://www.openhab.org/docs/configuration/actions.html#openhab-subsystem-actions ) for background information
2022-02-20 09:21:55 +00:00
### Run Rule or Script created in UI

2022-11-03 17:43:14 +00:00
_Function:_ calls another _rule_ or _script_ that was created via the openHAB UI.
2022-02-20 09:21:55 +00:00
2022-11-03 17:43:14 +00:00
The _ruleUID_ can be found in the list of rules or scripts in the second line of the list (like here _helloBlockly_ or _helloWorld_ )
2022-02-20 09:21:55 +00:00

Parameters are optional:
2022-11-03 17:43:14 +00:00
- If not providing parameters leave the _with context_ section as is.
- If providing parameters you **must** replace the _create empty dictionary_ block with [the _dictionary_ block from the Lists section ](https://community.openhab.org/t/blockly-reference/128785#lists-76 ), modifying the number of key/value pairs to suit.
2022-02-20 09:21:55 +00:00
Notes:
- parameters can be retrieved in the called script via the "get context attribute"-block (see below)
- the called rule / script cannot return any value
- it is not possible to access a particular function in another script or rule as scripts / rules have to be perceived as completely autonomous
- the called rule / script is run synchronously
### Retrieve context attribute from rule
Function: Retrieve context attributes passed by a calling rule/script (see above)

This retrieves the value for the key "myKey1" that was passed by the calling rule.
2022-11-03 17:43:14 +00:00
_Example_
2022-02-20 09:21:55 +00:00

### Retrieve rule context information

2022-11-03 17:43:14 +00:00
_Function:_ Retrieve event context related information of the rule
2022-02-20 09:21:55 +00:00
A rule carries contextual information when triggered - this block can retrieve that information.
2023-07-29 08:18:47 +00:00
- The rule trigger type defines which of the attributes are available to the rule - the types available depend on the trigger type of the rule.
2023-07-02 15:58:17 +00:00
- For more detailed information see [UI Event Object ](https://next.openhab.org/addons/automation/jsscripting/#ui-event-object ) or [openHAB Events ](https://www.openhab.org/docs/developer/utils/events.html ).
2022-02-20 09:21:55 +00:00
2023-07-29 08:18:47 +00:00
Here is a list of possible values that can be retrieved.
- rule UID - String
- event type - String
- new state of item - String / Number by selection
- previous state of item - String / Number by selection
- triggering item name - [Item ](rules-blockly-items-things.html#item ), not a String
- received command - String / Number by selection
- triggered channel - String
- triggered event - String
The block adds a selection drop down in case a state or command is returned:

2022-02-20 09:21:55 +00:00
## Transform values via Map, Regex or JsonPath and others
2022-12-26 22:08:42 +00:00
openHAB provides many [transformations ](https://www.openhab.org/docs/configuration/transformations.html ):
2022-02-20 09:21:55 +00:00
- [Map ](https://www.openhab.org/addons/transformations/map/ )
- [Regex ](https://www.openhab.org/addons/transformations/regex/ )
- [JsonPath ](https://www.openhab.org/addons/transformations/jsonpath/ )
- [Binary to Json ](https://www.openhab.org/addons/transformations/bin2json/ )
- [Exec ](https://www.openhab.org/addons/transformations/exec/ )
- [Jinja ](https://www.openhab.org/addons/transformations/jinja/ )
- [Scale ](https://www.openhab.org/addons/transformations/scale/ )
- [XPath ](https://www.openhab.org/addons/transformations/xpath/ )
- [XSLT ](https://www.openhab.org/addons/transformations/xslt/ )
The following describes examples for Map, Regex, and JsonPath



Function: Transform the given value via one of the different transformation methods
### Example 1: Regex
Convert #123456 into rgb(12,34,56)

### Example 2: JsonPath transformation
Extract the temperature from the following JSON
```json
{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}
```
by using the jsonpath
```json
$.device.status.temperature
```

### Example 3: Map transformation
2022-11-03 17:43:14 +00:00
This example applies a map transformation from the map file nanoleaf.map in _$OPENHAB-CONF/transform/_
2022-02-20 09:21:55 +00:00

The above, with the below map file
```text
ON=Ja
OFF=Nein
effects=Effekte
-=?
NULL=n/a
hs = Hue/Saturation
ct = Color Temperature
```
would result in the following log entry
```bash
Hue/Saturation
```
## Inline Script

2022-11-03 17:43:14 +00:00
_Function:_ execute arbitrary ECMAScript content
2022-02-20 09:21:55 +00:00
Provides the possibility to inject any ECMAScript at a given position.
This should be used in cases when Blockly does not provide the desired functionality.
Use with diligence.
2022-07-05 19:22:53 +00:00
### Example
2022-02-20 09:21:55 +00:00

2022-09-10 16:05:57 +00:00
See also the short video part about  [Inline Scripts ](https://youtu.be/KwhYKy1_qVk?t=2165 )
2022-02-20 09:21:55 +00:00
## Return to Blockly Reference
[return to Blockly Reference ](index.html#run-process-rules-and-scripts )