Hi Paul, This is really a Lua question but my debugging session is failing with the output below. I am guessing but it could be to do with a common scenario in Vera. The Luup library provided by MCV includes the function call_delay. It is used to schedule an action in the future e.g switch on bedroom light at 22:30. call_delay takes a function name to call, the delay period, and the device id and action to apply to the device. I am scheduling an action where the function that is activated is in the module I am debugging. I don't know anything about threading/reentrancy in Lua but the failure coincides with having scheduled an action that will be performed immediately. When I comment the call_delay line, I don't get the error. As far as I can see, the call_delay function argument has to be in the same module as the call_delay statement. I will check on this in the forum. I have pasted some MCV documentation at the bottom of this note that shows 'call_delay' in action. Regards, Clive Connecting to MCV Vera device at 192.168.0.200:3480... Program starting as '"D:\Products\ZeroBraneStudio for Lua\ZeroBraneStudio\bin\lua.exe" -e "local s = require('socket') local c = s.tcp() c:settimeout(5) function check(ok, err) if not ok then print(err); os.exit() end end check(c:connect('192.168.0.200', 3480)) check(c:send([[GET /data_request?id=lu_action&serviceId=urn:micasaverde-com:serviceId:HomeAutomationGateway1&action=RunLua&Code=require('mobdebug').loop('192.168.0.2',8172);require('mobdebug').done() HTTP/1.1]]..'\n\n')) c:settimeout(nil) local line, err = c:receive() c:close() if not line:find('200 OK') then print(err or line) end"'. Program 'lua.exe' started in 'D:\Development\MiCasaVerde\Vera\Luup\OccupiedVSwitch' (pid: 4920). Debugging session started in 'D:\Development\MiCasaVerde\Vera\Luup\OccupiedVSwitch\'. Debugging session completed (traced 30 instructions). D:\Products\ZeroBraneStudio for Lua\ZeroBraneStudio\bin\lua.exe: (command line):1: attempt to index local 'line' (a nil value) stack traceback: (command line):1: in main chunk [C]: ? Program completed in 112.97 seconds (pid: 4920; code: 1). Example Code from the MCV Documents Thermostat conditioned by door/window Turn off the thermostat if the door/window is left open for 5 minutes or more and back on if the door/window is closed for 10 minutes or more. 1. Create a scene and add a trigger to run the scene when the door sensor is tripped (door is opened). 2. Add this code in the Luup code box: local SENSOR = 17 -- The door/window sensor device number local THERMOSTAT = 3 -- The thermostat device number local DELAY = 300 -- Seconds local SES_SID = "urn:micasaverde-com:serviceId:SecuritySensor1" local HVACO_SID = "urn:upnp-org:serviceId:HVAC_UserOperatingMode1" luup.call_delay( "turnOffAc", DELAY) -- Turn off the thermostat if the sensor has been tripped for at least 5 minutes. function turnOffAc() local tripped = luup.variable_get( SES_SID, "Tripped", SENSOR) or "0" local lastTrip = luup.variable_get( SES_SID, "LastTrip", SENSOR) or os.time() if (tripped == "1" and (os.time() - lastTrip >= DELAY)) then local modeStatus = luup.variable_get( HVACO_SID, "ModeStatus", THERMOSTAT) or "Off" luup.variable_set( HVACO_SID, "LastModeStatus", modeStatus, THERMOSTAT) luup.call_action( HVACO_SID, "SetModeTarget", {NewModeTarget = "Off"}, THERMOSTAT) end end 3. Create another scene and add a trigger to run the scene when the door sensor is not tripped (door is closed). 4. Add this code in the Luup code box: local SENSOR = 17 -- The door/window sensor device number local THERMOSTAT = 3 -- The thermostat device number local DELAY = 600 -- Seconds local SES_SID = "urn:micasaverde-com:serviceId:SecuritySensor1" local HVACO_SID = "urn:upnp-org:serviceId:HVAC_UserOperatingMode1" luup.call_delay( "turnOnAc", DELAY) -- Turn on the thermostat if the sensor hasn't been tripped in the past 10 minutes. function turnOnAc() local tripped = luup.variable_get( SES_SID, "Tripped", SENSOR) or "0" local lastTrip = luup.variable_get( SES_SID, "LastTrip", SENSOR) or os.time() if (tripped == "0" and (os.time() - lastTrip >= DELAY)) then local lastModeStatus = luup.variable_get( HVACO_SID, "LastModeStatus", THERMOSTAT) or "Off" luup.call_action( HVACO_SID, "SetModeTarget", {NewModeTarget = lastModeStatus}, THERMOSTAT) end end5. Save. __________ Information from ESET NOD32 Antivirus, version of virus signature database 8570 (20130715) __________ The message was checked by ESET NOD32 Antivirus. http://www.eset.com