20.07.2015, 06:10
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.
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.
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.