This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

2 hour timer
#1
I need to switch the exterior lights off for the building 2 hours after store closes which is set by preset schedule time and switches group 2/2/2,

Currently i have an event script on 2/2/2(trigger from schedule) storing the os.time() at the scheduled time, then a resident script set to 60s checking the difference between 
the stored value and the current to see if time has expired like
Code:
schedule_off = grp.getvalue('2/2/2')


if not schedule_off  then -- (2/2/2 = false )
if os.time() - storage.get('store close') >=  60*120 then

--switch lights off
end
end
i only need this script to run while the 2 hr period is active then it can stop running until next time the schedule runs, where as at the moment it runs always when the schedule has triggered it until the next scheduled time switches it again. 

is there a way to receive the scheduled off time for the schedule (from the schedular) and add 2 hours to this then execute the off command after the 2 hour period?
like having an offset value for a specific timed schedule, the same as in sunrise/sunset + or - 1 hour etc? 


is there a better way to do it and what is best?
Reply
#2
Scheduled script that runs once a minute should be enough for this task.

If you want to find a certain event time, you can only do this via database query.
Change scheduler ID as needed. This example assumes that scheduler has only one event with 0/false value.
Code:
scheduler = 1 -- scheduler ID
query = 'SELECT * FROM scheduler_events WHERE scheduler=? AND (value=0 OR value="false")'
evt = db:getrow(query, scheduler)
log(evt.start_hour, evt.start_min)
Reply


Forum Jump: