Since version 0.0.1.26, Lua scripting has been introduced.
Lua script is very simple and lightweight. Have a look at the Lua 5.1 reference manual for further info.
A script condition is a LUA script that is executed when the rule is evaluated. The return value is interpreted as a boolean.
<condition type="script"> return tonumber(obj("setpoint_room1")) > tonumber(obj("temp_room1")); </condition>
In versions before 0.0.1.28, the condition is evaluated twice. So be careful if you reuse variables from one execution to the next one, or if you display some text with lua print function, it will be executed twice. This bug is corrected since 0.0.1.28.
A script action is a LUA script that is executed when the action is executed.
<action type="script"> delta = obj("setpoint_room1")-obj("temp_room1"); value = math.min(math.max(100*delta, 255),0); print ("value = ", value); set("heat_room1", value); </action>
The following functions are available in LUA-scripts.
The function obj(object_id) allows to access the current value of a linknx object (the value is returned as a string). Available in Conditions and Actions.
Check if timestamp "ts" is an exception day. If no timestamp is given, the current time is used. Available in Conditions.
set(object_id, value) sets the current value of a linknx object to value. Available in Actions.
iosend(ioport, data) sends "data" to "ioport". See also [IO_Ports]. Available in Actions.
sleep(delay) suspends LUA script execution for "delay" seconds. Available in Actions.