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.

Calculate Daily, Monthly, and Yearly Energy from Trend
#5
Instead of making one script per trend you can use a single script for multiple trends:
Code:
mapping = {
  { trend = 'energy A', output = '0/0/1' },
  { trend = 'energy B', output = '0/0/2' },
  { trend = 'energy C', output = '0/0/3' },
}

require('trends')

dates = {}
dates['start'] = os.date('*t')
dates['end'] = os.date('*t')
dates['end'].day = dates['end'].day + 1

for _, map in ipairs(mapping) do
  sum = 0
  values = trends.fetch(map.trend, dates)

  for _, value in ipairs(values) do
    sum = sum + (value or 0)
  end

  grp.checkupdate(map.output, sum)
  os.sleep(1)
end
Reply


Messages In This Thread
RE: Calculate Daily, Monthly, and Yearly Energy from Trend - by admin - 10.04.2026, 13:29

Forum Jump: