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.

24h Temperature average
#6
(19.09.2022, 07:28)Daniel Wrote: https://forum.logicmachine.net/showthrea...7#pid17347

thanks Daniel for the pointer.

(19.09.2022, 08:15)admin Wrote: Another option is to use storage.

1. Event script to accumulate the values:
Code:
value = event.getvalue()
key = 'average'

storage.exec('incrbyfloat', key .. ':acc', value)
storage.exec('incr', key .. ':cnt')

2. Scheduled script to calculate the average and reset the accumulated values:
Code:
key = 'average'
acc = storage.get(key .. ':acc', 0)
cnt = storage.get(key .. ':cnt', 0)

avg = 0
if cnt > 0 then
  avg = acc / cnt
end

grp.update('1/1/1', avg)

storage.delete(key .. ':acc')
storage.delete(key .. ':cnt')

thank you very much, I shall try this too.
Reply


Messages In This Thread
24h Temperature average - by kropfm - 17.09.2022, 09:21
RE: 24h Temperature average - by kropfm - 21.09.2022, 18:23
RE: 24h Temperature average - by Daniel - 19.09.2022, 07:28
RE: 24h Temperature average - by kropfm - 22.09.2022, 03:49
RE: 24h Temperature average - by admin - 19.09.2022, 08:15

Forum Jump: