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.

Turn off light in 4 hours
#3
If you want to turn objects that were on for a certain time, you need a scheduled or a resident script with large sleep time.

Add "AutoOff" tag to all objects that should be turned off after a certain time. The script below will work for both binary on/off and scaled 1-byte objects. Note that each "on" telegram will reset the auto-off timer for each object.

Code:
-- maximum time that object can be on, in seconds
ontime = 4 * 60 * 60

-- current timestamp, in seconds
now = os.time()

-- get all objects with AutoOff tag
objects = grp.tag('AutoOff')

-- check all objects
for _, object in ipairs(objects) do
 -- object is on
 if toboolean(object.data) then
   delta = now - object.updatetime

   -- timer expired, turn off
   if delta >= ontime then
     object:write(0)
   end
 end
end

Using os.sleep and event script is not a good idea - each event script runs in a separate process which will be active for 4 hours. This will certainly exhaust all LM memory sooner or later. The system will reboot automatically in this case.
Reply


Messages In This Thread
Turn off light in 4 hours - by RSV4 - 18.07.2015, 10:48
RE: Turn off light in 4 hours - by Pawel - 18.07.2015, 18:51
RE: Turn off light in 4 hours - by admin - 20.07.2015, 06:10
RE: Turn off light in 4 hours - by RSV4 - 20.07.2015, 08:01
RE: Turn off light in 4 hours - by Pawel - 20.07.2015, 09:29
RE: Turn off light in 4 hours - by admin - 21.07.2015, 08:19
RE: Turn off light in 4 hours - by edgars - 22.01.2016, 07:58

Forum Jump: