Logic Machine Forum
Retrieving Trend Data via periods.lp - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Application Store (https://forum.logicmachine.net/forumdisplay.php?fid=11)
+--- Thread: Retrieving Trend Data via periods.lp (/showthread.php?tid=6102)



Retrieving Trend Data via periods.lp - hocine - 04.09.2025

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!


RE: Retrieving Trend Data via periods.lp - Daniel - 04.09.2025

https://kb.logicmachine.net/libraries/trends/


RE: Retrieving Trend Data via periods.lp - hocine - 04.09.2025

(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"
  },



RE: Retrieving Trend Data via periods.lp - Daniel - 04.09.2025

What is your full script?


RE: Retrieving Trend Data via periods.lp - hocine - 04.09.2025

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"
  }
}