I have made a Lua script that monitor with PingSensor if my or my wife is present. If not, it will close all the lights, music, close the blinds and lock the door.
My issue is that one in a while, I get a error on the script and Lua hangs.
I tried all kind of codes to fix that issue but since I didn’t pin point when it happends, I’m screwed.
Any thoughts?
LuaUpnp Log.
08 06/12/16 15:26:29.100 Scene::RunScene running 91 Presence <0x2bd26680>
01 06/12/16 15:26:29.101 LuaInterface::CallFunction_Scene Scene 91 failed attempt to call a nil value <0x2bd26680>
Scene Lua:
function nopresence(log)
if log == “1” then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(os.date().. " ")
filewrite:flush()
filewrite:close()
end
--[[ If No one if home, flip the VShitch. --]]
local VSSebHome = assert(tostring(luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status", 847)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" VSSebHome:"..VSSebHome)
filewrite:flush()
filewrite:close()
end
local VSTashaHome = assert(tostring(luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status", 848)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" VSTashaHome:"..VSTashaHome)
filewrite:flush()
filewrite:close()
end
local PingSebHome = assert(tostring(luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped", 843)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" PingSebHome:"..PingSebHome)
filewrite:flush()
filewrite:close()
end
local PingTashaHome = assert(tostring(luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped", 846)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" PingTashaHome:"..PingTashaHome)
filewrite:flush()
filewrite:close()
end
local PingNotSebHome = assert(tostring(luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",849)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" PingNotSebHome:"..PingNotSebHome)
filewrite:flush()
filewrite:close()
end
local PingNotTashaHome = assert(tostring(luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",850)),"1")
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" PingNotTashaHome:"..PingNotTashaHome)
filewrite:flush()
filewrite:close()
end
local res,mode = luup.inet.wget("http://192.168.1.146:3480/data_request?id=variableget&Variable=Mode",5)
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Mode:"..mode)
filewrite:flush()
filewrite:close()
end
mode = assert(tostring(mode),"1")
--[[ If seb not home and reverse tripped, change status VS to 0 --]]
if (PingSebHome == "0" and PingNotSebHome == "1") then
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Seb not home ")
filewrite:flush()
filewrite:close()
end
luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "0"}, 847)
end
if (PingSebHome == "1" and PingNotSebHome == "0") then
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Seb is home ")
filewrite:flush()
filewrite:close()
end
luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "1"}, 847)
end
--[[ If Tasha not home and reverse tripped, change status VS to 0 --]]
if (PingTashaHome == "0" and PingNotTashaHome == "1") then
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Tasha not home ")
filewrite:flush()
filewrite:close()
end
luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "0"}, 848)
end
if (PingTashaHome == "1" and PingNotTashaHome == "0") then
luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "1"}, 848)
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Tasha is home ")
filewrite:flush()
filewrite:close()
end
end
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" check 1 ")
filewrite:flush()
filewrite:close()
end
if (VSSebHome == "0" and PingNotSebHome == "1") then
if (VSTashaHome == "0" and PingNotTashaHome== "1") then
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" Nobody home ")
filewrite:flush()
filewrite:close()
end
luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "0"}, 845)
end
end
if log == “1” then
local filewrite = io.open(“/mnt/usb/lognopresence.txt”, “a”)
filewrite:write(" check 2 ")
filewrite:flush()
filewrite:close()
end
if log == "1" then
local filewrite = io.open("/mnt/usb/lognopresence.txt", "a")
filewrite:write(" ", "\n")
filewrite:flush()
filewrite:close()
end
end
nopresence(“1”)