I have a simple Lua script that after no motion (between 2 motion sensors) has been detected for 20 minutes then lights turn off. my script is not working properly the lights keep turning off after a few seconds of the last motion sensor becoming safe. Can someone see what I have done wrong in the script. Thanks!
--[[
%% autostart
%% properties
51 value
86 value
%% weather
%% events
%% globals
Day_night
--]]
local startSource = fibaro:getSourceTrigger();
if (