I have a motion detector in Domoticz with the name "PIR Gang Voor". The ON function is working, but the OFF function, afther a couple of minutes is not working, it`s not going OFF.
I use these scripts: https://www.domoticz.com/wiki/Smart_Lua_Scripts
When a motion is detected i use this script. This works fine and the motion detector is going ON.
Code: Select all
-- ~/domoticz/scripts/lua/script_device_PIRs.lua
commandArray = {}
tc=next(devicechanged)
v=tostring(tc)
if (v:sub(1,3) == 'PIR') then
c=v:sub(4)
commandArray[c] = 'On'
tmess = c..' On - time 0'
print(tmess)
end
return commandArray
Code: Select all
-- ~/domoticz/scripts/lua/script_time_PIRs.lua
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
timeon = 120
tc = tostring(i)
v = i:sub(1,3)
if (v == 'PIR') then
difference = timedifference(otherdevices_lastupdate[tc])
if (difference > timeon and difference < (timeon + 60)) then
tempdiff = tostring(difference)
c = i:sub(4)
tempmessage = c.." Light Off - after at least " .. (timeon+1) .. "secs up - actually - " .. tempdiff .. "seconds"
print(tempmessage)
commandArray[c] = 'Off'
end
end
end
return commandArray
How come that the command commandArray[c] = 'Off' is not with the OFF command but is working with the ON command in the first script?