I just received my Fibaro Multi-Sensor a couple of days ago and started writing a timed (runs every minute) lua script. The goal is to get the lights on between 6:30 and 23:00 when there was motion for the last 15 minutes and the amount of lux was below 15. Also, when it is past 23:00 and there was no motion longer than 15 minutes, the lights should go off (See script below).
Now, this seems to work quite nicely (any approvements are welcome) but now when I switch off a light manually during the period that the script tells it that it should be on, it will get back on again (of course). So...is there an option to say something like: hey, switch on the lights if needed but don't do so for lights that where manually switched off in the meantime. The same goes for the other way around, when I switch a light on when the motion script tells it to be off.
Any help appreciated.
Code: Select all
commandArray = {};
function dateToTime (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)
return os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds};
end
function diffTime (t)
currentTime = os.time();
return os.difftime(currentTime, t);
end
motionTreshold = 600; -- 15 min
luxTreshold = 15;
currentDate = os.date('*t');
startTime = os.time{year=currentDate.year, month=currentDate.month, day=currentDate.day, hour='6', min='30', sec='0'};
endTime = os.time{year=currentDate.year, month=currentDate.month, day=currentDate.day, hour='23', min='0', sec='0'};
motionDiff = diffTime(dateToTime(otherdevices_lastupdate['MS Woonkamer']));
startDiff = diffTime(startTime);
endDiff = diffTime(endTime);
numberOfLux = tonumber(otherdevices_svalues['LX Woonkamer']);
isDayTime = (startDiff >= 0 and endDiff <= 0);
isNightTime = (startDiff > 0 and endDiff > 0);
isMotionWithinTreshold = (motionDiff <= motionTreshold);
isLuxWithinTreshold = numberOfLux <= luxTreshold;
print('Checking lights status. StartDiff: ' .. startDiff .. ', EndDiff: ' .. endDiff .. ', motionDiff: ' .. motionDiff .. ', Lux: ' .. numberOfLux);
-- Turning lights on
if
isDayTime and
isMotionWithinTreshold and
isLuxWithinTreshold
then
commandArray['Scene:Basis verlichting woonkamer'] = 'On';
print('Turning on basis verlichting woonkamer.');
end
-- Turning lights off
if
(isNightTime and not isMotionWithinTreshold) or
not isLuxWithinTreshold
then
commandArray['DS Alles uit'] = 'On';
print('Turning off all lights.');
end
return commandArray;