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.

Retrieving Trend Data via periods.lp
#1
Hello everyone,

I'm currently building a custom energy monitoring application on Lm5. I’ve successfully accessed real-time values using 
grp.getvalue() and identified the key trends (energy, power, consumption, etc.).

Now I’d like to implement period-based calculations (daily, weekly, monthly, yearly) using the periods.lp file to track 
energy consumption over time.


 My goal is to:
  • Store the trend index at midnight (e.g. for photovoltaic energy)
  • Compare it with the current index to calculate daily production
  • Extend this logic to weekly, monthly, and yearly periods

 Questions:

  1. What is the recommended way to store and retrieve trend indexes at specific timestamps (e.g. midnight) using 
    periods.lp ?
  2. Is there a built-in API or LogicMachine function to manage periods and deltas?
  3. Should I create a custom structure inside periods.lp , or is there a standard format I should follow?
  4. Has anyone implemented similar logic for periodic energy calculations and could share best practices?
Thanks in advance for your help and insights!
Reply
#2
https://kb.logicmachine.net/libraries/trends/
------------------------------
Ctrl+F5
Reply
#3
(04.09.2025, 07:23)Daniel Wrote: https://kb.logicmachine.net/libraries/trends/

Error in ./www/apps/data/compteur4multi/libs/compteur4multi.lua at line 45: attempt to index global 'storage' (a nil value)

i always have this issue and i don't understand my mistake  
i have this at line 45

Code:
"dependencies": {
    "lua_modules": ["storage", "trend", "grp", "json"],
    "system_version": ">=2.5.0"
  },
Reply
#4
What is your full script?
------------------------------
Ctrl+F5
Reply
#5
I have a file app.json 

Code:
{
  "id": "compteur4multi",
  "title": "Compteur Multi-énergies",
  "version": "1.0.0",
  "author": "Schneider Electric",
  "description": "Calculs d'autoconsommation et d'autonomie photovoltaïque",
  "category": "energy",
  "tags": ["energy", "photovoltaic", "consumption", "monitoring"],
  "icon": "icon.svg",
  "main": "index.lp",
  "config": "config.lp",
  "permissions": {
    "storage": true,
    "trends": true,
    "groups": true,
    "scripts": true
  },
  "files": [
    "index.lp",
    "config.lp",
    "style.css",
    "compteur4multi.js",
    "icon.svg",
    "api/compute.lp",
    "api/config_save.lp",
    "api/periods.lp",
    "api/diag.lp",
    "libs/compteur4multi.lua",
    "libs/utils.lua"
  ],
  "dependencies": {
    "lua_modules": ["storage", "trend", "grp", "json"],
    "system_version": ">=2.5.0"
  },
  "installation": {
    "create_resident_script": true,
    "script_name": "compteur4multi_resident"
  }
}
Reply


Forum Jump: