# Run & Process (Rules and Scripts)

return to Blockly Reference

# 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

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.

# Overview of the Run & Process blocks

run-and-process-blocks

# Run & Process Blocks

See also the short video part about youtube Run & Process blocks, transform (opens new window)

# Call Script File

run-script-file

Function: Calls a script file with the given name which must be located in the $OPENHAB_CONF/scripts/ folder.

  • No parameters can be provided

See openHAB Call-Script (opens new window) for background information

# Run Rule or Script created in UI

run-rule-or-script

Function: calls another rule or script that was created via the openHAB UI.

The ruleUID can be found in the list of rules or scripts in the second line of the list (like here helloBlockly or helloWorld) rule-uuid

Parameters are optional:

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)

retrieve-context

This retrieves the value for the key "myKey1" that was passed by the calling rule.

Example

retrieve-context-example

# Retrieve rule context information

retrieve-context-info

Function: Retrieve event context related information of the rule

A rule carries contextual information when triggered - this block can retrieve that information.

# Transform values via Map, Regex or JsonPath and others

OpenHAB provides many transformations (opens new window):

The following describes examples for Map, Regex, and JsonPath

map regex jsonpath

Function: Transform the given value via one of the different transformation methods

# Example 1: Regex

Convert #123456 into rgb(12,34,56)

transform-regex

# Example 2: JsonPath transformation

Extract the temperature from the following JSON

{ "device": { "location": "Outside", "status": { "temperature": 23.2 }}}

by using the jsonpath

$.device.status.temperature

transform-jsonpath

# Example 3: Map transformation

This example applies a map transformation from the map file nanoleaf.map in $OPENHAB-CONF/transform/

transform-map

The above, with the below map file

ON=Ja
OFF=Nein
effects=Effekte
-=?
NULL=n/a
hs = Hue/Saturation
ct = Color Temperature

would result in the following log entry

Hue/Saturation

# Inline Script

inline-script

Function: execute arbitrary ECMAScript content

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.

# Example

inline-script-example

See also the short video part about youtube Inline Scripts (opens new window)

# Return to Blockly Reference

return to Blockly Reference