12.11.2022, 23:24
I couldn't understand how to transform that to a script that could be useful, so I googled lua average value and found this in another thread:
-- storage key
key = 'temp_average'
-- time between average value send (in seconds)
maxtime = 60 * 60
-- resulting average value
result = '4/3/34'
time = os.time()
data = storage.get(key)
if not data then
data = { values = {}, time = time }
end
value = event.getvalue()
table.insert(data.values, value)
delta = time - data.time
if delta >= maxtime or delta < 0 then
storage.delete(key)
avg = 0
count = #data.values
for _, value in ipairs(data.values) do
avg = avg + value
end
grp.write(result, avg / count)
else
storage.set(key, data)
end
Is there a way to make this start the count at the beginning of the clock hour?
-- storage key
key = 'temp_average'
-- time between average value send (in seconds)
maxtime = 60 * 60
-- resulting average value
result = '4/3/34'
time = os.time()
data = storage.get(key)
if not data then
data = { values = {}, time = time }
end
value = event.getvalue()
table.insert(data.values, value)
delta = time - data.time
if delta >= maxtime or delta < 0 then
storage.delete(key)
avg = 0
count = #data.values
for _, value in ipairs(data.values) do
avg = avg + value
end
grp.write(result, avg / count)
else
storage.set(key, data)
end
Is there a way to make this start the count at the beginning of the clock hour?