Übersicht Script programming

This function block can be used to program your own scripts in high-level language. Lua (www.lua.org) is used as interpreter. In this description only the language extensions are discussed.


Inputs

E1-x
Input 1-x
Inputs. These can be addressed in the script via the global variables E1, E2, etc. For a better overview, alias names can also be assigned to them.



Outputs

A1-Ax
Output 1-x
Inputs. These can be addressed in the script via the global variables A1, A2, etc. For a better overview, alias names can also be assigned to them.



Parameter

Number of inputs
number of inputs
Number of outputs
number of outputs
Eventfilter
By default, events or telegrams are only forwarded to the function block if the corresponding variables are connected at the inputs or outputs. By switching off this filter, all events are forwarded to the function block. Please note that the processing of all events takes considerably more processing time, the filter should therefore only be deactivated if absolutely necessary.
Edit
Click on this button to edit the script, alternatively you can also right-click on the function block.


Editing window

Click on the Edit parameter or right-click on the function block to display the dialog for editing the script:



This dialog is divided into the following three areas:

  1. Script: Here the script is edited.
  2. Console: This window displays all interpreter output, such as info and error messages or messages sent with the function call "sys_debug_print".
  3. Variables: This window is used to send the value of internal variables. Unlike the Console window, the output is not continuous but in a table. Which variables are displayed here is defined with the function call "sys_debug_watch".
Important: To send messages or variables, the Play button must be pressed. By clicking on Save, the script is transferred to the controller and executed immediately, but only if the Play button is pressed:




By default, there is only the function "onInputChanged()" in the script. This function is called when something has changed at the inputs. For most applications this is sufficient. With the menu button you can add more system functions. These so-called callback functions are described in the following:

Important: Callback functions must not block. For example, if endless loops are programmed here, the internal watchdog timer is triggered and the runtime is reset. Generally the function calls should be processed as fast as possible (e.g. no sleep functions or loops that take a long time to process).

onCreate()
This function is called once when the function block is initialized. For example, you can define initializations of global variables here.
onInputChanged()
This function is called if something has changed at the inputs.
onEvent(Value,Phys_Address,Group_Address,Command)This function is called when a telegram is received, for example a KNX variable connected to the input. By default, only telegrams which are connected to the inputs are passed on to the script, this can be deactivated with the "Event filter" parameter.

The following arguments are passed to the function:

  • Value: Value
  • Phys_Address: Source address in "0.0.1" format
  • Group_Address: Destination address in "0/0/1" format
  • Command: Commands, WRITE, RESPONSE, READ

Important: This function should only be used if it is really necessary to react to telegrams, for example KNX telegrams. If possible the function onInputChanged should be used. If onEvent is activated, the telegrams are forwarded to the interpreter, which results in a higher load on the controller.


onTimerEvent100ms() This function is called once per 100 milliseconds.
onTimerEvent1s()
This function is called once per second.
onTimerEvent1m()
This function is called once per minute. The call is always made at the beginning of each minute.
onTimerEvent1h()
This function is called once per hour. The call is always made at the beginning of each hour.


System calls

The following system calls are currently integrated.



sys_write_value("0/0/0",value,force)
Write any variable:

The variable is only sent when the value has changed. This allows the function to be called cyclically.

  • value: Value
  • force: If 1, the variable is always sent, even if the value has not changed.
sys_get_value("0/0/0")
Query the value of a variable

  • The address is passed as argument in the form "0/0/0".

sys_debug_print("Text: ",value)
Output of a text in the console. With each call a new line is sent to the debug console, this can be used to check if a function has been called. The function is given two arguments:

  • Text: Any text
  • value: Any value (texts must be put in quotation marks)

sys_alias("E1","Wert_xy")
With this function a symbolic name can be assigned to an input or output. These are then also displayed in the window for the links.

Important: Aliases must be defined in the function "onCreate()". The alias names must not contain spaces, umlauts or special characters.

  • sys_alias("E1","Outdoor_Temperature"): Assigns the name "Outdoor_Temperature" to the first input, this can then be addressed as "Outdoor_Temperature" in the following script. Example if (Outdoor_Temperature > 10 ).
  • sys_alias("A1","Setpoint"): Assigns the name "Setpoint" to output A1, this can be addressed at the "Setpoint" in the following script. For example "Setpoint = 10".

sys_get_addr_in(1) Returns the address of the linked variable of an input in the format "1/2/3", where 1 is E1 etc.
sys_get_addr_out(1) Returns the address of the linked variable of an output in the format "1/2/3", where 1 is A1 etc.
sys_set_persistent_value("Name","Value") With this function, any data can be stored in the persistent area of the controller.

Important: The controller is equipped with a flash memory that cannot be written to as often as required. This function must therefore not be called  too often. Continuous saving of persistent values shortens the lifetime of the flash memory and leads to a defect or loss of data.
sys_get_persistent_value("Name","DefaultValue") With this function the persistent values can be read out again.






See also general parameters of all function blocks.