Frequently asked questions
How to troubleshoot C-Bus Automation Controller LUA Scripts
FAQ000268379
24 July 2024
C-Bus Application and Network Automation Controllers utilize LUA scripting to provide an additional level of customizable functionality via LUA event-based, resident or scheduled LUA scripting. The following troubleshooting tips can assist in troubleshooting LUA script issues.Save Script - Syntax errors are shown when saving the script
These errors relate to general LUA command/statement syntax
example 1: in following if - then - else - end condition the following LUA script is missing the closing "end" statement
if (StrRmReedSwitch == false) then
-- Turn ON the Store Room Alarm and Alarm Light
SetCBusState(0, 56, 77, true)
SetCBusState(0, 56, 79, true)
else
SetCBusState(0, 56, 77, false)
SetCBusState(0, 56, 79, false)
results in the following error when attempting to save
Show Error Logs - Logical errors are shown when "Error log" is selected (1), and from the Error log window selecting "Show errors only for current script" (2) and "Clear" (3) then running the LUA script - by changing related object statuses etc in Object Tab, Visualization or Run Script
Logic errors relate to logical issues with the LUA Script such as trying to retrieve the state of an uninitialized group or trying to retrieve the state of a group that does not exist, or performing incompatible arithmetic etc.
example 2: Library cbuslogic:0: unable to find 0/56/250 --- (check if application 56, group address 250 object exists?)
example 3: Library cbuslogic:0: unable to decode 0/56/150 --- (check if application 56, group address 150 object currently nil "un-initialized")
example 4: User script:5: attempt to perform arithmetic on global 'StmRmTempSwitch' (a nil value) stack traceback: --- (check compatibility of arithmetic)
The following LUA script tries to perform a mathematical addition of a boolean returned from GetCBusState and an integer value resulting in Error log message
-- Get state of Store Room - Reed Switch on the local network
StmRmTempSwitch = GetCBusState(0, 56, 78)
IntValue = 5
CalcValue = IntValue + StmRmTempSwtich
Log messages which can help further troubleshoot LUA script issues are shown when "Log" is selected (1), and from the Current logs window selecting "Show logs only for current script" (2) and "Clear" (3) then running the LUA script - by changing related object statuses etc in Object Tab, Visualization or Run Script
Log messages can be used to log values of c-bus states, levels, variables and determine whether expected conditional and behavior is being met or may provide answer why a condition is not met and a certain block of the LUA script is not being executed.
example 5: Running the following script shown in image and turning the Strong Room Reed Switch group OFF and ON shows script is working as expected.