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
#8
Thanks! Here my version of the code. I use an object with a slider to allow us to set the auto-off value in minutes via the Visualization. I have it in a resident script with 60 seconds update. Works well.


Code:
ontime = grp.getvalue('9/4/0') * 60 -- autooff group in minutes * 60 seconds

-- 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
 istrue = toboolean(object.data)
 if istrue then
   delta = now - object.updatetime
   -- timer expired, turn off
   if delta >= ontime then
     object:write(0)
   end
 end
end
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
RE: Turn off light in 4 hours - by managementboy - 01.02.2016, 10:24

Forum Jump: