01.02.2016, 10:24
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