Logic Machine Forum
energy data - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: energy data (/showthread.php?tid=5314)



energy data - busta - 21.03.2024

How can I retrieve the energy consumption curve data? 
I have created curves for energy consumption ( kWh in counter mode ) and i would like to display daily consumption as well as the consumption for the past 3 days. I would also like to do the same for months and years."

I have this script but only day work 


require('trends')

os_date = os.date("*t")
os_end_date = {
  year = os_date.year,
  month = os_date.month,
  day = os_date.day + 1
  }
 

dates = {
  ['start'] = { year = os_date.year, month = os_date.month, day = os_date.day },
  ['end'] = { year = os_end_date.year, month = os_end_date.month, day = os_end_date.day },
}
--log(dates)
 
-- fetch current value
day = trends.fetchone(' Main ', dates)
--log(day)
grp.update('2/1/1', day)

month = trends.fetch(' Main ', dates)
--log(month)
grp.update('2/1/2', month)


RE: energy data - admin - 21.03.2024

Check this thread: https://forum.logicmachine.net/showthread.php?tid=4202
Example of loading trends data from Custom JS: https://forum.logicmachine.net/showthread.php?tid=3789&pid=34287#pid34287


RE: energy data - busta - 21.03.2024

(21.03.2024, 08:49)admin Wrote: Check this thread: https://forum.logicmachine.net/showthread.php?tid=4202
Example of loading trends data from Custom JS: https://forum.logicmachine.net/showthread.php?tid=3789&pid=34287#pid34287
 thx 

Do you know why my script don't work for month ?


RE: energy data - admin - 21.03.2024

You need to specify a different date period to get monthly data:
Code:
dates = {}
dates['start'] = os.date('*t')
dates['start'].month = dates['start'].month - 1
dates['end'] = os.date('*t')

month = trends.fetchone(' MAIN ', dates)

Example for yearly data: https://kb.logicmachine.net/libraries/trends/#examples