Logic Machine Forum
Daily logging of produced energy from solar inverter - 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: Daily logging of produced energy from solar inverter (/showthread.php?tid=1429)



Daily logging of produced energy from solar inverter - tintsch - 06.06.2018

Hi,

I'd like to log the daily energy production (kWh) of my solar inverter.
I created a scheduled script running once a day. This script reads the energy production of the previous day from the inverter.

Is it possible to save daily data consisting of a timestamp and a value?

I tried to save it with the following script, but obviously the value of 'pv' gets overriden every time.


Code:
save = {
  ["Pac"] = PV_Pac,  -- PV_Pac is set to the energy value coming from the inverter
  ["timestamp"] = os.date('%Y-%m-%d', os.time()-24*60*60)  -- yesterday's timestamp
}
result = storage.set('pv', save)

Can data be appended with the storage object? Or how could this be accomplished?

The goal of this logging is to produce bar charts later on.

thanks!
Valentin


RE: Daily logging of produced energy from solar inverter - buuuudzik - 06.06.2018

Maybe better create table in storage:
Code:
pvLogs = storage.get('pvLogs')

toAdd = {
timestamp = os.time(),
Pac = PV_Pac
}

table.insert(pvLogs, toAdd)
storage.set('pvLogs', pvLogs)

In such logs it is enough to use only os.time() and only when show you can then convert it to readable format.


RE: Daily logging of produced energy from solar inverter - admin - 06.06.2018

Why not use trend logs?


RE: Daily logging of produced energy from solar inverter - buuuudzik - 06.06.2018

All in all, the admin has rightWink


RE: Daily logging of produced energy from solar inverter - tintsch - 06.06.2018

Hi,
thanks buuuudzik for the hint how to append values to a table. I tested it and it works as expected.

admin: I tried to achieve this by using trends and ran into the following limitations:
- Trend resolution is too small, I need to log one value once a day.
- I'm logging the total amount of kWh produced on every day. This value increases throughout the current day until it reaches a maximum value (when the inverter deactivates itself). So 
when I create a trend of the produced kWh's there's too much information in it. As far as I read here in the forum, an averaging is performed on the trend data when it dates back more than 30 days (or whatever value was chosen when creating the trend). This averaging is not apropriate in this case, as the maximum value is wanted.
- Finally it's going to be displayed as a bar chart, with daily/monthly/yearly values.

thanks again. Here's the script and the view of the storage attached as png. 

Code:
-- Log PV-Production
-- get value of object named 'PV Yesterday kWh'
-- Config:
logVariable = '_PV_Energy_daily'  -- custom value so it shows on top of the Storage Viewer App

-- Script start:
value = grp.getvalue('PV Yesterday kWh')
pvLogs = storage.get(logVariable)

toAdd = {
 timestamp = os.time(),
 Energy = value
}

if (pvLogs == nil) then
 -- create table first
 saveTable = {}
 table.insert(saveTable, toAdd)
 storage.set(logVariable, saveTable)
else
 table.insert(pvLogs, toAdd)
 storage.set(logVariable, pvLogs)
end



RE: Daily logging of produced energy from solar inverter - buuuudzik - 06.06.2018

I like in LM controller that it is amazingly elastic and with some knowledge you can do nearly everything in not only one wayWink And when you add to this unlimited power on the client you can do much moreWink