Below is the script it is referring to, with line 35 being "timeon = (tonumber(onmode) * 60) - 1" :-Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_time_PIRs.lua: /home/pi/domoticz/scripts/lua/script_time_PIRs.lua:35: attempt to perform arithmetic on a nil value
Code: Select all
-- ~/domoticz/scripts/lua/script_time_pirs.lua
-- Each of the motion sensors in Domoticz follow this name convention:
-- PIRxrzSwitchName or PIRxgzGroupName
-- x speicifies when the PIR controls - a=all day, n=nighttime, d=daytime,
-- 1=custom timer 1 set to 22:00 to 07:30
-- y specifies what the PIR is controlling -
-- r = room (single Domoticz) switch and g = group
-- z specifies how long the ligth will stay on for in minutes, so z = 5 turns
-- the switch or the group on for 5 minutes
-- N.B. be careful as currently there is little error checking so wrongly
-- named PIRs in Domoticz may cause an error
-- N.B. one wrongly named PIR may stop the script, check log for any issues
function timedifference(s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
for i, v in pairs(otherdevices) do
tc = tostring(i)
v = i:sub(1,3)
if (v == 'PIR') then
onmode = i:sub(6,6)
if onmode ~= "u" then
timeon = (tonumber(onmode) * 60) - 1
-- print(tostring(60 * tonumber(onmode) ^ 2) - 1)
difference = timedifference(otherdevices_lastupdate[tc])
-- print(i..difference)
if (difference > timeon and difference < (timeon + 60)) then
tempdiff = tostring(difference)
c = i:sub(7)
if i:sub(5,5) == "g" then
c="Group:"..c
end
tempmessage = c.." Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
print(tempmessage)
commandArray[c] = 'Off'
end
end
end
end
return commandArray
Any idea why I am getting the error?