23.06.2020, 05:46
(This post was last modified: 23.06.2020, 05:49 by benanderson_475.)
I want to get the highest time and then switch the groups on in the order from highest time(stored in on_time) to lowest time until all the groups are on, groups/ range i am interested in are 1/1/1 to 1/1/20
i am storing the obj.updatetime in a table with the associated address etc as below
Then i want to get the highest value from all the t.on_time/s and switch each off, in order from the longest off value (stored in on_time) until all the complete range 1/1/1 - 1/1/20 are all off
this runs from a function which is called from a scheduled script every x minutes.
This is where i am stuck, this is what i have so far, my question is how can i calculate the highest on_time value and what will happen if two possibility have the same on_time value?
I hope this is making sense....
i am storing the obj.updatetime in a table with the associated address etc as below
Code:
function chk_off()
t ={}
for i = 1, 20 do
addr = '1/1/'.. tostring(i)
obj = grp.find(addr)
if obj and obj.value == 0 then
--put all off obj in table with update time
table.insert(t, {address = addr, level = obj.value, upd_time = obj.updatetime, on_time = os.time() -obj.updatetime } )
end
end
return t
end
Then i want to get the highest value from all the t.on_time/s and switch each off, in order from the longest off value (stored in on_time) until all the complete range 1/1/1 - 1/1/20 are all off
this runs from a function which is called from a scheduled script every x minutes.
This is where i am stuck, this is what i have so far, my question is how can i calculate the highest on_time value and what will happen if two possibility have the same on_time value?
I hope this is making sense....
Code:
function load_time_off()
t = chk_off()
if t then
for k, v in ipairs(t) do
log(v.on_time) -- this gives me all the on_time vals
-- how to get highest on_time value?? and switch on the associated address
end
end
end